# Maximum Sharpe portfolio (no short selling restrictions)

Suppose we have $$n$$ assets whose expected return vector is $$r$$ and is positive, and whose covariance matrix is $$\Sigma$$. Is there a closed form or quasi closed form (like the eigenvector of a matrix etc) solution to the portfolio weights vector $$w$$ which maximises the Sharpe ratio $$w^T r/\sqrt{w^T \Sigma w}$$? (Assume no restriction on short selling.)

If in general its not possible, does a closed form solution exists for low dimensional cases like $$n=2,3$$? I remember being taught a closed form solution for $$n=2$$ in the class. The expression is a bit complicated and unfortunately isn't accompanied with a proof.

I tried differentiating wrt $$w$$ but the gradient is a mess. I don't think we can get anything useful out of it.

Per the comment, the linked source claims that the maximiser is in the direction of $$\Sigma^{-1}r$$. Could someone explain or suggest otherwise? Thanks.

• If you have no constraints, you only need to solve a linear system (i.e. no optimisation). See comisef.wikidot.com/tutorial:tangencyportfolio Commented Feb 12, 2019 at 8:23
• @EnricoSchumann thanks. Usually we require no short selling though.
– Vim
Commented Feb 12, 2019 at 8:28
• OK, then I doubt a generic closed-form solution exists. With inequality constraints, you'll need to solve an optimisation model. Commented Feb 12, 2019 at 8:31
• @EnricoSchumann in case of no constraints, could you provide a concret expression for this? The link you posted doesn't seem to give an explicit expression.
– Vim
Commented Feb 12, 2019 at 8:33
• You need to solve \Sigma^{-1}\mu, in which \Sigma is the variance--covariance matrix and \mu are the expected excess returns. (It's the third method in the link.) Commented Feb 12, 2019 at 8:36

There are two cases, where short sales are allowed: With riskless lending and borrowing and without. As mentioned in the comments, you just have to solve a linear system.

## With riskless lending and borrowing

The existence of a riskless lending and borrowing rate $$r_f$$ implies that there is a single portfolio of risky assets, that is preferred to all other portfolios. You want to maximize the function

$$\theta = \frac{\bar{R}_P - R_f}{\sigma_p}$$

subject to the constraint $$\sum_{i=1}^N X_i = 1$$.

$$\bar{R}_P$$ denotes the average portfolio return of $$N$$ assets $$i$$ with weights $$X_i$$ and $$\sigma_P$$ is the standard deviation of portfolio returns. From the definition of portfolio return, $$R_f = 1 \cdot R_f = \left( \sum_{i=1}^N X_i \right) \cdot R_f = \sum_{i=1}^N (X_iR_f)$$, and their standard deviation, you get

$$\theta = \frac{\sum_{i=1}^N X_i(\bar{R}_i - R_f)}{\left[ \sum_{i=1}^N (X_i^2 \sigma_i^2) + \sum_{i=1}^N \sum_{\substack{j=1 \\ j\neq i}}^N X_iX_j\sigma_{ij} \right]^{\frac{1}{2}}}$$ where $$\sigma{ij}$$ is the covariance of asset returns $$r_i$$ and $$r_j$$.

It is a simple maximization problem, you take the derivative with respect to each variable and set it equal to zero. You get a system of equations:

1. $$\frac{d\theta}{dX_1}=0$$
2. $$\frac{d\theta}{dX_2}=0$$
3. $$\frac{d\theta}{dX_i}=0$$
4. ...

In general: $$\frac{d\theta}{dX_i}=-(\lambda X_1\sigma_{1i}+\lambda X_2\sigma_{2i}+ ... + \lambda X_i\sigma_{i}^2+ ...+\lambda X_{N-1}\sigma_{N-1,i}+\lambda X_{N}\sigma_{Ni})+\bar{R}_i - R_f = 0$$

with

$$\lambda = \frac{\sum_{i=1}^N X_i(\bar{R}_i - R_f)}{ \sum_{i=1}^N (X_i^2 \sigma_i^2) + \sum_{i=1}^N \sum_{\substack{j=1 \\ j\neq i}}^N X_iX_j\sigma_{ij} }$$

After defining a new variable $$Z_k = \lambda X_k$$, the formulation simplifies to the system (lets call it A):

$$\bar{R}_1 - R_f = Z_1\sigma_1^2 + Z_2 \sigma_{12}+Z_3 \sigma_{13}+Z_N \sigma_{1N}$$ $$\bar{R}_2 - R_f = Z_1\sigma_{12} + Z_2 \sigma_2^2+Z_3 \sigma_{23}+Z_N \sigma_{2N}$$ $$...$$ $$\bar{R}_N - R_f = Z_1\sigma_{1N} + Z_2 \sigma_{2N}+Z_3 \sigma_{3N}+Z_N \sigma_N^2$$

The $$Z_N$$ are proportional to the optimum amount to invest in each security. First, solve the above system for $$Z_N$$, then the optimum weight $$X_k$$ for each asset $$k$$ is

$$X_k = \frac{Z_k}{\sum_{i=1}^N Z_i}$$

## Without riskless lending and borrowing

If a riskless rate $$R_f$$ is not available, the solution above has to be modified. Assume that $$R_f$$ exists and find the optimum portfolio with the method above. Then assume a different $$R_f$$ and find the optimum portfolio that corresponds to this slightly changed riskless rate. Continue changing the assumed rate until the full efficient frontier is determined.

Consider again the linear system A. However, we do not have to substitute in a particular value of $$R_f$$. We can simply leave $$R_f$$ as a general parameter and solve for $$Z_k$$ in terms of $$R_f$$. This results in a solution of the form

$$Z_k = C_{0k} + C_{1k}R_f$$

where $$C_{0k}$$ and $$C_{1k}$$ are constants. They have a different value for each asset $$k$$, but that value does not change with changes in $$R_f$$. Once the $$Z_k$$ are determined as functions of $$R_f$$, we could vary $$R_f$$ to determine the amount to invest in each security at various points along the efficient frontier.

Lintner(1965) has an alternative definition of short sales which is more realistic. He assumes correctly that when an investor sells stock short, cash is not received but rather is held as collateral. Furthermore, the investor must put up an additional amount of cash equal to the amount of stock he or she sells short. In summary, the constrain here becomes $$\sum_{i=1}^N \left| X_i \right| = 1$$.

## Reference

Elton/Gruber/Brown/Götzmann (2014), Modern Portfolio Theory and Investment Analysis, ed. 9, John Wiley & Sons.

Let $$R$$ be a random vector of risky returns and let $$r_f$$ denote the risk free rate. Let vector of expected returns $$\boldsymbol{\mu} = \operatorname{E}[R]$$ and covariance matrix $$\Sigma = \operatorname{Cov}(R)$$.

The maximum Sharpe ratio portfolio among risky assets is called the tangency portfolio.

### Quick method to tangency portfolio

Let's find the variance-frontier among ALL assets (including the risk free security) in excess return space. (The return of any zero cost portfolio, i.e. one return minus another, is an excess return.) The tangency portfolio will be the mean-variance efficient portfolio (i.e. has minimum variance given any expected return) with 0 weight on the risk free rate.

Let $$x_i$$ denote the weight on excess return $$R_i - r_f$$ (hence there's a weight of $$1 - \sum_i x_i$$ on the risk free rate).

$$$$\begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over \mathbf{x})} & \frac{1}{2}\mathbf{x}'\Sigma\mathbf{x} \\ \mbox{subject to} & \mathbf{x}'(\boldsymbol{\mu} - r_f) = c - r_f \end{array}$$$$

