ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.59k stars 809 forks source link

Cumulative Performance in reports.html does not calculate correctly #343

Open manuelwithbmw opened 3 months ago

manuelwithbmw commented 3 months ago

Hello - It seems to me that the Cumulative Performance in reports.html does not calculate correctly possibly since the point in time where the Strategy performance goes (incidentally) negative - the Sharpe ratio calculation seems okay overall, but if I use the qs.reports.html method as below:

qs.reports.html(returns_df.sharpe, "SPY", rf=0.000066, output = "..path../Strategy Tearsheets/strategy_report.html")

the Cumulative Performance calculation does not adds up correctly, it overestimates my manual calculations. The reports shows 106.83% while I have 84.97% (easily verifiable in my excel file). I made some simulations and it seems the problem arises since the Strategy goes negative, when it goes up, the Report.html overestimate it

Screenshot 2024-04-02 at 11 10 10

Also - it would be nice to know how the risk free has to be entered (here I set rf rate = 0.000066 (shown in the chart as 0.01%), for a 10Y Treasury at 4.25%, is that correct?). I am using 0.000066 as the RF 10Y US Daily Return with a 10Y Treasury at 4.25% should be 0.0066% (formula I am using I Excel is =(POWER((1+4.25),(1/252))-1)/100)

Thank you

GOATsann commented 3 months ago

Bump

DannyMartens commented 3 months ago

Try this: qs.reports.html(returns_df.sharpe, "SPY", rf=0.000066, output = "..path../Strategy Tearsheets/strategy_report.html", compunded=False)

Note also that some others are now maintaining @ https://github.com/Lumiwealth/quantstats_lumi

manuelwithbmw commented 3 months ago

Thank you @DannyMartens - the compound = False has not changed much.

I have also tried installing quantstats_lumi as well and I am comparing the results with quantstats. I can see for now that Lumi overestimates (circa 10%) the Sharpe Ratio of the other library quantstats - anyway I seem to understand the Lumi version is better maintained? Anyway, this difference does not bother me too much

Can you please let me know what is the right way of entering the Risk Free value in the report.html? If we have a US 10 yrs at 4.61% as of now, in the html.report function I am using the Avg RF Daily Returns which according to my calculations (for my time window of observation) would be 0.000066, so I am entering 0.000066 as below:

qs.reports.html(returns_df.sharpe, "SPY", rf=0.000066, output = "/Users/.../Strategy Tearsheets/strategy_report.html")

Is this the right way to use RF rate here?

lorisn commented 2 months ago

I also changed to use https://github.com/Lumiwealth/quantstats_lumi No all problems i had with the original library are fixed, check it out.