How to use quadprog for constrained maximization (portfolio opitization)

18 views (last 30 days)
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
Piotr
Piotr on 2 Dec 2014
At first I use vector of zeros for x0 and use interion point algorithm, than I set x0=x and use sqp algorithm with tolcon,tolfun,tolx set to 1e-20. I found this method fast and at least a solution seems to be "good". If I started with sqp or active-set from the beginning Matlab couldn't find a solution even after several hours.I will add that my cov matrixes are quite big, from 100x100 to 450x450.
Piotr
Piotr on 2 Dec 2014
I will add one more thing. I set lb to be a vector of zeros so I don't allow a short sellign and I set ub to be a vector of 0.03 so I limit each equity to have maximum 3% share in a portfolio.

Sign in to comment.

Accepted Answer

Matt J
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
Piotr
Piotr on 4 Dec 2014
From what I know every covariance matrix is positive semi-definite. I calculated my matrix in excel using monthly returns of my equities. Maybe it is the matter that before uploading it into Matlab I didn't round values so I have a huge matrix with values having even 15 decimal places and Matlab has problem to handle that.
During a weekend when I will have more time I will try to dig deeper into your quadprog idea. I'm quite new to Matlab and don't really understand your Matlab syntax (especialy the code for H).
Anyway, thank you very much for all your help. You already gave me a lot of ideas.
Matt J
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

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox 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!