# 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. Apr 5, 2018 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, 2018 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).

• 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$. Apr 6, 2018 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. Apr 6, 2018 at 17:44

H is the hessian matrix

f = [0;0;0;0;0;0;0;0;0;0;0];
n = 10;
rf = 0.0082;
ExpReturns =  -0.00591 + 0.002 * (1:10)';

% Optimization problem data
lb = zeros(n+1,1);
ub = inf*ones(n+1,1);
F = ones(n,1);
Aeq = [( AvrReturn- rf)' 0;ones(1,n) -1];
beq = [1; 0];
A = [eye(n),-1*ones(n,1)];
b = zeros(n,1);
[x4 fval4,exitflag,output] = quadprog(H,f,A,b,Aeq,beq,lb,ub)
y = x4(1:n);
k = x4(n + 1);
x = x4/k;

• " ExpReturn" and "F " are not useful in the code, there should be ignored. Apr 14, 2020 at 19:50