QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.48k stars 3.21k forks source link

Adds MaximumRecoveryTime Portfolio Statistics #4581

Open AlexCatarino opened 4 years ago

AlexCatarino commented 4 years ago

Expected Behavior

Funds understand that all algorithms experience drawdowns, and the smaller, the better, but the recovery time is especially important. An algorithm that is in a sustained drawdown for more than 6-months most likely won't be traded by a fund and would likely be dropped if this occurs in live trading. (source)

Actual Behavior

No statistics on the maximum recovery time.

Potential Solution

Implement such measurement.

Checklist

swisstackle commented 1 month ago

@jaredbroad I took a quick look at the codebase. Would this be implemented in Common\Statistics\Statistics.cs and then added to the StatisticsBuilder ?

I think I would also have to add a ReportElement and feed the statistic with data in Report.cs (backtestresult and/or liveresult), correct?

jaredbroad commented 1 month ago

Yes perfect @swisstackle, to make it show in the footer of the backtest view it would need to end up in the Dictionary here.

swisstackle commented 1 month ago

@jaredbroad Do you have a formal definition of maximum recovery time?

With daily prices {100, 98,99,98,99}, is the maximum recovery time non-existent or 1 day?

I'm asking because if it's 1 day, the statistic seems useless in scenarios like {100,98, 99,98,99,50,0}, where the strategy never truly recovers, yet the maximum recovery time would still be 1 making it look good.

jaredbroad commented 4 weeks ago

@swisstackle We think the right answer is for it to return null/inf in your example above; the view might need to be adjusted to handle the inf/null values but if you make the PR return the correct value we'll handle the rest.

swisstackle commented 4 weeks ago

@jaredbroad Ok, when I get time to work on this, I will go for the "recovery time of the maximum drawdown" which fits your description and then we can make adjustments later.