Max sharpe ratio portfolio with constrains, using FMINCON + NONLCON
2 views (last 30 days)
Show older comments
Hi all, i'm trying to find the weights of the max sharpe portfolio (wh) with an upperbound on risk contribution (URC). The code works well, but the NONLCON input function does not, i get the problem "too many output arguments".
%% MAX SHARPE PORTFOLIO CODE %%
[A,B] = xlsread('US_stocks') ;
prices = A;
logret = diff(log(prices));
sigma = cov(logret);
mu = mean(logret);
std = sqrt(diag(sigma));
f = @(w) -((mu*w)/sqrt(w'*sigma*w));
opts2=optimset('Display','iter','algorithm','sqp');
lb=zeros(1,N);
ub=ones(1,N);
Amat=ones(1,N);
Bmat=1;
w0=1/N*ones(N,1);
wh = fmincon(f,w0,[],[],Amat,Bmat,lb,ub,@GRCcon,opts2);
% total risk
R=sqrt((wh')*sigma*wh);
% un-standardized Marginal Risks
mR = sigma*wh;
% standardized Risk Contributions
RC= wh.*mR/R;
trn=mu*wh;
%% GRCcon FUNCTION %%
function [cineq] = GRCcon(w)
global sigma;
% total risk
R=sqrt((w')*sigma*w);
% un-standardized Marginal Risks
mR = sigma*w;
% standardized Risk Contributions
RC = w.*mR/R;
% upper bound
URC = 0.5*ones(size(mR));
% Compute inequalities
cineq = (RC-URC);
end
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!