www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/std_wgts_asset_130_30_longclass.m
function weight_vector = std_wgts_asset_130_30_longclass(weight_vector, M, wgt_sum, TW, low_up_bounds) % adjust lower bounds of assets L = wgt_sum; F = TW - sum(low_up_bounds(1,M)); term = F /L; weight_vector(M) = low_up_bounds(1,M)+ (weight_vector(M)* term); % 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(weight_vector(q)); F = TW - ( sum(low_up_bounds(1,q))+ sum( low_up_bounds(2,r)) ); term = F/L; weight_vector(q) = low_up_bounds(1,q) + (weight_vector(q)* term); weight_vector(r) = low_up_bounds(2,r); end end end