Y.cady
Y.cady

Reputation: 21

optimization with python cvxopt

I am trying to minimize the portfolio variance using Python's cvxopt. However, after lots of trying, it doesn't seem to work. The function and my code and the error are pasted below. Thanks for helping!

the minimize problem

objective function: min x.dot(sigma_mv).dot(x.T)

the constraint condition is all x>=0, sum(X) = 1

sigma_mv is the covariance matrix of 800*800, dim = 800

code

dim = sigma_mv.shape[0]
P = 2*sigma_mv   
q = np.matrix([0.0])
G = -1*np.identity(dim)
h = np.matrix(np.zeros((dim,1)))

sol = solvers.qp(P,q,G,h)

Traceback (most recent call last):

  File "<ipython-input-47-a077fa141ad2>", line 6, in <module>
    sol = solvers.qp(P,q)   

  File "D:\spyder\lib\site-packages\cvxopt\coneprog.py", line 4470, in qp
    return coneqp(P, q, G, h, None, A,  b, initvals, kktsolver = kktsolver, options = options)

  File "D:\spyder\lib\site-packages\cvxopt\coneprog.py", line 1822, in coneqp
    raise ValueError("use of function valued P, G, A requires a "\

ValueError: use of function valued P, G, A requires a user-provided kktsolver

Upvotes: 2

Views: 7655

Answers (1)

sam
sam

Reputation: 2311

You have both equality and inequality constraints so you need to provide all the arguments to the built-in qp solver Gx <=h Ax=b

Here x>=0 can be written as -x<=0 So, G matrix will look like -1*(Identity matrix) and h will a 0 vector Similarly, your A will be an Identity matrix and b will be a unity vector(all elements =1)

Finally, solve expression should look like :

sol=solvers.qp(P, q, G, h, A, b)

Upvotes: 0

Related Questions