quantlab.model.split.split_ranges#
- quantlab.model.split.split_ranges(timestamps, windows)[source]#
Cut a backtest’s bars into in-sample and out-of-sample runs.
- Parameters:
- timestampsnp.ndarray
The sorted bars of the backtest.
- windowssequence of (first, last) or None
In-sample windows such as
in_sample_windowreturns, both ends inclusive and compared as exact timestamps;Noneentries are skipped.
- Returns:
- in_samplelist of (first, last)
The contiguous runs of bars inside any window, in time order.
- out_of_samplelist of (first, last)
The contiguous runs of the remaining bars, in time order.
Examples
>>> days = pd.bdate_range("2024-01-01", periods=5).values >>> inside, outside = split_ranges(days, [(days[1], days[2])]) >>> [(str(a)[:10], str(b)[:10]) for a, b in inside + outside] [('2024-01-02', '2024-01-03'), ('2024-01-01', '2024-01-01'), ('2024-01-04', '2024-01-05')]