def calculate_min_var(cov, lb, ub):
"""Calculate minimum variance portfolio subject to supplied constraints
Inputs: covariance matrix, constraints (lb - lower bound, ub - upper bound)
Output: asset weights
Sum to 1 constraint is added automatically"""
n= len(cov)
P= cvx.matrix(cov)
q = cvx.matrix(0.0, (n, 1))
#G = cvx.matrix(-np.identity(n)) #x>=0
G= cvx.matrix(np.concatenate((-np.identity(n),np.identity(n)), axis=0))
#h = cvx.matrix(0.0, (n, 1)) #x>=0
h= cvx.matrix(np.concatenate((-lb,ub), axis=0),tc='d')
#A = cvx.matrix(1.0, (1, n)) #sum to 1
A = cvx.matrix(1.0, (1, n)) #sum to 1
b = cvx.matrix(1.0) #sum to 1
slv.options['show_progress'] = True
slv.options['abstol'] = 1e-7
slv.options['reltol'] = 1e-6
sol = slv.qp(P, q, G, h, A, b)
arr= np.array(sol['x'])
return arr