全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
6316 1
2010-10-06
悬赏 50 个论坛币 未解决
程序源代码为:
function CVaR(ScenRets)
%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.9; %change it if you want but stay between 0.9 and 0.999
UB=1;  %the upper bound to inforce diversification, positive between (0,1)
R0=0.07;  %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
[email=objfun=@(w]objfun=@(w[/email]) 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','0n');
options=optimset(options,'MaxFunEvals',10000);
[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;
问题:
Optimization terminated: first-order optimality measure less than options.TolFun
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):

本人为初学者,在此恳请高人帮忙解答,谢谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-10-6 10:07:37
这说明你的问题在局部最优点收敛了

你需要修改 options.TolCon = 1e-006来改变收敛条件,可能还需要修改其他的条件 这个要看收敛的结果是不是可靠
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群