def solve_minvar(xs_avg, covariance_matrix):
    ' Solve for the weights of the minimum variance portfolio \n\n        Constraints:\n            sum of weights = 1,\n            weights bound by [0, 0.2],\n\n        Returns the weights and the jacobian used to generate the solution.\n        \n        '

    def __minvar(weights, xs_avg, covariance_matrix):
        ' Anonymous function to compute stdv '
        return np.sqrt(np.dot(weights.T, np.dot(weights, covariance_matrix)))
    p_size = len(xs_avg)
    args = (xs_avg, covariance_matrix)
    constraints = [{'type': 'eq', 'fun': (lambda x: (np.sum(x) - 1))}]
    bounds = ([(0, 0.2)] * p_size)
    minimized_weights = optimize.minimize(__minvar, np.zeros(p_size), args=args, method='SLSQP', bounds=bounds, constraints=constraints, options={'maxiter': 1000})
    return minimized_weights
Solve for the weights of the minimum variance portfolio 

Constraints:
    sum of weights = 1,
    weights bound by [0, 0.2],

Returns the weights and the jacobian used to generate the solution.
def solve_minvar(xs_avg, covariance_matrix):
    ' Solve for the weights of the minimum variance portfolio \n\n        Constraints:\n            sum of weights = 1,\n            weights bound by [0, 0.2],\n\n        Returns the weights and the jacobian used to generate the solution.\n        \n        '

    def __minvar(weights, xs_avg, covariance_matrix):
        ' Anonymous function to compute stdv '
        return np.sqrt(np.dot(weights.T, np.dot(weights, covariance_matrix)))
    p_size = len(xs_avg)
    args = (xs_avg, covariance_matrix)
    constraints = [{'type': 'eq', 'fun': (lambda x: (np.sum(x) - 1))}]
    bounds = ([(0, 0.2)] * p_size)
    minimized_weights = optimize.minimize(__minvar, np.zeros(p_size), args=args, method='SLSQP', bounds=bounds, constraints=constraints, options={'maxiter': 1000})
    return minimized_weights