robertmartin8 / PyPortfolioOpt

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

How to get binary weights for X number of assets ? #232

Closed usamabaig1 closed 3 years ago

usamabaig1 commented 3 years ago

I'm want to find out the 'x' number of assets in which to invest. Thus the output of the ef.max_sharpe() function should be binary weights (1 or 0) and sum of 1 should be x (meaning that only x assets should be recommended.

I'm using the ef.max_sharpe() function to find the weights. A sample desired output image is attached for x = 3. Kindly help.

robertmartin8 commented 3 years ago

Hi @usamabaig1,

I'm not entirely sure what you're after (the image didn't go through). I'd caution against using PyPortfolioOpt for portfolio selection – it is meant for portfolio optimisation: once you have a set of assets from which you want a portfolio, PyPortfolioOpt will optimise the weights.

Best, Robert

robertmartin8 commented 3 years ago

Closing due to inactivity. Feel free to reopen

kayuksel commented 3 years ago

@usamabaig1 I have implemented a combinatorial optimization algorithm for this some years ago. https://github.com/kayuksel/combinatorial-bandit

I believe that checking the binary neural network literature may also be relevant for this: https://www.sciencedirect.com/science/article/pii/S0031320320300856

I just found a better idea to perform this though and looking forward to trying it asap.

robertmartin8 commented 3 years ago

@kayuksel Thanks for sharing the links!

Somewhat related (but not very applicable): I went to a quantum computing (QC) meetup a couple of years ago and some quant MD was giving a presentation about QC in portfolio optimisation. Apparently, this kind of binary selection problem is an area where QC dominates classical.

Maybe an interesting tidbit for someone with your CS background! Might be a nice source of edge a couple of years from now when AWS has QC servers that ordinary people can provision ;)