portfolio optimization: risk parity

58 views
Skip to first unread message

Theodosis Athanasiadis

unread,
Feb 16, 2021, 2:54:57 AM2/16/21
to mosek
hello,

I am trying to code the risk parity algo from the following Python notebook to MATLAB 

I am using MATLAB (2019) and the latest MOSEK. 

I am getting Error(1311): Tyring to append a too big cone.

I am not sure if I define the cones properly. Can you take a look at my code below and tell me what I am doing wrong?

function wgts = erc(n,GT,c,b) 
name = 'symbcon';
[~,~, res] = evalc('mosekopt(name)');

prob = [];

% Objective vector: r-c*b'*t (x,t,r)
prob.c = [zeros(n,1);-c*b;1];

% budget constraint 
prob.a = [ones(1,n),zeros(1,n+1)];
prob.blc = 0;
prob.buc = inf;

% Bounds exclude shortselling (x,t,r)
prob.blx =  zeros(2*n+1,1);
prob.bux = inf.*ones(2*n+1,1)];

% An affine conic constraint: [1, r, GT*x] in rotated quadratic cone
% [ 0  0  0]  [ x ]     [ 1 ]
% [ 0  0  1]  [   ]  +  [ 0 ]  \in Q_r
% [ GT 0  0]  [ r ]     [ 0 ]  
prob.f = sparse( [ zeros(1,2*n+1); [zeros(1,2*n),1]; [GT, zeros(n,n+1)] ]);
prob.g = [ 1; 0; zeros(n,1) ];
prob.cones = [ res.symbcon.MSK_CT_RQUAD n ];

% Logarithmic bounds  (xi,1,ti)∈Kexp
% (1,r,Fx)
%  [ 0  0  0]  [ x ]     [ 1 ]
%  [ 0  0  1]  [   ]  +  [ 0 ]  \in Q_r
%  [ GT 0  0]  [ r ]     [ 0 ]  
prob.f = [prob.f; sparse( [ [ones(1,n),zeros(1,n+1)]; zeros(1,2*n+1); [zeros(1,n),ones(1,n),0] ]) ];
prob.g = [prob.g;  [ 0; 1; 0] ];
prob.cones   = [ prob.cones repmat([res.symbcon.MSK_CT_PEXP 3], 1, n)];

% Maximize problem and return the objective value
[rcode,res] = mosekopt('minimize echo(0)', prob, []);
wgts = res.sol.itr.xx;

end


Michal Adamaszek

unread,
Feb 16, 2021, 3:05:18 AM2/16/21
to mosek
Hi,

Towards the end of your code you extend the conic description with 3 rows in f, 3 rows in g, but increase the total dimension of cones by 3n. That's a mismatch.

The quadratic cone to begin with also has a mismatch: f, g have n+2 rows, so you probably want to use n+2 as cone dimension.

So ultimately the error comes from the fact that the total dimension of cones specified in prob.cones is bigger than the number of row s in f.

Michal

Theo

unread,
Feb 16, 2021, 9:01:24 AM2/16/21
to mo...@googlegroups.com
Hi Michal,

Thank you for your prompt response. I did fix it and it runs fine but the results I am getting do not look right. 
I believe the error is in the exponential cone. Can you take a quick look at the code and see if you can spot the error?

Theo

--
You received this message because you are subscribed to a topic in the Google Groups "mosek" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mosek/4zLWKZ_46ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mosek+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mosek/2714504e-6707-46a1-8d08-2a7f7b461547n%40googlegroups.com.
test.m

Theo

unread,
Feb 17, 2021, 12:42:58 AM2/17/21
to mo...@googlegroups.com
actually I think it is correct now 

On Tue, Feb 16, 2021 at 12:27 PM Theo <theodosis.a...@gmail.com> wrote:
I think my exponential cone was wrong. I think I fixed it. It runs fine but the results dont look correct. Please disregard the previous code and use this one 

On Tue, Feb 16, 2021 at 3:05 AM Michal Adamaszek <michal.a...@mosek.com> wrote:

Theo

unread,
Feb 17, 2021, 12:43:05 AM2/17/21
to mo...@googlegroups.com
I think my exponential cone was wrong. I think I fixed it. It runs fine but the results dont look correct. Please disregard the previous code and use this one 

On Tue, Feb 16, 2021 at 3:05 AM Michal Adamaszek <michal.a...@mosek.com> wrote:
test.m
Reply all
Reply to author
Forward
0 new messages