Robust Markowitz Modell: Problems in the Covariance Matrix

74 views
Skip to first unread message

Lissi

unread,
Jul 16, 2013, 5:50:47 AM7/16/13
to yal...@googlegroups.com
I'm still trying to implement a robust version of the markowitz modell. Thanks to you for helping me the last time!
I'm sorry, but now I have a new problem and I'm helpless, as it seems that its just a small alteration of the code.

Now I am trying to increase the uncertainties in the covariance matrix. First I just considered the variances Sigma(t) as uncertain, but now I want the covariances to be uncertain too. I calculate them as covariance(1,2) = Corelation(1,2)* sqrt(Sigma(1)*Sigma(2)) for example. But when I run the code, I get the error that my matrix is singular or badly scaled?
Do I have too many uncertainties or is my matrix just badly chosen?

Thank you!

% test data
% vector of return
mu_t = [0.05; 0.11; 0.16; 0.25];

% corelation matrix
Cor_t =     [1.0 0.1 0.7 -0.1;
            0.1 1.0 -0.2 0.4;
            0.7 -0.2 1.0 0.3;
            -0.1 0.4 0.3 1.0];

% Covariance matrix       
Sigma_t = [ 0.025 0.00055 0.0056 0.00125;
            0.00055 0.0121 -0.00352 0.011;
            0.0056 -0.00352 0.0256 0.012;
            0.00125 0.011 0.012 0.0625];

ab = 0.01;
lambda = 1;


% upper and lower bound for the box constraint of the vector of return
mu_l = mu_t - ab*mu_t;
mu_u = mu_t + ab*mu_t;

% upper and lower bound for the box constraint of the covariance matrix
Sigma_l = Sigma_t - ab*Sigma_t;
Sigma_u = Sigma_t + ab*Sigma_t;

n = length(mu_t);
w = sdpvar(n,1);
mu = sdpvar(n,1);


% Definition of Sigma, and the covariances, later to be uncertain
sdpvar t1 t2 t3 t4 t12 t13 t14 t23 t24 t34

t12 = Cor_t(1,2)*sqrt(t1*t2);
t13 = Cor_t(1,3)*sqrt(t1*t3);
t14 = Cor_t(1,4)*sqrt(t1*t4);
t23 = Cor_t(2,3)*sqrt(t2*t3);
t24 = Cor_t(2,4)*sqrt(t2*t4);
t34 = Cor_t(3,4)*sqrt(t3*t4);

Sigma =     [t1, t12, t13, t14;
            t12, t2, t23, t24;
            t13, t23, t3, t34;
            t14, t24, t34, t4];


% constraints on the portfolio
W = [sum(w) == 1, w >= 0];

% uncertainty for the vector of returns
M = [mu_l <= mu <= mu_u, uncertain(mu)];


% uncertainty for the variances
S = [Sigma_l(1,1)<= t1 <= Sigma_u(1,1),
    Sigma_l(2,2)<= t2 <= Sigma_u(2,2),
    Sigma_l(3,3)<= t3 <= Sigma_u(3,3),
    Sigma_l(4,4)<= t4 <= Sigma_u(4,4),
    uncertain(t1), uncertain(t2), uncertain(t3), uncertain(t4)];

% objective function
objective = lambda*w'*Sigma*w-mu'*w;
sdpvar t

solvesdp([W + S + M,lambda*w'*Sigma*w-mu'*w<=t] , t)

double(w)




Johan Löfberg

unread,
Jul 16, 2013, 1:15:20 PM7/16/13
to yal...@googlegroups.com
I am surprised the code even runs through the robustification. That uncertainty does not look conic representable. I think YALMIP doing something very wrong here to begin with.
Message has been deleted

Lissi

unread,
Jul 30, 2013, 3:12:23 PM7/30/13
to yal...@googlegroups.com
Thank you very much!  I've now changed the code to a SOCP. Anyhow, this time I get the error, that "Sigmonial SOCP not supported". What does that mean?

My code now is as follows:

% test data
 mu_t = [0.05; 0.11; 0.16; 0.16];

 Cor_t =     [1.0 0.1 0.7 -0.1;
             0.1 1.0 -0.2 0.4;
             0.7 -0.2 1.0 0.3;
             -0.1 0.4 0.3 1.0];
        
 Sigma_t = [ 0.025 0.00055 0.0056 0.00125;
             0.00055 0.0121 -0.00352 0.011;
             0.0056 -0.00352 0.0256 0.012;
             0.00125 0.011 0.012 0.027];
       

ab = 0.05;
R = mean(mu_t);

% upper and lower bounds for mu

mu_l = mu_t - ab*mu_t;
mu_u = mu_t + ab*mu_t;
mu_l(3) = 0.08;

% upper and lower bounds for Sigma

Sigma_l = Sigma_t - ab*Sigma_t;
Sigma_u = Sigma_t + ab*Sigma_t;


% upper and lower bounds for the corelation matrix
Cor_l = Cor_t - ab*Cor_t;
Cor_u = Cor_t + ab*Cor_t;

% definition of the variables
n = length(mu_t);

mu = sdpvar(n,1); %mu, later to be uncertain
w = sdpvar(n,1); 
Sigma = sdpvar(n,n); %Sigma, later to be uncertain

sdpvar z;           % additional variable


        % constraints on the portfolio
        W = [sum(w) == 1, w >= 0];

        % Uncertainty of mu
        M = [mu_l <= mu <= mu_u, mu'*w >= R, uncertain(mu)];

        %Uncertainty of Sigma, now it depends on the corelation matrix
        C = [];
        for k = 1:n
            for j = 1:n
                C = [C, norm([2*z;Sigma(k,k) - Sigma(j,j)],2) <= Sigma(k,k) + Sigma(j,j),
                Cor_l(k,j)*z >= Sigma(k,j) >= Cor_u(k,j)*z];
            end
        end

        for k = 1:n
            for j = 1:n
                C = [C, uncertain(Sigma(k,j))];
            end
        end
       
        %here I think lies the problem: I want to add a constraint on the risk Sigma, it shouldn't be any larger than a fixed value
        sdpvar y;
        y = Sigma.^(1/2)*w;
        C = [C, norm(y,2)<= 0.015];
     
       
        % Zielfunktion
        sdpvar t
     solvesdp([W + M + C,w'*Sigma*w<=t] , t)



Thany you very much in advance!

Johan Löfberg

unread,
Jul 30, 2013, 3:28:29 PM7/30/13
to yal...@googlegroups.com
You cannot have square roots of uncertainties etc and work with them arbitrarily. The only uncertainty scenarios supported are those listed in my paper Automatic Robust Optimization

You want w'*Sigma*w <= 0.015^2. Doesn't that work?

Lissi

unread,
Jul 30, 2013, 3:36:48 PM7/30/13
to yal...@googlegroups.com
it's working! I can't understand how I missed the totally obvious.
Thank you again!
Reply all
Reply to author
Forward
0 new messages