www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/std_wgts_asset_130_30_shortclass.m
function weight_vector = std_wgts_asset_130_30_shortclass(weight_vector, M, abswgt_sum, TW, low_up_bounds) % adjust lower bounds of assets L = abswgt_sum; F = TW - sum(low_up_bounds(1,M)); if (L==0) term = F/length(M); weight_vector(M) = low_up_bounds(1,M)+ term; else term = F /L; weight_vector(M) = low_up_bounds(1,M)+ (abs(weight_vector(M))* term); end % adjust upper bounds of assets kr = 1; r = []; ex_flag = true; q = setdiff(M, r); while (ex_flag == true) ex_flag = false; for j = 1: length(q) if (weight_vector(q(j))> low_up_bounds(2,q(j))) ex_flag = true; r(kr) = q(j); kr = kr+1; end end q = setdiff(M, r); if (ex_flag == true) L = sum(abs(weight_vector(q))); F = TW - (sum(low_up_bounds(1,q))+ sum( low_up_bounds(2,r)) ); if (~isempty (q)) if (L==0) term = F; weight_vector(q(1))= term; else term = F/L; weight_vector(q) = low_up_bounds(1,q) + (abs(weight_vector(q))* term); end end weight_vector(r) = low_up_bounds(2,r); end end end