1

I'm using python code lifted from a quantopian blog in order to find an optimized portfolio.

I've gone through the entire exercise detailed here: https://blog.quantopian.com/markowitz-portfolio-optimization-2/

Everything works like a charm until the last equation in the optimal_portfolio function:

wt = solvers.qp(opt.matrix(x1 * S), -pbar, G, h, A, b)['x']

where I get a super messy error:

C:\Software\Anaconda2\envs\gl-env\lib\site-packages\cvxopt-1.1.8-py2.7-win-amd64.egg\cvxopt\coneprog.py in qp(P, q, G, h, A, b, solver, initvals, **kwargs) 4466 'residual as dual infeasibility certificate': dinfres} 4467 -> 4468 return coneqp(P, q, G, h, None, A, b, initvals, options = options)

C:\Software\Anaconda2\envs\gl-env\lib\site-packages\cvxopt-1.1.8-py2.7-win-amd64.egg\cvxopt\coneprog.py in coneqp(P, q, G, h, dims, A, b, initvals, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxpy, yscal, **kwargs) 2241 # lmbdasq = lambda o lambda. 2242 -> 2243 if iters == 0: W = misc.compute_scaling(s, z, lmbda, dims) 2244 misc.ssqr(lmbdasq, lmbda, dims) 2245

C:\Software\Anaconda2\envs\gl-env\lib\site-packages\cvxopt-1.1.8-py2.7-win-amd64.egg\cvxopt\misc.py in compute_scaling(s, z, lmbda, dims, mnl) 283 284 m = dims['l'] --> 285 W['d'] = base.sqrt( base.div( s[mnl:mnl+m], z[mnl:mnl+m] )) 286 W['di'] = W['d']**-1 287 lmbda[mnl:mnl+m] = base.sqrt( base.mul( s[mnl:mnl+m], z[mnl:mnl+m] ) )

ValueError: domain error

it appears that I might be trying to take the sqrt of a negative number. Any ideas on how to address this?

Werhli
  • 251
  • 1
  • 2
  • 4

0 Answers0