Question
- Is my python code an answer (at least a close answer) to get the weight vector of the Global Minimum Variance portfolio problem? My codes are shown below after some explanations.
Details to add
The GMV with no-short sale constraint portfolio problem can be described as below :
$$\boldsymbol{w}_{G M V}=\arg \min \left\{\boldsymbol{w}^\top \Sigma \boldsymbol{w} \enspace : \enspace \boldsymbol{w}^\top \mathbf{1}_{N}=1, \enspace w>0\right\}$$
$\boldsymbol{w}=\left(w_{1}, \ldots, w_{n}\right)^\top$ is a vector of portfolio weights
$\Sigma$ is a variance covariance matrix of assets (stocks)
$\mathbf{1}_{N}$ is a $N$ dimensional vector of ones
The answer to the problem if the short sales are allowed, can be calculated as below :
$$ \boldsymbol{w}_{G M V}=\frac{\sum^{-1} \mathbf{1}_{N}}{\mathbf{1}_{N}^\top \Sigma^{-1} \mathbf{1}_{N}} $$
According to the question 'Tangent portfolio weights without short sales?' from mathematics stack exchange, we do not have an analytical solution to the GMV problem with no short-sales constraints.
My python code answer to this is simple ; Set the negative weights in $\boldsymbol{w}_{G M V}$ coming out of the calculation above to 0, and with the rest positive weights, make them sum up to 1. The code is shown as below.
cov_df = stock_data_df.cov()
inverse_cov_df = np.linalg.pinv(cov_df)
numerator = np.matmul(np.ones(20).T, inverse_cov_df)
denominator = np.matmul(np.ones(20), (np.matmul(inverse_cov_df, np.ones(20))))
GMV_weight_vector = numerator / denominator
GMV_weight_vector[GMV_weight_vector < 0] = 0
GMV_weight_vector = GMV_weight_vector/(GMV_weight_vector.sum())
- The
stock_data_df
has 20 stocks' 252 day-long daily return. - The last 2 line at the bottom is the line that suffice the 'no-short selling constraint'.
- I am curious to know if these 2 lines are good enough to be consider an answer to the GMV portfolio problem without short-selling constraint.
Disclaimer
- Many python libraries such as Pyportfolioopt uses the scipy.minimize function to solve this problem of 'no short-selling constraint', but I am not allowed to use any solver in my assignment.