robertmartin8 / PyPortfolioOpt

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

Max/Min Number of Assets for the optimized Portfolio (pypfopt.efficient_frontier.EfficientCVaR) #529

Open fstuelzebach opened 1 year ago

fstuelzebach commented 1 year ago

What are you trying to do? I am optimizing via the pypfopt.efficient_frontier.EfficientCVaR (mainly with efficient_risk() / efficient_return())

I was wondering how one could implement a min. or max. limit regarding the number of assets which the optimized portfolio should hold (as another restriction - like atleast 10 stocks or not more than 30 for example).

In my case efficient_risk() with ratio = 0.2 for example leads to very clumped portfolios for example and even for efficient_return() at ratios between 0.06 und 0.15 out of 52 assets it for example only considers 8 at best.

I am relatively new to python and could really use some help :)

If such a feature already exists i truly am sorry for bringing it up. Thanks in advance for the feedback and of course for the amazing module!

What data are you using? I am using mainly stocks and optimizing the CVaR for a potential list of >50 assets.

88d52bdba0366127fffca9dfa93895 commented 1 year ago

Hi @fstulle,

That kind of stuff is not currently supported, as it requires an additional and complex constraint. I could give you a single line of code for this constraint, but I cannot guarantee the results, so I won’t do that here.

However, I believe this feature (min and/or max number of assets) would be useful for others, especially for practitioners. I’d like to include it in our next version. I hope this will be useful for you and others.

schlafen318 commented 1 year ago

Any update on this? thanks.

Liam-Deacon commented 5 months ago

In addition to min/max number of assets, it would be great to be able state which ones must be included in the result (which must be < nmax). For example we may want at least 3 assets in our portfolio, but we always want to have GOOGL included.