How to implement Conditional-Drawdown-at-Risk with linear programming?
1 view (last 30 days)
Show older comments
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 Comment
Matt J
on 26 Jul 2015
using fmincon as it is a linear programming problem
If it is a linear program, then LINPROG would be the most appropriate.
Answers (2)
Matt J
on 26 Jul 2015
Edited: Matt J
on 26 Jul 2015
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 Comments
Matt J
on 27 Jul 2015
Edited: Matt J
on 27 Jul 2015
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
on 30 Apr 2021
Edited: Lorenzo Sattolo
on 29 May 2021
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;
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!