CVXOPT can not find an optimal solution and quits with ValueError: domain error

817 views
Skip to first unread message

vr...@cornell.edu

unread,
Feb 4, 2017, 2:21:27 PM2/4/17
to CVXOPT
I have the following code:

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

I call it using: 
t_opt_perc2= mtc.calculate_min_var(test_cov, lb_dec, ub_dec)

I have attached covariance matrix, lower bound and upper bound constraints that give me an error. (I tried scaling constraints and inputs by 100 - it did not help. Unconstrained case works fine (lb=0, ub=0))

This code is calculating constrained minimum variance portfolio with upper bound set to market cap weight * 1.2 (or any other k>1 for that matter) and lower bound set to market cap weight * 0.8 (or, once again any k less than 1). In my use case, lower and upper bounds are always symmetric (lower bound + upper bound = 2). 

This code quits with ValueError: domain error. I wasn't able to debug it myself. Covariance matrix is well conditioned.

Can please somebody explain to me what is going on and how I can fix it?

I would really appreciate your help.

Thanks in advance,
Vitaliy
covariance.npy
lower bound.npy
upper bound.npy

vr...@cornell.edu

unread,
Feb 12, 2017, 3:49:00 PM2/12/17
to CVXOPT
I managed to fix my own problem. Upper bound is less than 1, I hope it helps if someone experiences a similar issue

Agnello Hupp

unread,
Jul 21, 2017, 3:02:13 AM7/21/17
to CVXOPT
I'm having the same problem.

Does the code remain the same?

Thank you for sharing
Reply all
Reply to author
Forward
0 new messages