www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/weight_std_130_30_budgetconstr.m
function std_weight_mat = weight_std_130_30_budgetconstr(weight_mat, long_low_up_bounds, short_low_up_bounds) [row_mat, col_mat]= size(weight_mat); % budgets for long positions eta = 1.3; gamma = 0; for p = 1:row_mat H = group_assets_130_30(col_mat, weight_mat(p,:)); % Adjust weights representing long positions deposit_wgts =0; h=1; sum_wgts = sum(weight_mat(p,H{h})); % check if sum of weights of long positions lie within limits if (sum_wgts <= eta ) && (sum_wgts >= gamma) continue; else deposit_wgts = deposit_wgts + (sum_wgts-eta); MP = eta; weight_mat(p,:) = std_wgts_asset_130_30_longclass(weight_mat(p,:), H{h}, sum_wgts, MP, long_low_up_bounds); end % Adjust weights representing short positions if (deposit_wgts ==0) continue; else h = 2; sum_wgts = sum(weight_mat(p,H{h})); abs_sum_wgts = sum(abs(weight_mat(p,H{h})) ); deposit_wgts = deposit_wgts + sum_wgts; weight_mat(p,:) = std_wgts_asset_130_30_shortclass(weight_mat(p,:), H{h}, abs_sum_wgts, deposit_wgts, short_low_up_bounds); end end std_weight_mat=weight_mat; end