How to implement Conditiona​l-Drawdown​-at-Risk with linear programming?

5 次查看(过去 30 天)
I'm trying to implement the Conditional-Drawdown-at-Risk as a portfolio strategy (see Chekhlov et al, 2003 for the theory) - using fmincon as it is a linear programming problem. The objective is to minimize the Conditional-Drawdown-at-Risk such that the target portfolio return is met, weights cannot be negativ (lb and ub) and have to add up to one and the constraints for the LP are met.
The following code doesn't run at the moment - but the bigger problem is that I'm not even sure whether all the constraints are implemented correctly. The formula is in the screenshot below, it just needs to be changed in order to minimize the risk with respect to a target return (the constraints remain the same though). My code is also below. z, u and zeta are auxiliary variables to enable the LP. Especially the fact that I need constraints for u and u(k-1) is proving difficult for me (initial guess with loop or in constraint, and if so how?).
Any help would be great!
clear all;
%import the historical data
filename ='Test.csv';
delimiterIn = ';';
headerlinesIn = 1;
Test = importdata(filename,delimiterIn,headerlinesIn);
Returns = Price2Returnlog(Test.data);
[J, nAssets]=size(Returns); i=1:nAssets;
beta=0.95; %confidence parameter R0 = 0; %target return
% initial guess
w0=[(1/nAssets)*ones(1,nAssets)]; %equal weight portfolio
cumreturns=cumsum(Returns);
for i=1:2
zeta = 0;
uk = cumreturns*w0';
zk=max((uk - cumreturns*w0' - zeta),0);
end
w1=[w0';zeta; uk; zk];
%objective function
objfun=@(w) zeta+(1/J)*(1/(1-beta))*sum(zk)
% constraints
lb = [zeros(nAssets,1); zeros(2*J+1,1)];
ub = [ones(nAssets,1); inf(2*J+1,1)];
A=[-mean(Returns) zeros(1,1) ones(1,J) zeros(1,J)];
b=[-R0; 0; -cumreturns*w0'];
Aeq=[ones(1,nAssets) zeros(1,2*J+1)];
beq=[1; zeros(J,1)];
options = optimset('Algorithm','active-set');
[w,fval,exitflag]=fmincon(objfun,w1,A,b,Aeq,beq,lb,ub,[],options)
  1 个评论
Matt J
Matt J 2015-7-26
using fmincon as it is a linear programming problem
If it is a linear program, then LINPROG would be the most appropriate.

请先登录,再进行评论。

回答(2 个)

Matt J
Matt J 2015-7-26
编辑:Matt J 2015-7-26
Especially the fact that I need constraints for u and u(k-1) is proving difficult for me (initial guess with loop or in constraint, and if so how?).
To simplify, I'll assume that u(k) are the only unknowns. The constraints,
u(k-1)-u(k)<=0, k=2,...,N
can be represented in the matrix form A*u<=b where
A=-eye(N-1,N);
A(N:N:end)=1;
b=zeros(N-1,1);
Since you have additional variables besides u, you will have to embed the above in larger matrices compatible with multiplication with [u;zeta;z;x].
  2 个评论
L Enders
L Enders 2015-7-27
Hi Matt, thanks - I have implemented it now and the code runs (see below) but unfortunately I now get the following error:
Exiting: One or more of the residuals, duality gap, or total relative error
has stalled:
the primal appears to be infeasible (and the dual unbounded).
(The dual residual < TolFun=1.00e-08.)
Is that because the constraints are implemented false or due to my data? Many Thanks!
clear all;
%import the historical data
filename ='Test.csv';
delimiterIn = ';';
headerlinesIn = 1;
Test = importdata(filename,delimiterIn,headerlinesIn);
%generating returns from the prices
Returns = Price2Returnlog(Test.data);
[J, nAssets]=size(Returns);
i=1:nAssets;
beta=0.95; %confidence parameter
R0 = 0; %target returns
K = beta*J;
% initial guess
w0=[(1/nAssets)*ones(1,nAssets)]; %equal weight portfolio
yk=cumsum(Returns);
zeta = 0;
uk = yk*w0';
zk=max((uk - yk*w0' - zeta),0);
w1=[w0';zeta; uk; zk];
%objective function
f= [zeros(nAssets,1); 1; zeros(J,1); (1/K)*ones(J,1)];
% constraints
lb = [zeros(nAssets,1); zeros(2*J+1,1)];
ub = [ones(nAssets,1); inf(2*J+1,1)];
A=[-yk -ones(J,1) eye(J,J) -eye(J,J)];
A1=[-mean(Returns) zeros(1,2*J+1)];
A=[A; A1];
A2=-eye(J-1,J); A(J:J:end)=1; %for uk and uk-1
A3=[zeros(J-1,nAssets+1) A2 zeros(J-1,J)];
A=[A;A3];
A=[A; -yk -zeros(J,1) -eye(J,J) -zeros(J,J)];
b=[zeros(J,1); R0; zeros(J-1,1); zeros(J,1)];
Aeq=[ones(1,nAssets) zeros(1,2*J+1)];
beq=[1];
options = optimset('Algorithm','active-set');
%optimization
[w1,fval,exitflag]=linprog(f,A,b,Aeq,beq,lb,ub,[],options);
Matt J
Matt J 2015-7-27
编辑:Matt J 2015-7-27
The error means that linprog thinks your problem is infeasible, i.e., your constraint set is empty. So, you may have an error in your A,b,Aeq,beq,lb,ub data.
If you know at least one feasible point apriori, a good troubleshooting strategy would be to plug that point into your constraints to see which constraints are incorrectly violated.

请先登录,再进行评论。


Lorenzo Sattolo
Lorenzo Sattolo 2021-4-30
编辑:Lorenzo Sattolo 2021-5-29
this should work
clear
close
clc
%%
load('YourData.mat');
ret = diff(AssetPrices)./AssetPrices(1:end-1,:);
[T, n] = size(ret);
y = cumsum(ret); % matrix of uncompounded cumulative returns
d = T/252; % number of years in our analysis
alpha = 0.99; % confidence level
C = 1; % available capital
uno = ones(T-1,1);
w = 0;
nu3 = 1;
%% CDaR(alpha) optimization
f = -[(1/(d*C))*y(end,:), zeros(1,2*T), 0];
A = [zeros(1,n), 1/((1-alpha)*T)*ones(1,T), zeros(1,T), 1;
-y, -eye(T), +eye(T), -ones(T,1);
y, zeros(T,T), -eye(T), zeros(T,1);
zeros(T,n), zeros(T,T), -eye(T)+diag(uno,1), zeros(T,1)];
b = [nu3*C;
zeros(T*3,1)];
Aeq = [ones(1,n), zeros(1,T*2+1)];
beq = [1];
LB = [w*ones(1,n), zeros(1,T), -inf(1,T+1)];
UB = [];
[X,FX] = linprog(f,A,b,Aeq,beq,LB,UB);
weights = X(1:n,1);
Max_Ret = -FX;

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by