问题
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
回答1:
It should be cvx.sum_entries
instead of sum_entries
. Similarly, your Problem
should be cvx.Problem
.
来源:https://stackoverflow.com/questions/51139272/cvxpysum-entries-is-not-defined