czielinski / portfolioopt

Financial Portfolio Optimization Routines in Python
MIT License
303 stars 95 forks source link

Max weights help #5

Closed Atropos123 closed 6 years ago

Atropos123 commented 6 years ago

Hello,

First thank you for sharing your work. I am using the code and find it helpful to me. One thing i am not having success with is incorporating many asset classes. In the create_test_data function the number of assets is 5. I understand how to increase the number but am finding a portfolio with many assets and small weights. I need to constrain the model to set a max and min weight to asset classes. I am trying to find the efficient frontier and create a portfolio with assets selection/population of around 150 but want to limit the weight of a specific asset to a specific number for example 5%. 100/5 = 20 so i am trying to find a fund of only 20 with 150 selections to choose from. I am writing in the hopes that you know a simple and elegant solution. My solutions have not been optimal. Thanks in advanced and i understand if you are busy.

czielinski commented 6 years ago

Hello @Atropos123,

I'm afraid that the problem with the additional restriction of fixing the number of assets with a weight > 0 is not quadratic in nature and, thus, the numerical approach to find optimal solutions used in this library is not applicable. For small asset numbers one could use a (very inefficient) brute force approach by calculating the optimal asset allocation of all possible subsets with 20 assets, but with a universe of 150 assets you would have to solve >10^24 optimization problems, which is practically impossible. Maybe there are suitable algorithms for your problem out there, but I simply don't know.

Otherwise you could come up with some heuristic algorithm and hope that the results will be satisfying. Maybe just selecting the 20 assets with the largest absolute weight can be chosen when normalizing the sum of their weights to unity. Solutions of these form are in general not optimal though.