I am using fmincon to find the solution (weights of each assets) that optimizing my investment portfolio.How can I make each of the weight less than 1, instead of less than or equal to 1, but the sum of weights equals 1? The codes are:
w = zeros (4,1)
cov = xlsread('gupiao.xls','equal weights','O13:R16')
sigmaP = w'*cov*w
delta_x = xlsread('gupiao.xls','sheet3','A503:D503')
delta_P = delta_x*w
fun = @(w)-[delta_x*w-0.5*[0.7*w'*cov*w+1/1000000*(0.1*36843+0.2*48772)]^2]
Aeq = ones(1,4)
beq = 1
A = []
b = []
lb = []
ub=ones(size(w))
w = fmincon(fun,w,A,b,Aeq,beq,lb,ub)
It gives me the results:
w =
1.0000
1.0000
1.0000
-2.0000
But, these results violate my constraint that each of the weight is less than 1. Could you please tell me how can I solve this problem?

 Réponse acceptée

Walter Roberson
Walter Roberson le 10 Mai 2018

1 vote

A = ones(1,4);
b = 1-eps;
Aeq = [];
beq = [];
This forces the sum to be less than or equal to 1-eps, which should be equivalent to being less than 1.

3 commentaires

Xiangnan Liu
Xiangnan Liu le 10 Mai 2018
Modifié(e) : Xiangnan Liu le 10 Mai 2018
Hi~ Thank you for replying me! I tried your codes, and it gives me w =
1.0000
1.0000
1.0000
-48.8791
I appologize for not stating my problem clearly, it should be: make each of the weight less than 1, instead of less than or equal to 1, but the sum of weights equals 1.
If so, could you please tell me what constraint should I use?
Ah, that is a different problem. To do that use your original setting but set
ub = ones(1,4)-eps;
Xiangnan Liu
Xiangnan Liu le 10 Mai 2018
Modifié(e) : Xiangnan Liu le 10 Mai 2018
I rewrote my codes applying your suggestions, it works! Thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (2)

Stephan
Stephan le 10 Mai 2018
Modifié(e) : Stephan le 10 Mai 2018

1 vote

Hi,
i assume, negative values are not allowed. A share of -2 of the stock represented by variable 4 makes no sense.
If that is correct, use
lb=zeros(1,4)
Together with your Aeq and beq constraint this should work.
Best regards
Stephan

1 commentaire

Xiangnan Liu
Xiangnan Liu le 10 Mai 2018
Hello! Thanks a lot for your reply! Actually, in my portfolio, negative weights are allowed, which means I am short selling. Could you please tell me what constraint should I use then?

Connectez-vous pour commenter.

Matt J
Matt J le 10 Mai 2018

0 votes

If the unconstrained minimum lies at w(i)=1, then there is no sense pursuing a constraint like w(i)<1. It would be like minimizing f(z)=(z-1)^2 with the constraint that z<1. The minimum cannot be attained.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by