How do I solve for portfolio weights to achieve specific min/max objective?

25 views (last 30 days)
Let me preface this by disclosing that I think I must be overlooking something very simple or so obvious that it merits being overlooked.
Take the following example: I have a portfolio of 10 securities and monthly return data for 24 months. Based on this data, I set a few constraints like the total weight of the portfolio must equal 1 and the maximum allocation to for any one security is 50%, while the minimum is, say, 5%.
After tinkering with the estimateMaxSharpeRatio function for a while, I was able to generate a blotter reflecting securities and their respective weights that yielded the maximum Sharpe Ratio.
Then, as part of the basic portfolio management process, I wanted to see what portfolio weights would yield the highest Sortino Ratio. And this is where the problems began. Not only was I unsuccessful after several attempts, I began to wonder how I might solve for weights that would yield just the minimum variance (subject to my constraints), or just the maximum return, or the minimum CVaR, or the minimum MaxDrawdown, or the minimum Delta Normal VaR, or the maximum Treynor Ratio, or the minimum downside deviation, or any other target of my choosing.
These are basic -- and fundamental -- portfolio management functions, but I haven't seen them clearly demonstrated or explained in either the Financial Toolbox manual or the Mathworks website. Additionally, the aforementioned tasks are very easy to do in Excel using the solver. You simply ask it to minimize or maximize any selected cell (i.e. return/risk ratio) by changing another set of variables (i.e. the portfolio weights), such that the total of the portfolio weights equals 1 or any other desired constraint.
How do you "solve" these problems using MATLAB or the financial toolbox or the optimization toolbox? It seems to me it should be an extremely basic code that is fundamentally similar for all ratios or other measures that you want to minimize or maximize. I don't want to see efficient frontier graphs, or scatter plots, or area graphs; I just want to see ticker symbols and weights that represent the algebraic solution.
Please help.
Thanks.

Accepted Answer

Run Zhu
Run Zhu on 9 Nov 2017
Hi Dave,
The way that Optimization Toolbox solving the problem as you mentioned starts with the mathematical formulation. Say you have simple problem
Expected Return E of a portfolio
E = w1 * R1 + w2 * R2 + ...+ wn * Rn
Subject to:
w1 + + wn = 1
5% <= wi <= 50% (i = 1 … n)
There are twos way to solve it by the Optimization Toolbox:
One is the problem-based approach, which is new since 2017a
(1) Define w as optimization variable
w = optimvar(w, 1, n , UpperBound, 0.5, LowerBound, 0.05)
(2) Define objective function
E = sum(R.*w)
where
R = [R1, R2, , Rn]
(3) Define constraint
EqConstr = sum(w) == 1
(4) Define the optimization problem
prob = optimproblem('ObjectiveSense','maximize');
prob. Constraints. Objective = E
prob. Constraints.Constr =EqConstr
(5) Solve the problem
optimW = solve(prob)
A detailed example in Portfolio Optimization is provided here
Another way is the traditional solver-based approach. An example with the same Portfolio Optimization can be found here
Hope this will help you get started. Good luck!
  2 Comments
Kawee Numpacharoen
Kawee Numpacharoen on 9 Nov 2017
Currently, we do have out-of-the-box solutions for portfolio optimization using mean-variance, CVaR, and mean absolute deviation (MAD). Please see the attached files for both mean-variance and CVaR portfolio optimization.
Dave
Dave on 10 Nov 2017
Thank you -- I was hoping that the financial toolbox provided the tools for robust optimization. Please consider adding out-of-the-box solutions for solving for measures like Sortino Ratio, Treynor Ratio, Max Drawdown, etc. (or at least disclose where one could obtain/purchase these codes). I suspect the financial toolbox was designed to maximize the utility of those facing financial problems, enabling the user to focus more on solutions rather than writing code. Obviously this can't be accomplished for every user's needs; however, portfolio optimization based on the aforementioned variables is FUNDAMENTAL TO FINANCE. In my opinion, not having these features is a major oversight. MATLAB provides several fancy codes for very specific cases related to option pricing, transaction costs, and even market timing. But all of this is ancillary to building an optimal portfolio, which is the end goal of pretty much all investment-related matters.

Sign in to comment.

More Answers (0)

Categories

Find more on Portfolio Optimization and Asset Allocation 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!