First order condition:

$$\Sigma \mathbf{x} = \lambda \left( \boldsymbol{\mu} - r_f \right)$$

The portfolio on the frontier comprised only of risky securities ($$\sum_i x_i = 1$$) is:

$$\mathbf{x}_\mathrm{tan} = \frac{\Sigma^{-1} \left( \boldsymbol{\mu} - r_f\right)}{\mathbf{1}' \Sigma^{-1} \left( \boldsymbol{\mu - r_f} \right)}$$

## A full, brute force derivation

Let $$R$$ be a random vector of risky returns and let $$r_f$$ denote the risk free rate. Let vector of expected returns $$\boldsymbol{\mu} = \operatorname{E}[R]$$ and covariance matrix $$\Sigma = \operatorname{Cov}(R)$$.

A classic way to proceed is to first solve for the mean-variance frontier among risky assets, that is, given a desired expected return $$c$$, find the portfolio weights $$\mathbf{w}$$ which minimize variance.

$$$$\begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over w)} & \frac{1}{2}\mathbf{w}'\Sigma \mathbf{w} \\ \mbox{subject to} & \boldsymbol{\mu}' \mathbf{w} = c \\ & \mathbf{1}'\mathbf{w} = 1 \end{array}$$$$ This is a convex optimization problem because it has a convex objective subject to affine constraints. Furthermore Slater's condition is satisfied hence the first order conditions are necessary and sufficient for an optimum. Form the Lagrangian:

