hello i would appreciate some help to implement a nonlinear inequality in my fmincon program. I am trying to maximize Sharpe ratio under two constraints. First that the sum of the weights equal one and the second one is that (((w-w0).^2).^1/2) -0.005 >= 0 (tracking error constraint where w0 is set to be the benchmark weights vector). I am getting errors when trying to programme the tracking error constraint. Thank you!
for i=1:T-M
objective = @(w) -(zbarA3(:,i)'*w - rf)/(sqrt(w'*covmatA3{1,i}*w));
w0 = Wi_AQ2;
Aeq = ones(1,n);
beq = 1;
W_Q3(:,i) = fmincon(objective,w0,[],[],Aeq,beq,[],[],nonling);
end
%where nonling is
function [c,ceq]=nonling(w)
c= sqrt((w(1) - Wi_AQ2)^2) -0.005;
ceq=w*0;
end

댓글 수: 6

Matt J
Matt J 2018년 2월 9일
Please indent your code (but not your text) to make it more readable.
Mohamad Moussa
Mohamad Moussa 2018년 2월 9일
Fixed, sorry for that first time asking.
Is this
(((w-w0).^2).^1/2)
really in fact supposed to be
norm(w-w0)
?
Mohamad Moussa
Mohamad Moussa 2018년 2월 9일
It is supposed to take the absolute value of the difference.
Matt J
Matt J 2018년 2월 9일
편집: Matt J 2018년 2월 9일
w and w0 are length-n vectors. Do you therefore have n contraints?
abs(w(i)-w0(i))>=0.005, i=1...,n
Mohamad Moussa
Mohamad Moussa 2018년 2월 9일
편집: Mohamad Moussa 2018년 2월 9일
True i did not notice that oppositely to Aeq and Beq, c and ceq right side in the inequality is a scaler not a vector. Maybe this should do the trick if not ill try making a loop like you stated previously. Thank you
function [c,ceq]=nonling(w,w0)
c= abs(w - w0)*ones(1,n) -0.005;
ceq=[];
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2018년 2월 9일
편집: Matt J 2018년 2월 9일

0 개 추천

for i=1:T-M
objective = @(w) -(zbarA3(:,i)'*w - rf)/(sqrt(w'*covmatA3{1,i}*w));
w0 = Wi_AQ2;
Aeq = ones(1,n);
beq = 1;
W_Q3(:,i) = fmincon(objective,w0,[],[],Aeq,beq,[],[], @(w) nonling(w,w0) );
end
function [c,ceq]=nonling(w,w0)
c= .005^2-norm(w - w0)^2 ;
ceq=[];
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기

질문:

2018년 2월 9일

편집:

2018년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by