quantlab.model.split.in_sample_window#

quantlab.model.split.in_sample_window(calendar, train_start, train_end, lookahead)[source]#

Return the first and last bar a fitted model has seen.

The model fitted labels on the bars of [train_start, train_end], and the label of the last one reads lookahead bars further, so those bars are in-sample too.

Parameters:
calendarnp.ndarray

The sorted bar axis the backtest trades on.

train_start, train_end

The fitted training window, both ends inclusive, resolved as purge_segments resolves segment bounds. train_end is the last bar fitted, after any purge.

lookaheadint

L, the largest lookahead_bars() among the model’s labels.

Returns:
tuple of np.datetime64 or None

The first training bar and the bar lookahead bars after the last one, clamped to the calendar’s last bar; None when the window holds no bar of the calendar.

Examples

>>> days = pd.bdate_range("2024-01-01", periods=10).values
>>> in_sample_window(days, "2024-01-01", "2024-01-05", 2)
(np.datetime64('2024-01-01T00:00:00.000000000'), np.datetime64('2024-01-09T00:00:00.000000000'))