$$\mathcal{L} = \mathbf{w}'\Sigma\mathbf{w} - \lambda \boldsymbol{\mu}' \mathbf{w}- \gamma \mathbf{1}'\mathbf{w}$$

The first order condition with respect to $$\mathbf{w}$$:

$$\frac{\partial \mathcal{L}}{\partial \mathbf{w}} = \Sigma \mathbf{w} - \lambda \boldsymbol{\mu} - \gamma \boldsymbol{1} = \mathbf{0}$$

Assuming $$\Sigma$$ is full rank (i.e. no risk free assets or linearly dependent assets):

$$\mathbf{w} = \lambda \Sigma^{-1} \boldsymbol{\mu} + \gamma \Sigma^{-1} \mathbf{1}$$

Now we need to solve for multipliers $$\lambda$$ and $$\gamma$$. Using $$\boldsymbol{\mu}'\mathbf{w} = c$$ and $$\mathbf{1}'\mathbf{w} = 1$$

$$\lambda \boldsymbol{\mu'} \Sigma^{-1} \boldsymbol{\mu} + \gamma \boldsymbol{\mu'} \Sigma^{-1} \mathbf{1} = c \quad \quad \lambda \mathbf{1'} \Sigma^{-1} \boldsymbol{\mu} + \gamma \mathbf{1'} \Sigma^{-1} \mathbf{1} = 1$$

Looks complicated but this is just a simple 2 equation, 2 variable linear system. Let:

$$s_{\mu\mu} = \boldsymbol{\mu'} \Sigma^{-1} \boldsymbol{\mu} \quad \quad s_{1\mu} = \boldsymbol{\mu'} \Sigma^{-1} \mathbf{1} \quad \quad s_{11} = \mathbf{1}' \Sigma^{-1} \mathbf{1}$$

The system and solution is:

$$\begin{bmatrix} s_{\mu\mu} & s_{1\mu} \\ s_{1\mu} & s_{11} \end{bmatrix} \begin{bmatrix} \lambda \\ \gamma \end{bmatrix} = \begin{bmatrix} c \\ 1 \end{bmatrix} \quad \quad \begin{bmatrix} \lambda \\ \gamma \end{bmatrix} = \begin{bmatrix} s_{\mu\mu} & s_{1\mu} \\ s_{1\mu} & s_{11} \end{bmatrix}^{-1} \begin{bmatrix} c \\ 1 \end{bmatrix}$$

Hence:

$$\mathbf{w} = \begin{bmatrix} \Sigma^{-1} \boldsymbol{\mu} & \Sigma^{-1} \mathbf{1} \end{bmatrix} \begin{bmatrix} s_{\mu\mu} & s_{1\mu} \\ s_{1\mu} & s_{11} \end{bmatrix}^{-1} \begin{bmatrix} c \\ 1 \end{bmatrix}$$

