dcajasn / Riskfolio-Lib

Portfolio Optimization and Quantitative Strategic Asset Allocation in Python
https://riskfolio-lib.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
3.04k stars 519 forks source link

NaN Values in Mean Variance Risk Measure for Some Assets in HRP Optimization #210

Closed MhmdFasihi closed 3 weeks ago

MhmdFasihi commented 1 month ago

I am currently working on a Hierarchical Risk Parity (HRP) optimization using the riskfolio-lib library and have encountered an issue specifically related to the Mean Variance (MV) risk measure. Here are the details: I have implemented HRP optimization with constraints, and while I am obtaining good results with all other risk measure methods, I consistently receive NaN values for some of my assets when I set MV as the risk measure.

I have attempted to adjust various code dependencies and configurations, but regardless of the changes made, the NaN results persist specifically for the MV risk measure. The issue seems to be isolated to this risk measure, as other methods function correctly. Screenshot 2024-09-26 171239

dcajasn commented 1 month ago

Hi @MhmdFasihi

Can you send a reproducible code?

Best, Dany

MhmdFasihi commented 1 month ago

Hi @dcajasn thank you for your response here is link of my Google Colab code. https://colab.research.google.com/drive/0C2V0O_d2x4jYxlBqNRoASSa6Z?usp=sharing best, mhmd

dcajasn commented 1 month ago

This example not works for me, I need a simple example, like the examples in the example section. That shows where is the problem.

MhmdFasihi commented 1 month ago

sorry, could you please have a look to this https://colab.research.google.com/drive/0C2V0O_d2x4jYxlBqNRoASSa6Z?usp=sharing one more time, it should works for you. and ok now I'm working on writing a sample code.

dcajasn commented 1 month ago

I told you a simple example, your code have too many things that I don't have time to check, I need a simple example that shows where is the problem.

MhmdFasihi commented 1 month ago

Sorry about that @dcajasn Here is simple code based on your sample tutorial. https://colab.research.google.com/drive/1SSWCr

MhmdFasihi commented 4 weeks ago

Hi @dcajasn could you please guide me about this issue? best, Mhmd

dcajasn commented 3 weeks ago

Hi @MhmdFasihi,

I solved the bug (that happens mainly because your data has too extreme values and too zeros returns), but I will released the fix in next riskfolio-lib version in two or three weeks.

Best regards, Dany

dcajasn commented 2 weeks ago

Hi @MhmdFasihi,

Download version 6.3.0 to fix the problem.

Best, Dany