Maximizing the Sharpe Ratio with Long-Only Portfolio Weights
Summary
The document considers choosing nonnegative stock allocations under a fixed budget to maximize a portfolio’s historical Sharpe ratio. The response identifies the target as the tangency portfolio and recommends formulating the problem with asset returns, expected returns, and their covariance matrix rather than portfolio values derived directly from adjusted closing prices. It also notes that total returns should account for distributions.
For the unconstrained basic case, the response points to solving a linear system involving the covariance matrix and expected returns. With long-only constraints, it describes tracing the efficient frontier by repeatedly minimizing portfolio variance subject to a target expected return, full investment, and nonnegative weights. These quadratic programs can be solved globally for a reasonable number of assets, after which the tangency portfolio can be selected. The key limitation is input uncertainty: expected return and covariance estimates can be poor, producing unstable allocations. Bayesian estimation or regularization are mentioned as possible responses, but no specific estimator or out-of-sample evidence is provided.
Key ideas
- The Sharpe-maximizing portfolio is commonly called the tangency portfolio.
- Portfolio formulation should use returns, expected returns, and the return covariance matrix.
- Total returns should include distributions as well as price changes.
- Long-only efficient frontier points can be found with constrained quadratic optimization.
- Noisy expected return and covariance estimates can make optimized weights unreliable.
Tags
Full text
# How to maximize the Sharpe ratio given historical closing prices?
# How to maximize the Sharpe ratio given historical closing prices?
I have historical adjusted closing prices for $k$ stocks over $n$ days. I have a budget of $B$ dollars, and I'd like to choose allocations for each of the stocks, $a_{1:k}$, such that I maximize the Sharpe ratio for this time period.
More formally:
\begin{align*} \text{given } & c_{i, j} \text{ for } i=1...n, \; j=1...k && \text{adjusted close of stock } j \text{ on day } i \\ \text{and } & B && \text{total budget} \\ \text{find } & a_{1:k} && \text{allocations for each stock} \\ \text{that maximize } & s = \frac{\mu}{\sigma} && \text{Sharpe ratio} \\ \text{where } & \mu = \frac{1}{n} \sum_{i=1}^n r_i && \text{sample mean of the daily returns} \\ & \sigma = \sqrt{\frac{1}{n}\sum_{i=1}^n (r_i - \mu)^2} && \text{sample standard deviation of the daily returns} \\ & r_1 = 0 && \text{return on day one is zero} \\ & r_i = \frac{p_i}{p_{i-1}} - 1 \;\; \text{for } i=2...n && \text{percent change in portfolio value on day } i \\ & p_i = a^{\top} c_i && \text{portfolio value on day } i \\ \text{subject to } & a_j \geq 0 \text{ for } j = 1...k && \text{only non-negative allocations for each stock} \\ & \sum_{j=1}^k a_j = B && \text{must use total budget} \end{align*}
One way I tried solving this was simply setting $a_{1:k} = B \times \texttt{softmax}(w_{1:k})$ or $a_{1:k} = B \times \frac{\texttt{relu}(w_{1:k})}{\texttt{sum}(\texttt{relu}(w_{1:k}))}$, for some latent variables $w_{1:k}$, and then running gradient ascent using TensorFlow. This works well in practice, but I'm wondering if there is a better way (i.e., something with guaranteed convergence to the global maximum).
## Answer by Matthew Gunn (score 3, accepted)
https://quant.stackexchange.com/a/35993
#### Several comments:
- What you're looking for in known in finance and portfolio theory as the tangency portfolio.
- Your formulation of the problem is imprecise/problematic. It's much cleaner to formulate this problem in terms of portfolio weights, returns, and covariance of returns, rather than with prices. Along those lines, where's the covariance matrix of returns? Portfolio variance with portfolio weights $w_1, \ldots, w_m$ can be written as $\sum_{ij} \operatorname{Cov}(r_i, r_j) w_i w_j$ or with covariance matrix $\Sigma$ and portfolio weight vector $\mathbf{w}$ as $\mathbf{w}' \Sigma \mathbf{w}$. Returns are $\frac{P_t + D_t}{P_{t-1}}$, that is, you must include distributions. (Use a data provider that calculates returns for you.)
- There are excellent resources across the Internet on the basics of Markowitz portfolio theory.
- The solution to this problem in its most basic form can be trivially found once you solve the linear system $\Sigma \mathbf{x} = \boldsymbol{\mu}$ for $\mathbf{x}$. Using gradient descent to solve this problem strikes me as a big bizarre.
- In practice, a big problem is that your estimates of expected returns are garbage and estimates of covariance are poor. Garbage in, garbage out. Possible solutions? Explicit Bayesian methods or regularlization etc.... See Cochrane (2007) and his section on wacky weights.
#### An intuitive, numerical approach with no short sale constraints
These these slides from Eric Zivot given an overview.
Financial portfolio theory defines the efficient frontier as the curve showing the lowest standard deviation that can achieve a given expected return.
Points along the efficient frontier can be found numerically by solving an optimization problem. To find a non-negative portfolio weight vector $\mathbf{w}\succeq \mathbf{0}$ that achieve expected return $\mu_p$ at minimum variance, solve:
$$ \begin{equation} \begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over $\mathbf{w}$)} & \mathbf{w}'\Sigma\mathbf{w} \\ \mbox{subject to} & \mathbf{w}'\boldsymbol{\mu} = \mu_p \\ & \mathbf{w}'\mathbf{1} = 1 \\ & \mathbf{w} \succeq \mathbf{0} \end{array} \end{equation} $$ Then portfolio variance is $\sigma^2_p = \mathbf{w}' \Sigma \mathbf{w}$.
For reasonable number of assets, this quadratic programming problem can be solved close to instantaneously for a global solution. Starting with the minimum variance portfolio, you can solve then this problem multiple times with different $\mu_p$ values to trace out the efficient frontier, and then you can find the tangency portfolio.
#### References:
Cochrane, John, "Portfolio Theory, 2007, "Portfolio Theory"Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.