This shows that the mean-variance portfolio is a linear with varying weights on vectors $$\Sigma^{-1} \boldsymbol{\mu}$$ and $$\Sigma^{-1} \mathbf{1}$$. This in turn implies the so called two-fund separation result, that the mean-variance frontier is composed of linear combinations of portfolios $$\frac{\Sigma^{-1} \boldsymbol{\mu}}{\mathbf{1}'\Sigma^{-1} \boldsymbol{\mu}}$$ and $$\frac{\Sigma^{-1}\mathbf{1}}{\mathbf{1}'\Sigma^{-1}\mathbf{1}}$$. In portfolio-weight space, the mean-variance frontier is a line.

### Finding the max sharpe ratio:

You can show that at an optimum $$\mathbf{w}$$ the variance is given by:

\begin{align*} \mathbf{w}'\Sigma \mathbf{w} &= \lambda c + \gamma \\ &= \begin{bmatrix} c & 1 \end{bmatrix} \begin{bmatrix} s_{\mu\mu} & s_{1\mu} \\ s_{1\mu} & s_{11} \end{bmatrix}^{-1} \begin{bmatrix} c \\ 1 \end{bmatrix} \\ &= \frac{s_{11}c^2 - 2s_{1u}c +s_{uu}}{s_{11}s_{uu} - s_{1u}^2} \end{align*}

Hence solving for the max Sharpe ratio on the mean-variance frontier can be written as:

$$$$\begin{array}{*2{>{\displaystyle}r}} \mbox{maximize (over c)} & \frac{c - r_f}{\sqrt{ \frac{s_{11}c^2 - 2s_{1u}c +s_{uu}}{s_{11}s_{uu} - s_{1u}^2}} } \end{array}$$$$

Multiply out constant to make problem easier. We only need

$$\frac{d}{dc} \left[\frac{c - r_f}{\sqrt{ s_{11}c^2 - 2s_{1u}c +s_{uu} }}\right] = 0$$

$$\sqrt{ s_{11}c^2 - 2s_{1u}c +s_{uu} } - \frac{1}{2}(c - r_f) \frac{2 cs_{11} - 2 s_{1u}}{\sqrt{ s_{11}c^2 - 2s_{1u}c +s_{uu} }} = 0$$ $$c = \frac{s_{uu} - r_f s_{1u}}{s_{1u} - r_fs_{11}}$$

