quantlab.runs.backtest_stats.drawdown_span#
- quantlab.runs.backtest_stats.drawdown_span(value)[source]#
Return the deepest drawdown of a value curve, from its valley to its recovery.
The drawdowns are vectorbt’s records of the curve (a drawdown starts after a peak and ends on the bar that regains it, or, still running, on the last bar; NaN bars are skipped) and the one returned is the deepest by
valley / peak - 1, never the longest. This is the span the report marks on the equity curve and names in its “Setup” table.- Parameters:
- valuexarray.DataArray
Portfolio value on a
timestampaxis.
- Returns:
- dict or None
valleyandend(bar_labelstrings of the deepest bar and of the bar it recovered on, or the last bar),bars(bars from the valley to the end, not calendar days),depth(a negative fraction) andrecovered;Nonewhen the curve has no drawdown with a finite depth.
Examples
>>> bars = pd.bdate_range("2024-01-01", periods=6) >>> value = xr.DataArray([100.0, 90.0, 80.0, 95.0, 101.0, 99.0], ... dims="timestamp", coords={"timestamp": bars}) >>> drawdown_span(value) {'valley': '2024-01-03', 'end': '2024-01-05', 'bars': 2, 'depth': -0.19999999999999996, 'recovered': True}