简体   繁体   中英

NotImplementedError: Creating a deepcopy of a CVXPY expression is not supported. Use .copy() instead

ef = EfficientFrontier(mu, S, weight_bounds=(None, None))
ef.add_constraint(lambda w: w[0] >= 0.2)
ef.add_constraint(lambda w: w[2] == 0.15)
ef.add_constraint(lambda w: w[3] + w[4] <= 0.10)

fig, ax = plt.subplots()
plotting.plot_efficient_frontier(ef, ax=ax, show_assets=True)
plt.show()

Mu is expected return in array form. S is covariance matrix. I got this error.

I'm assuming that you're facing this problem while using the PyPortfolioOpt library?

The line that produces the error is

plotting.plot_efficient_frontier(ef, ax=ax, show_assets=True)

I've had the same error when running this code on python 3.7. The fix was to switch to python 3.10. Then the error dissapears and the plot shows fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM