Search code examples
pythonpandasnumpyfinance

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.


Solution

  • 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.