2

I am trying to resolve a portfolio optimization problem in Python using CVXPY but getting an error sum_entries is not defined. I am using Anaconda 2.7 and Jupyter notebook. I have installed cvxpy, msgpack, argpack and cvxopt using conda pip install. Below is the snippet of the code. Any suggestions?

w=Variable(len(CovMatrix))
risk=quad_form(w,Sigma)
constraints=[]
constraints.append(w>=0)
constraints.append(sum_entries(w)==1)
prob=Problem(cvx.Minimize(risk),constraints)
prob.solve(solver='CVXOPT',verbose=True)

Here is the error I am getting:

NameError Traceback (most recent call last) <ipython-input-20-7f2f1e65a66e> in <module>() 4 constraints=[] 5 constraints.append(w>=0) ----> 6 constraints.append(sum_entries(w)==1) 7 8 

prob=Problem(cvx.Minimize(risk),constraints) NameError: name 
AnilRedshift
  • 7,937
  • 7
  • 35
  • 59
  • --------------------------------------------------------------------------- NameError Traceback (most recent call last) in () 4 constraints=[] 5 constraints.append(w>=0) ----> 6 constraints.append(sum_entries(w)==1) 7 8 prob=Problem(cvx.Minimize(risk),constraints) NameError: name 'sum_entries' is not defined – Sumit Malhotra Jul 02 '18 at 15:18

1 Answers1

1

It should be cvx.sum_entries instead of sum_entries. Similarly, your Problem should be cvx.Problem.

Snakes and Coffee
  • 8,747
  • 4
  • 40
  • 60