Skip to content
All library documents

Solving the Markowitz Portfolio Problem with Short Positions

Article Quant Q&A · Author: Mr. N

Summary

The document addresses a question about why portfolio weights from a mean variance optimization may not sum to one when short selling is allowed. It presents the Lagrange multiplier setup for minimizing portfolio variance subject to a budget constraint and a target expected return. The answer derives portfolio weights from the covariance matrix and expected returns, then uses the constraints to form a two equation system for the multipliers.

Key ideas

  • Short positions do not remove the budget constraint that portfolio weights sum to one.
  • The variance minimization problem uses constraints for total capital and target expected return.
  • The optimal weights can be derived from the covariance matrix and two Lagrange multipliers.
  • The multipliers are determined by solving a two equation system built from the constraints.
  • The questioner later attributed the unexpected weights to an implementation error involving the norm used.

Tags

Full text
# Weights don't add up to one Markowitz Portfolio Model


# Weights don't add up to one Markowitz Portfolio Model












I have recently implemented MPT in Python, however, when I allow negative weights (short selling), they do not add up to one. Isn't it suppose not to happen? On the other hand, when I don't allow, they add up to one as usual.

Here's what I did:

- Defined the return as usual: $\vec{W}^{T} \vec{R}$, where $\vec{W}$ have all the weights and $\vec{R}$ is the random vector of the returns;

- Calculated the expected returns and the covariance matrix all as percentages;

- Defined risk as the standard deviation, which satisfies: $\sigma^2(\vec{W}) = \vec{W}^{T} \Sigma \vec{W}$;

- Minimized $\sigma^2(\vec{W})$ under i) $\vec{W}^{T} \vec{I}=1$, where $\vec{I} = [1\,\ 1 \cdots 1]^{T}$ and ii) $\vec{W}^{T} \mathbb{E}[\vec{R}] = \mu_0$, where $\mu_0$ is given;

- Set the lagrangian as follows: $\mathcal{L}(\vec{W}, \lambda_1, \lambda_2) = \sigma^2(\vec{W}) + \lambda_1 (\vec{W}^{T} \vec{I} - 1) + \lambda_2 (\vec{W}^{T} \mathbb{E}[\vec{R}] - \mu_0)$

- Take all partial derivatives and end up in a system of equations like so:

\begin{equation} \begin{bmatrix} 2 \Sigma \,\,\, \vec{I} \,\,\, \mathbb{E}[\vec{R}] \\ \vec{I}^{T} \,\,\, 0 \,\,\, 0 \\ \mathbb{E}[\vec{R}]^{T} \,\,\, 0 \,\,\, 0 \end{bmatrix} \cdot \begin{bmatrix} \vec{W} \\ \lambda_1 \\ \lambda_2 \end{bmatrix} = \begin{bmatrix} \vec{0} \\ 1 \\ \mu_0 \end{bmatrix} \end{equation}

- Since this is a system of $A \vec{x} = \vec{b}(\mu_0)$ kind and $\vec{b}$ is parametrized by $\mu_0$, I used QR factorization to solve it for every $\mu_0$;

- Once I have the solution $\vec{x}$, I have the weights given by $\vec{W}$ as well. Therefore, it's been solved.

Is there anything missing? Does it happen commonly?

Thanks

EDIT

Thank you guys, I managed to solve the problem. The function I created to calculate all the weights was incorrect (I was using norm 1).

## Answer by foreignvol (score 1)

https://quant.stackexchange.com/a/68482

We will use bold notation for vectors and write $\pmb \mu = \mathbb E[\vec R]$.

From the first equation you have $$\pmb w = \frac 12 \pmb\Sigma^{-1}\left(\pmb 1^T\lambda_1 + \pmb\mu\lambda_2\right).$$ Hence, we will first find $\lambda_1$ and $\lambda_2$. Using the constraints, we may write \begin{aligned} 1 = \pmb1^T\pmb w &= \frac 12 \pmb1^T\pmb\Sigma^{-1}\left(\pmb 1^T\lambda_1 + \pmb\mu\lambda_2\right)\\ \mu_0 = \pmb \mu^T\pmb w &= \frac 12 \pmb\mu^T\pmb\Sigma^{-1}\left(\pmb 1^T\lambda_1 + \pmb\mu\lambda_2\right) \end{aligned} In other words, we need to solve the system

$$ \frac 12\begin{bmatrix} \pmb 1^T \pmb \Sigma^{-1}\pmb 1^T & \pmb 1^T \pmb \Sigma^{-1}\pmb \mu^T\\ \pmb 1^T \pmb \Sigma^{-1}\pmb \mu^T & \pmb \mu^T \pmb \Sigma^{-1}\pmb \mu^T \end{bmatrix}\begin{bmatrix} \lambda_1\\ \lambda_2 \end{bmatrix} = \begin{bmatrix} 1\\ \mu_0 \end{bmatrix}. $$

The solution is given by $$ \pmb\lambda = \frac{2}{(\pmb 1^T \pmb \Sigma^{-1}\pmb 1^T)(\pmb \mu^T \pmb \Sigma^{-1}\pmb \mu^T) - (\pmb 1^T \pmb \Sigma^{-1}\pmb \mu^T)^2}\begin{bmatrix} \pmb \mu^T \pmb \Sigma^{-1}\pmb \mu^T & -\pmb 1^T \pmb \Sigma^{-1}\pmb \mu^T\\ -\pmb 1^T \pmb \Sigma^{-1}\pmb \mu^T & \pmb 1^T \pmb \Sigma^{-1}\pmb 1^T \end{bmatrix}\begin{bmatrix} 1\\ \mu_0 \end{bmatrix}. $$

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.