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


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

Sorry to be the bearer of bad news, but this approach is not guaranteed to be the MinVol solution ;-(

The problem is that the long weights are only MV and weighted thus alongside the shorts (which the model thinks it can short-sell to hedge). If you ignore the shorts, then the longs won't then be MV in isolation. There is probably a long-only portfolio with a lower vol. That is not to say your algo isn't a "low vol" solution, of course.

To solve this, there are two possible iterative methods: 1) Run the equation above exactly as you have. Re-sample excluding any assets with a negative weight; and re-run until none are negative.

Else: 2) For each asset, calculate the volatility of a portfolio 1 basis point long that asset and 99.99% the current portfolio. Switch for every asset where the blended mix has a lower vol than the current mix; until none do anymore.

I don't know of any closed-form solutions to this kind of problem; so I suppose what kind of iterative solution qualifies as a "solver" is moot here.

  • $\begingroup$ I have tried your first solution, but the result is more different compared to the result of 'solver method' than my method. Is it mathematically proven that the first method would show the same result as the solver's method such as scipy.minimize or cvxopt? $\endgroup$ – Eiffelbear Oct 22 '19 at 11:35
  • $\begingroup$ Hi, interesting. I can’t think of any reason why MV for the two sample sets should be any different. I suppose there’s a simple test. Which one has the lower portf9lio vol? If both are long-only with weights that sum to 1, then it’s obvious which approach is ultimately right. $\endgroup$ – demully Oct 22 '19 at 18:57

There is no closed-form analytical solution for the long-only minimum-variance portfolio. Only the the unconstrained (short-sales allowed) portfolio. See here.

Modifying the unconstrained portfolio to become the constrained portfolio in the manner you described is not going to be equal to the true constrained portfolio solution, which must be obtained by convex optimization (quadratic programming).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.