Rolling Origin

greybox.rolling.rolling_origin(data: ndarray, h: int = 10, origins: int = 10, step: int = 1, ci: bool = False, co: bool = True, call: Callable | None = None, silent: bool = True, model_fn: Callable | None = None, predict_fn: Callable | None = None) RollingOriginResult[source]

Rolling Origin Evaluation.

Produces rolling origin forecasts using a single callable that accepts training data and horizon h. This is the standard approach for evaluating forecast accuracy on time series.

Parameters:
  • data (np.ndarray) – Time series data (1-D).

  • h (int, default=10) – Forecast horizon (number of steps ahead).

  • origins (int, default=10) – Number of rolling origins.

  • step (int, default=1) – Number of observations to advance between origins.

  • ci (bool, default=False) – If False (default), expanding window — training set grows each origin. If True, sliding window — training set has constant size.

  • co (bool, default=True) – If True (default), constant holdout: all origins forecast exactly h steps. If False, decreasing holdout: later origins may forecast fewer than h steps (when fewer observations remain).

  • call (callable) –

    call(data, h, **optional) -> forecasts

    data is the training slice (np.ndarray), h is the horizon. The function may optionally accept keyword arguments counti, counto, and/or countf (index arrays into the original series) — they are injected automatically if present in the signature.

    Return value can be:

    • np.ndarray of length h → stored as result.mean

    • dict with string keys → one attribute per key

    • object with .mean / .lower / .upper attributes

    • 3-tuple (mean, lower, upper)

  • silent (bool, default=True) – If False, print progress information per origin.

  • model_fn (callable, deprecated) – Old API: function train_data -> fitted_model.

  • predict_fn (callable, deprecated) – Old API: function (model, h) -> forecasts.

Returns:

  • .actuals — original data

  • .holdout — actual values, shape (h, origins), NaN-padded

  • .mean — point forecasts, shape (h, origins)

  • .lower / .upper — interval bounds (if returned by call)

  • .origins — number of origins evaluated

  • .h — forecast horizon

  • ._fields — list of forecast field names

Return type:

RollingOriginResult

Examples

>>> import numpy as np
>>> from greybox import rolling_origin
>>> np.random.seed(42)
>>> y = np.cumsum(np.random.randn(100))
>>> result = rolling_origin(y, h=5, origins=10,
...     call=lambda data, h: np.full(h, data.mean()))
>>> print(result)
Rolling origin with constant holdout was done.
 Forecast horizon: 5
 Number of origins: 10
>>> result.mean.shape
(5, 10)

RollingOriginResult

class greybox.rolling.RollingOriginResult(actuals: ndarray, holdout: ndarray, origins: int, h: int, fields: dict)[source]

Bases: object

Result of rolling origin evaluation.

actuals

The original data.

Type:

np.ndarray

holdout

Matrix of actual holdout values, shape (h, origins). NaN where h_actual < h (co=False, near end of series).

Type:

np.ndarray

mean

Point forecasts, shape (h, origins).

Type:

np.ndarray

lower

Lower interval bounds, shape (h, origins). Present if call returned ‘lower’ key/attribute.

Type:

np.ndarray, optional

upper

Upper interval bounds, shape (h, origins). Present if call returned ‘upper’ key/attribute.

Type:

np.ndarray, optional

origins

Number of rolling origins evaluated.

Type:

int

h

Forecast horizon.

Type:

int

_fields

Names of all forecast fields stored (always includes ‘mean’).

Type:

list[str]