# How can I find the portfolio with maximum Sharpe Ratio - Using Lagrange Multipliers

In Markowitz' portfolio theory we can construct portfolios with the minimum variance for a given expected return (or vice versa). Across expected risks, this traces out the well-known efficient frontier.

To find the so-called tangency portfolio, we look to solve:

$$\max_x \frac{\mu^T x}{\sqrt{x^T Q x}}$$

Following Tütüncü (section 5.2), this can be reformulated under a change of variables to a simpler quadratic optimisation problem:

$$\min_{y,\kappa} y^T Q y \qquad \text{where} \quad (\mu-r_f)^T y = 1,\; \kappa > 0$$

I've solved the problem and got values for $y$. However.. $\kappa$ is defined in terms of $x$... So, whilst I'm sure this is a stupid question, how do we actually translate the $y$ vector to recover the true portfolio weights $x$??

The only thing I can think of is that I did not include a constraint for $\kappa$. This is for the same reason as above (that it is defined in terms of $x$, and so not available), and because the KKT conditions suggested in this answer also ignore the $\kappa >0$ term.

• The $\kappa$ must be related to the other variables in the problem, otherwise your formulation does not make much sense. – Alex C Apr 5 '18 at 20:45
• I agree; it doesn't make sense to me. $\kappa$ is introduced on p62 of the book linked in the question, and the formulation is at the bottom of the same page, so perhaps I'm missing a nuance in the mathematical derivation, and how the feasible set $\chi$ is defined? – Zac Apr 6 '18 at 0:59

The trick is in the transformation of the constraints used to solve the optimisation problem. This can be seen in the definition of the set $\chi^+$ in the two lines following equation 5.4 of Tütüncü. So, for example, the usual budget constraint ($e^Tx = 1$) would be replaced by ($e^Tx - \kappa = 0$). After the addition of that constraint, the solution with the maximum Sharpe ratio is $x^* = \frac{\hat{x}}{\hat{\kappa}}$, where $(\hat{x},\hat{\kappa})$ is the solution to the quadratic programming problem (see bottom of page 62).
• Thanks - I see what you mean about multiplying the constraints by a \kappa term now, which I guess is equivalent to $(x,\kappa) \in \chi^{+}$. Unfortunately, I still don't quite see how to use $\kappa$ to change variables; it seems that we can perhaps pick any value, but the simulation I put together suggests that won't work, as I get different values for different $\kappa$, and the weights don't total 1 as required. I've uploaded the simulation here, using a placeholder $\kappa$: publiccode-zac-keskin.notebooks.azure.com/nb/notebooks/… – Zac Apr 6 '18 at 13:04
• The formulation allows for a variable $\kappa$ that can take any positive value. In your code, you are using $\kappa$ as a constraint in your Lagrangean, when you should be augmenting your solution vector with a $\kappa$. In other words, you should be solving for $(x, \kappa)$ rather than $x$. – Tim Wilding Apr 6 '18 at 14:44
• I think that’s the wrong approach. Your Lagrangean is $L(x, \kappa, \lambda_1, \lambda_2)$, and you should be solving for $(x, \kappa, \lambda_1, \lambda_2)$. Hence, your $A$ matrix should be $(N+3) \times (N+3)$. There should be an extra row for $\frac{\partial L}{\partial \kappa} = \lambda_1$. Your $b$ values should be all 0, apart from the $\lambda_2$ entry, which should be 1. – Tim Wilding Apr 6 '18 at 17:44
• Thank you - I think I've roughly done what you suggest, but I think that there's only one constraint in $\lambda$? In total I see two constraints: $e^Tx -\kappa = 0$ and $(\mu-r)^Tx = 1$ but maybe that is wrong? I implemented that now at publiccode-zac-keskin.notebooks.azure.com/nb/notebooks/… and seem to get portfolio of weight -1 (for any value of N I try).. so seems like I'm close but maybe (hopefully) just a sign gone awry?? – Zac Apr 6 '18 at 18:06
• Sorry I think I get what you mean now, noting the Lagrangian of those four terms. It seems that stationarity requires $\frac{\partial L}{\partial \kappa} = \lambda_1 = 0$, interestingly. This is what I have implemented and I do now get a portfolio of weight 1. However, it appears to be finding the opposite to what we're after.. namely it looks like the portfolio which minimises the Sharpe ratio rather than the maximising portfolio. This should be clear from the plot at publiccode-zac-keskin.notebooks.azure.com/nb/notebooks/…, but I'm not sure why! – Zac Apr 6 '18 at 22:57