# Is my python solution good? : Global Minimum Variance portfolio with 'no-short sale' constraint

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

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.