1

I am using quadprog to find a portfolio of optimal weights.

So far, I have managed to implement long-only and short-only constraints as follows:

FirstDegree             = zeros(NumAssets,1);
SecondDegree            = Covariance;

Long only

Aeq                     = ones(1,NumAssets);
beq                     = 1;
A                       = -eye(NumAssets);
b                       = zeros(NumAssets,1);

x0                      = 1/NumAssets*ones(NumAssets,1);
MinVol_Weights          = quadprog(SecondDegree,FirstDegree,A,b,Aeq,beq,[],[],x0, options);

Short-only

Aeq                     = ones(1,NumAssets);
beq                     = -1;
A                       = eye(NumAssets);
b                       = zeros(NumAssets,1);

x0                      = -1/NumAssets*ones(NumAssets,1);
MinVol_Weights          = quadprog(SecondDegree,FirstDegree,A,b,Aeq,beq,[],[],x0, options);

I am now looking for a way to combine those two and to allow for both long and short weights, thus x can be between -1 and 1. How can I achieve this?

I tried the following, but it only gives me equal weights:

Both long and short (does not work)

A                       = [eye(NumAssets); ones(1, NumAssets); -ones(1, NumAssets)]; 
b                       = [zeros(NumAssets, 1); 1; -1];
Aeq                     = [];
beq                     = [];
lb                      = [];
ub                      = [];

x0                      = 1/NumAssets*ones(NumAssets,1);
MinVol_Weights          = quadprog(SecondDegree,FirstDegree,A,b,Aeq,beq,lb,ub,x0, options);
WJA
  • 6,676
  • 16
  • 85
  • 152
  • 1
    The –1 in the last component should be a +1 as well. It means *–Σ w_i ≤ 1* which is the same as *–1 ≤ Σ w_i*. – Lumen Jan 25 '17 at 22:01
  • I’m sorry, I don’t think I understand what you’re trying to achieve. Can you describe the quadratic program that you want in your own words, or maybe even mathematically? Which constraints do you want for your variables? – Lumen Jan 25 '17 at 22:10
  • Simply that they are between -1 and 1. That's all. I.e. the investor can go long or short. The sum of short to add up to -1 and the sum of long to add up to 1, but it does not have to be the case. – WJA Jan 25 '17 at 22:13

1 Answers1

1

If all you want is that the sum of all weights is between –1 and 1, then the –1 in the last component of b should be a +1 as well. It means –Σw_i ≤ 1 which is the same as –1 ≤ Σw_i. Combining it with Σw_i ≤ 1 you get –1 ≤ Σw_i ≤ 1:

A  = [ ones(1, NumAssets);
      -ones(1, NumAssets)]; 
b  = [1;
      1];
Aeq = [];
beq = [];
lb = [];
ub = [];
Lumen
  • 3,554
  • 2
  • 20
  • 33