问题
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);
回答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 = [];
来源:https://stackoverflow.com/questions/41862287/how-to-allow-for-weights-between-1-and-1-using-constraints-in-aeq-x-beq