robertmartin8 / PyPortfolioOpt

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

A few questions about mean variance optimization and ef.max_sharpe() #179

Closed gtamba closed 4 years ago

gtamba commented 4 years ago

Hello! First of all thanks a lot for this library it has a very nice interface and the code is a great reference to harden the loose ends on concepts I have only recently began learning.

I did have a question about mean variance optimization, I am trying to allocate an optimal portfolio among a set of asset classes. The expected returns tend to be negative for 2 or 3 out of 5 asset classes, but when I try to calculate an EfficientFronter using ef.max_sharpe() I get the error Please check your objectives/constraints or use a different solver. This could potentially be related to #88 but I see that the OP was able to proceed by using the non convex solver from SciPy. While max_sharpe() fails, min_volatility() does not so I was wondering if the issue is related to the convexness of the problem, or the fact that I am trying to optimize both returns and volatility with assets that have fairly negative returns. For what it's worth I would expect the negative performing assets to be assigned 0 weights, but I could also theorize that those negative performing assets have the least volatility, making the problem unsolvable for max sharpe ratio? This is just conjecture and I'd like to hear your opinion on the matter.

robertmartin8 commented 4 years ago

Hi @gtamba,

Thanks for the question! I think you're spot on with the explanation. If you have assets with very low volatility, that can also cause numerical problems (because it is in the denominator of the Sharpe ratio). All the more so if the numerator is negative.

In a situation like this, I would try using a method like the critical line algorithm, which is a bit more robust.

Cheers, Robert

gtamba commented 4 years ago

Indeed the critical line algorithm worked for max_sharpe() without any optimization errors, thank you for the prompt response! I'll close this but if you have any reference summarizing the tradeoffs off the top of your head I'd be grateful :)