qis.compute_rolling_drawdown_time_under_water

qis.compute_rolling_drawdown_time_under_water(prices, sampling_freq='D')[source]

Compute joint drawdown and time-under-water series.

The levels are first rebased to sampling_freq with forward filling. Time under water then counts the consecutive grid points, up to and including each date, at which the level is below its running peak, resetting to zero at every new high. On ‘D’ it is the number of calendar days since the last day at the running peak: a Friday peak followed by a Monday fall counts from Sunday, the last forward-filled day at the peak.

Parameters:
  • prices (DataFrame | Series) – Price level Series or DataFrame.

  • sampling_freq (Literal['B', 'D']) – ‘D’ for calendar days, ‘B’ for business days. Calendar days are recommended for most reporting use cases as they reflect investor wall-clock recovery time.

Returns:

Tuple of (drawdown, time_under_water) of the input type (Series or DataFrame) and columns, both on the rebased sampling_freq grid, not the input index: a business-day input returns more rows on ‘D’. Leading missing levels count as zero time under water.

Raises:

ValueError – If prices is neither Series nor DataFrame.

Return type:

Tuple[DataFrame | Series, DataFrame | Series]