robertmartin8 / PyPortfolioOpt

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

Feature request: Replace cvxpy by cvxpy-base #511

Open tschm opened 1 year ago

tschm commented 1 year ago

Hi Robert, I can work on this feature during my holiday. Most professional shops (they all use your package) use professional solvers such as Mosek or Gorubi. The solvers that come with cvxpy are somewhat a pain. See the discussion here: https://github.com/cvxpy/cvxpy/issues/1478 I will make "solvers" an extra in your pyproject.toml file and only if explicitly specified they will be installed. Maybe @phschiele has a better idea? Best wishes for 2023 Thomas

robertmartin8 commented 1 year ago

Hey Thomas, nice to hear from you and merry Christmas!

415 is relevant here.

I think my concern is that "retail" users will then have to pip install pyportfolioopt ecos scs, without really knowing/caring what ecos and scs are. So the pip install pyportfolioopt is quite a nice thing to have for them.

I wonder if there's some PyPI way to predefine a flag, such that:

pip install pyportfolioopt  # installs everything by default
pip install pyportfolioopt --no-solvers  # just cvxpy-base

Eager for peoples' opinions on the matter.

tschm commented 1 year ago

Of course, it shall remain as easy as possible for the retail users. Your idea is correct, but I am not sure I can implement the negation as in --no-solvers. It would look more like

# with no solver
pip install pyportfolioopt

# with all free solvers
pip install pyportfolioopt[solvers]

# with specific solver(s) only
pip install pyportfolioopt[ecos, scs]

This is described here https://python-poetry.org/docs/pyproject#extras

Robert, Merry Christmas! I hope you like my gift ;-)

phschiele commented 1 year ago

I agree with the notion that pyportfolioopt should come "batteries included".

Similar to what you describe above, the ideal setup would look like:

# with default solvers
pip install pyportfolioopt

# with no solvers
pip install pyportfolioopt[no-solvers]

Based on some recent discussions, this still does not seem to be possible at the moment. This is also the reason why cvxpy-base exists in the first place, because the same logic would apply there (pip install cvxpy[no-solvers). One possibility would be to extend this handling to pyportfolioopt until the installation becomes sufficiently expressive, i.e., create pyportfolioopt-base, but that would of course create some overhead (see here for the cvxpy-base implementation).

tschm commented 1 year ago

@phschiele, I would prefer the batteries-included, too. However, poetry is not there yet and I am not sure it will move into that direction.

There's another aspect I would like to mention. If you establish the solvers as extras you could define mosek and gorubi as extras and then there is https://github.com/oxfordcontrol/Clarabel.rs. Users would of course contact Mosek or Gorubi for a valid license...

I also think that an error message like "No solver has been installed" is much easier to handle than "numpy issues vs ecos, multiarray broken, ...". After all, a standard without any solver is not too bad.