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) 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
解决方案
It should be cvx.sum_entries instead of sum_entries. Similarly, your Problem should be cvx.Problem.