How to constrain this optimisation to be long-only?
2 views (last 30 days)
Show older comments
Hi everyone, I'm using a library that optimise a portfolio based in past information and my views on best stocks. However, I need the final weights to be long-only (i.e. positives). Any idea if this is possible? See below the code:
function Allocation = DecisionBayesParameters(Market,InvestorProfile,Prior)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% estimate market parameters
Exp_LinRets_Hat=mean(Market.LinRetsSeries)';
Cov_LinRets_Hat=cov(Market.LinRetsSeries);
T=Market.T;
T_1=Prior.T_0+T;
Exp_LinRets_Post=(Prior.LinRets_EV*Prior.T_0+Exp_LinRets_Hat*T)/T_1;
Nu_1=Prior.Nu_0+T;
Cov_LinRets_Post=(Prior.LinRets_Cov*Prior.Nu_0+Cov_LinRets_Hat*T+(Exp_LinRets_Hat-Prior.LinRets_EV)*(Exp_LinRets_Hat-Prior.LinRets_EV)'*Prior.T_0*T/T_1)/Nu_1;
Exp_Prices_Hat=diag(Market.CurrentPrices)*(1+Exp_LinRets_Post);
Cov_Prices_Hat=diag(Market.CurrentPrices)*Cov_LinRets_Post*diag(Market.CurrentPrices);
% compute allocation
S=inv(Cov_Prices_Hat);
A_Hat=Market.CurrentPrices'*S*Market.CurrentPrices;
B_Hat=Market.CurrentPrices'*S*Exp_Prices_Hat;
Gamma = (InvestorProfile.Budget - InvestorProfile.RiskPropensity*B_Hat)/A_Hat;
Allocation = InvestorProfile.RiskPropensity*S*Exp_Prices_Hat + Gamma*S*Market.CurrentPrices;
This is the library: https://uk.mathworks.com/matlabcentral/fileexchange/9061-risk-and-asset-allocation
0 Comments
Answers (0)
See Also
Categories
Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!