필터 지우기
필터 지우기

CVAR Optimisation - Portfolio Weights and Iterations

조회 수: 4 (최근 30일)
Linus Tham
Linus Tham 2015년 5월 9일
답변: Johan Löfberg 2015년 5월 12일
Good Afternoon,
I'm trying to do a CVAR optimisation on 6 stock tickers and have no problems retrieving the data. However, my code seems to have the following issues:
1) Produces strange portfolio weights
2) Hits the iteration limit which I understand is 1000 . Is this normal?
I'm new to Matlab so would really appreciate guidance from more experienced users.
Linus
c = yahoo; ClosePriceBXMT = fetch(c,'BXMT','Close','08/01/15','08/25/10'); ClosePriceSTWD = fetch(c,'STWD','Close','08/01/15','08/25/10'); ClosePriceCLNY = fetch(c,'CLNY','Close','08/01/15','08/25/10'); ClosePriceSTAR = fetch(c,'STAR','Close','08/01/15','08/25/10'); ClosePriceRWT = fetch(c,'RWT','Close','08/01/15','08/25/10'); ClosePriceNRF = fetch(c,'NRF','Close','08/01/15','08/25/10');
pricematrix= [ClosePriceBXMT(:,2) ClosePriceSTWD(:,2) ClosePriceCLNY(:,2) ClosePriceSTAR(:,2) ClosePriceRWT(:,2) ClosePriceNRF(:,2)];
ScenRets = price2ret(pricematrix);
close(c);
%The code estimates the portfolio CVaR and the asset weights
%INPUTS: %The data matrix (historical returns or simulation) ScenRets size JxnAssets % the confidence level beta (scalar, between 0.9 and 0.999, usually o.95 or % 0.99) %the Upper Bounds for the weights in order to inforce diversification %R0 the portfolio target return [J, nAssets]=size(ScenRets); i=1:nAssets; beta=0.95; %change it if you want but stay between 0.9 and 0.999 UB=0.25; %the upper bound to force diversification, positive between (0,1) R0=0.03; %the target return ShortP=0; %If ShortP=1 allow for short positions, else if ShortP=0 only long positions are allowed %function to be minimized %w(31)=VaR objfun=@(w) w(nAssets+1)+(1/J)*(1/(1-beta))*sum(max(-w(i)*ScenRets(:,i)'-w(nAssets+1),0)); % initial guess w0=[(1/nAssets)*ones(1,nAssets)]; VaR0=abs(quantile(ScenRets*w0',1-beta)); % the initial guess for VaR is the %HS VaR of the equally weighted portfolio w0=[w0 VaR0]; % the (linear) equalities and unequalities matrixes A=[-mean(ScenRets) 0]; if ShortP==0 A=[A; -eye(nAssets) zeros(nAssets,1)]; A=[A; eye(nAssets) zeros(nAssets,1)]; b=[-R0 zeros(1,nAssets) UB*ones(1,nAssets)]; elseif ShortP==1 A=[A; -eye(nAssets) zeros(nAssets,1)]; A=[A; eye(nAssets) zeros(nAssets,1)]; b=[-R0 -LB*ones(1,nAssets) UB*ones(1,nAssets)]; elseif ShortP~=0|ShortP~=1 error('Input ShortP=1 (line14) if you allow short positions and 0 else!!')
end b=b'; Aeq=[ ones(1,nAssets) 0]; beq=[1];
options=optimset('LargeScale','off');
options=optimset(options,'MaxFunEvals',100000); [w,fval,exitflag,output]=fmincon(objfun,w0,A,b,Aeq,beq,[],[],[],options) portfWeights=zeros(1, nAssets); for i=1:nAssets % clear rounding errors if w(i)<0.0001 w(i)=0; end % save results to the workfile portfWeights(1,i)=w(i); end Risk=zeros(1,2); Risk(1,1)=w(nAssets+1); %Remember that w(31)= portfolio VaR Risk(1,2)=fval;

답변 (1개)

Johan Löfberg
Johan Löfberg 2015년 5월 12일
CVar from data is linear programming representable, so trying to to solve it as a non-smooth nonlinear program using a nonlinear solver is not a good idea. Just google cvar linear program and you will find a lot of material on how to solve these models.

카테고리

Help CenterFile Exchange에서 Portfolio Optimization and Asset Allocation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by