robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.38k stars 940 forks source link

Solver 'ECOS' failed. Try another solver, or solve with verbose=True for more information. #393

Closed Ann-eat-apple closed 2 years ago

Ann-eat-apple commented 2 years ago

What are you trying to do? Clear description of the problem you are trying to solve with PyPortfolioOpt

I tried the following:

  ef = EfficientFrontier(mu, S, solver = "ECOS")
  weights = ef.max_sharpe()

Solver 'ECOS' failed. Try another solver, or solve with verbose=True for more information.

Is there any thing that I can do to get a less accurate solution? (and get rid of this error).

What have you tried?

I also tried QRPS and other cvxpy optimizer, problem still persist.

What data are you using? What asset class, how many assets, how many data points. Preferably provide a sample of the dataset as a csv attachment.

robertmartin8 commented 2 years ago

Hi,

Could you try the following:

  1. Check you have solvers installed properly (pip install ecos scs osqp etc)
  2. Run the code without explicitly passing a solver (i.e just EfficientFrontier(mu, S)).
  3. If it's still not working, run with verbose=True as suggested by the error message and post back here.

If the problem persists, could you please share more information about what environment you're using (operating system, python version, pyportfolioopt version) and how you installed.

Cheers, Robert

Ann-eat-apple commented 2 years ago
ECOS 2.0.7 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  -2.513e+13  -6.197e+29  +3e+32  9e-01  6e+00  1e+00  2e+30    ---    ---    1  1  - |  -  - 
Slacks/multipliers leaving the cone, recovering best iterate (0) and stopping.

NUMERICAL PROBLEMS (reached feastol=6.1e+00, reltol=1.3e+19, abstol=3.4e+32)./Users/anne/miniconda3/envs/tf_new/lib/python3.8/site-packages/PyPortfolioOpt-1.2.7-py3.8.egg/pypfopt/risk_models.py:68: UserWarning: The covariance matrix is non positive semidefinite. Amending eigenvalues.
/Users/anne/miniconda3/envs/tf_new/lib/python3.8/site-packages/PyPortfolioOpt-1.2.7-py3.8.egg/pypfopt/risk_models.py:88: UserWarning: Could not fix matrix. Please try a different risk model.

ECOS 2.0.7 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +2.513e+13  -0.000e+00  +1e+30  9e-01  5e-08  1e+00  7e+27    ---    ---    1  1  - |  -  - 
Slacks/multipliers leaving the cone, recovering best iterate (0) and stopping.

NUMERICAL PROBLEMS (reached feastol=9.1e-01, reltol=nan, abstol=1.1e+30).Solver 'ECOS' failed. Try another solver, or solve with verbose=True for more information.
Ann-eat-apple commented 2 years ago

@robertmartin8

robertmartin8 commented 2 years ago

The problem appears to be in your covariance matrix. Could you check that all of your input data is ok? I.e no missing data or infinite returns etc

robertmartin8 commented 2 years ago

Closing due to inactivity. Often, these types of issues are due to data problems (e.g missing data, infinite returns).