# Portfolio Optimization Problem

I have the following expression for which I wish to find the $$\vec{w}$$ which minimizes it:

$$L = \frac{\vec{w}^TA\vec{w}}{\vec{w}^TB\vec{w}} - \lambda(\vec{w}^T\vec{1} - 1)$$

The partial derivates with respect to $$\vec{w}$$ and $$\lambda$$ are as follows

\begin{align*} \frac{\partial L}{\partial \vec{w}} &= \frac{2(\vec{w}^TB\vec{w})A\vec{w}-2(\vec{w}^TA\vec{w})B\vec{w}}{(\vec{w}^TB\vec{w})^2} - \lambda \\ \frac{\partial L}{\partial \lambda} &= -\vec{w}^T\vec{1} + 1 \end{align*}

But I'm having a hard time simplifying these to get the minimizing value of $$\vec{w}$$. Any insights?

• Would you mind explaining what A and B stands for? Thanks
– T123
May 13, 2022 at 16:23
• They are both nxn matrices, and $\vec{w}$ is an nx1 vector May 13, 2022 at 16:40
• If you want more detail than that: $$A = \Sigma - \sigma_D^2; B = \sigma_D1\sigma_D - \sigma_D^2$$ where $\Sigma =$ Covariance matrix of assets, $\sigma_D =$ diagonal matrix showing each asset's standard deviations (so $\sigma_D^2$ is the same but with variances), and the $1$ matrix is simply an nxn matrix filled with ones. $A$ is therefore essentially a matrix filled with the covariances between each asset but with zeros along the diagonal. May 13, 2022 at 16:53

Due to the $$\vec w^TB\vec w$$ in the denominator, you have to solve this problem numerically, either as a direct minimization with a constraint, or by finding the roots of the two Lagrangian equations after taking partial derivatives.
$$min_\vec{w} \left(\frac{\vec{w}^TA\vec{w}}{\vec{w}^TB\vec{w}}\right) \quad s.t. \quad\vec{w}^T \vec{1}-1 = 0.$$ In Python this can be done e.g. using scipy.optimize.minimize with equality constraint argument specified.
$$\frac{\partial L}{\partial \vec{w}} = 0 \\ \frac{\partial L}{\partial \lambda} = 0,$$ by finding the vector $$\vec{w}$$ and the value of $$\lambda$$ that solves the two equations (root finding). In Python this can be done using scipy.optimize.root.