quantlab.runs.backtest_stats.in_ranges#

quantlab.runs.backtest_stats.in_ranges(timestamps, ranges)[source]#

Return a boolean mask of the timestamps inside any of ranges.

Both ends of a range are included and compared as exact timestamps (a date is midnight), never by day.

Parameters:
timestampsarray_like of datetime64

The bars to test.

rangessequence of (str, str)

Inclusive bar-label ranges.

Returns:
numpy.ndarray

A boolean mask, True where a bar falls inside any range.

Examples

>>> ts = pd.bdate_range("2024-01-01", periods=5).values
>>> in_ranges(ts, [("2024-01-02", "2024-01-03")]).tolist()
[False, True, True, False, False]