fmincon: nonliner constraint
Show older comments
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?
Accepted Answer
More Answers (2)
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 Comment
Xiangnan Liu
on 10 May 2018
Matt J
on 10 May 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.
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!