How to use quadprog for constrained maximization (portfolio opitization)
18 views (last 30 days)
Show older comments
Hi,
I use a student version of Matlab for solving a portfolio optimization problems (optimization toolbox, I don't have a financial toolbox). My current problem is to maximize:
(x'*r-rf)/sqrt(x'*C*x)
where: x- vector of equities shares in a portfolio;
r - vector of expected returns;
rf- rish free rate;
C - covariance matrix
In short I try to maximize a Sharpe ratio and find a tangency portolio. To do that I use a fmincon:
[x,fval]=fmincon(@(x)-(x'*r-rf)/sqrt(x'*C*x),x0,[],[],Aeq,beq,lb,ub,[],options);
Unfortunately I think that a solution which I receive is not really a tangency portfolio. I think a solver fails to find a global minimum. That is why I would like to use a quadprog (x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options). I found it effective in finding a minimum variance portfolio (minimazing sqrt(x'*C*x)). The problem is I don't know if it is possible to use a quadprog having a function shown above. Can anyone help me to parameterize my problem using a quadprog?
Thank you very much in advance.
3 Comments
Accepted Answer
Matt J
on 2 Dec 2014
Edited: Matt J
on 2 Dec 2014
To answer your question, I don't think your function can be rewritten as quadratic, however, if the goal is to minimize
x'*C*x/(x'*r-rf)^2
it might be a useful approximation to minimize the difference between the numerator and the denominator
min. x'*C*x - (x'*r-rf)^2
This is a quadratic program, and can be solved with quadprog with
H = C-r(:)*r(:).'
f = -2*r*rf
If nothing else, this might give you a better initial guess x0 for fmincon than what you are using now. You could also try using the minimum variance portfolio as your initial guess.
In either case, when using fmincon, I would try rewriting your minimization objective as
x'*C*x/(x'*r-rf)^2
maybe with appropriate additional constraints on x'*r-rf. Avoiding the sqrt() operations gets rid of differentiability issues.
7 Comments
Matt J
on 5 Dec 2014
Edited: Matt J
on 5 Dec 2014
I'm quite new to Matlab and don't really understand your Matlab syntax (especialy the code for H).
It may be helpful to study the effect of the (:) operation on different matrices, e.g.,
>> x=[1 2 3; 5 6 7].'
x =
1 5
2 6
3 7
>> x(:)
ans =
1
2
3
5
6
7
>> x(:).'
ans =
1 2 3 5 6 7
More Answers (0)
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!