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).