qis.compute_drawdowns_stats_table¶
- qis.compute_drawdowns_stats_table(price, max_num=None, freq='D')[source]¶
Compute a sorted table of drawdown episodes and their statistics.
The series is first rebased to
freqwith forward filling (kept on its own grid forfreq=None). An episode is a maximal run of consecutive grid points below the running peak. Itsstartis the first grid point of the plateau at the peak level immediately before the fall, that is the date the peak was first reached, not the last date at the peak. Itstroughis the earliest deepest point of the run, and itsendis the first point back at or above the peak, or the final grid point for an episode still under water (is_recovered=False, and its durations are right-censored lower bounds). Episodes are sorted by maximum drawdown depth, then by start date to resolve equal depths.Durations are measured from
start, so on the calendar-day grid a Friday peak followed by a Monday fall starts on Friday, whilecompute_rolling_drawdown_time_under_watercounts time under water from Sunday, the last forward-filled day at the peak;days_ddexceeds the time under water by that plateau and, for a recovered episode, by the recovery day.- Parameters:
price (Series) – Price level Series.
max_num (int | None) – Maximum number of drawdown episodes to return (worst N).
freq (str | None) – Frequency to rebase to before block detection. Any non-None frequency gives durations in calendar days between grid dates (
freq='B'also gives calendar days); the default ‘D’ makes them wall-clock days on a daily grid. Pass None to count durations in observations of the original grid.
- Returns:
start, trough, end, max_dd, days_dd, days_to_trough, days_recovery, peak, bottom, recovery, is_recovered.
- Return type:
DataFrame sorted by max_dd ascending, with columns