Therefore for the tangency portfolio: \begin{align*} \mathbf{w}_\mathrm{tan} &= \begin{bmatrix} \Sigma^{-1} \boldsymbol{\mu} & \Sigma^{-1} \mathbf{1} \end{bmatrix} \begin{bmatrix} s_{\mu\mu} & s_{1\mu} \\ s_{1\mu} & s_{11} \end{bmatrix}^{-1} \begin{bmatrix} \frac{s_{uu} - r_f s_{1u}}{s_{1u} - r_fs_{11}} \\ 1 \end{bmatrix} \\ &= \begin{bmatrix} \Sigma^{-1} \boldsymbol{\mu} & \Sigma^{-1} \mathbf{1} \end{bmatrix} \begin{bmatrix} \frac{1}{s_{1u} - r_f s_{11}} \\ \frac{-r_f}{s_{1u}- r_f s_{11}} \end{bmatrix}\\ &= \frac{ \Sigma^{-1} (\boldsymbol{\mu} - r_f)}{\mathbf{1}'\Sigma^{-1} \boldsymbol{\mu} - r_f \mathbf{1}'\Sigma\mathbf{1}}\\ &= \frac{ \Sigma^{-1} (\boldsymbol{\mu} - r_f)}{\mathbf{1}'\Sigma^{-1} \left( \boldsymbol{\mu} - r_f \right) } \end{align*}

Note also the minimum variance portfolio is given by:

$$\mathbf{w}_\mathrm{mvp} = \frac{\Sigma^{-1}\mathbf{1}}{\mathbf{1}'\Sigma^{-1}\mathbf{1}}$$

### Notation note:

I use bold letters for vectors, capital letters for random variables and matrices, and lowercase letters for scalars. $$\mathbf{1} = \begin{bmatrix} 1 \\ 1 \\ \ldots \\ 1 \end{bmatrix}$$ and $$\mathbf{0} = \begin{bmatrix} 0 \\ 0 \\ \ldots \\ 0\end{bmatrix}$$.

• wow! so do I get it right, if I say that in case the assets are uncorrelated, the weights for the tangency portfolio are $w_i = \frac {\frac {\mu_i}{\sigma_i^2}} { \sum {\frac {\mu_k}{\sigma_k^2}} }$ Commented May 13, 2021 at 5:02
• @elemolotiv Yeah, that's it if the assets are uncorrelated and the risk free rate is 0. If the risk free rate is non-zero then you have $w_i = \frac{ \frac{\mu_i - r_f}{\sigma^2_i} }{ \sum_k \frac{\mu_k - r_f}{\sigma^2_k} }.$ Commented May 13, 2021 at 13:00
• @MatthewGunn, this is a very helpful answer. However, I don't understand the first sentence in the "Finding the max sharpe ratio" section. Could you please explain why the first equality holds? Thank you.
– jds
Commented Jan 5, 2022 at 5:18
• @gwg Use $\mathbf{w} = \lambda \Sigma^{-1} \boldsymbol{\mu} + \gamma \Sigma^{-1} \mathbf{1}$ to get $\mathbf{w}'\Sigma\mathbf{w} = \lambda \mathbf{w}' \boldsymbol{\mu} + \gamma \mathbf{w}' \mathbf{1}$ Then use the two constraints. Use that the weights sum to 1: $\mathbf{w}' \mathbf{1} = 1$. Also use that the expected return is $c$: $\mathbf{w}'\boldsymbol{\mu} = c$. Then you get $\mathbf{w}'\Sigma\mathbf{w} = \lambda c + \gamma$. Commented Jan 5, 2022 at 13:57

To complement @skoestimeier's answer on the shortselling-allowed case, I provide a vectorised version. Using the original notation in my post (you may change $$r$$ to something like $$r-r_f$$, but this doesn't affect the algebraic structure). Our goal is to find the maximiser for the problem $$\max_{w}f(w):=\frac{w^T r}{(w^T\Sigma w)^{1/2}}.$$ Let $$\phi: w\mapsto \begin{bmatrix}w^Tr \\ w^T\Sigma w\end{bmatrix},\quad h(x,y):=\frac x {y^{1/2}}$$ Then $$f(w) = h\circ\phi(w)$$, and thus \begin{align} D_wf(w) &= (Dh)(\phi(w)) (D\phi)(w)\\ &=\begin{bmatrix} \frac1{(w^T\Sigma w)^{1/2}} & -\frac{w^T r}{2(w^T\Sigma w)^{3/2}} \end{bmatrix} \begin{bmatrix} r^T \\ 2w^T \Sigma \end{bmatrix}\\ & = \frac1{(w^T\Sigma w)^{3/2}}((w^T\Sigma w) r^T - (w^T r) w^T\Sigma) \end{align} Now let $$D_w f(w)=0$$. Drop the demoninator, and transpose, we get $$r(w^T\Sigma w) - \Sigma w (r^T w)=0$$ Divide each side by $$w^T r$$ to get $$\Sigma w = r\cdot\frac{w^T\Sigma w}{r^T w}=r\cdot \lambda$$ where we let $$\lambda:=\frac{w^T\Sigma w}{r^T w}$$ which is a scalar. Now, we see that $$w=\lambda(\Sigma^{-1} r)$$. But recalling that the function $$f(w)$$ is 0-homogeneous, i.e. rescaling the argument by any nonzero constant doesn't affect the output. Therefore, we only need to care about $$w$$'s direction. So knowing that $$w$$ is in the same direction as $$\Sigma^{-1} r$$ essentially solves the problem. What's left to do is just to rescale by some constant $$\beta$$ such that $$\beta (1^T \Sigma^{-1}r)=1$$ to satisfy the constraint $$1^T w\equiv 1$$, and it is clear that $$\beta = (1^T \Sigma^{-1}r)^{-1}$$. Therefore $$w = \frac{\Sigma^{-1}r}{1^T \Sigma^{-1}r}$$

For the no short selling case, as pointed out in the comments and the accepted answer, the algorithm is much more complicated and no closed form solution exists perhaps.

• (+1) for this excellent mathematical representation! Commented Feb 13, 2019 at 15:49