FoundationModelBacktestForecaster#

class openstef_foundation_models.integrations.beam.FoundationModelBacktestForecaster(**data: Any) None[source]

Bases: BaseModel, BacktestBatchForecasterMixin, BacktestForecasterMixin

Backtest wrapper around a single, shared forecasting workflow.

The wrapped workflow is built once and reused for every prediction window (load-once). Each window is forecast through predict() with the window horizon as the forecast start, so the adapter never reaches into the workflow’s model.

Setting batch_size greater than 1 makes beam’s pipeline route consecutive prediction windows through predict_batch(), which issues a single batched workflow.predict_batch call (one backend call inside the forecaster) instead of one call per window.

Prefer from_workflow(), which sizes the window to the workflow’s own horizon:

adapter = FoundationModelBacktestForecaster.from_workflow(workflow)

The raw constructor takes a workflow and a window config; the config defaults to a generic zero-shot, load-once setup (DEFAULT_BACKTEST_CONFIG).

Parameters:

data (Any)

workflow: CustomForecastingWorkflow
config: BacktestForecasterConfig
batch_size: int | None
classmethod from_workflow(workflow: CustomForecastingWorkflow, *, predict_length: timedelta | None = None, predict_context_length: timedelta = DEFAULT_BACKTEST_CONFIG.predict_context_length, batch_size: int | None = None) Self[source]

Build a load-once adapter with a zero-shot window config sized to workflow.

Parameters:
  • workflow (CustomForecastingWorkflow) – The pre-built workflow to reuse across every backtest window.

  • predict_length (timedelta | None) – Forecast horizon per window. Defaults to the workflow’s maximum configured horizon.

  • predict_context_length (timedelta) – History fed to the model as context.

  • batch_size (int | None) – Max prediction windows stacked into one backend call. None or 1 forecasts one window at a time.

  • workflow

  • predict_length

  • predict_context_length

  • batch_size

Returns:

A configured adapter wrapping workflow.

Return type:

Self

property quantiles: list[Quantile]

Return the list of quantiles that this forecaster predicts.

fit(data: RestrictedHorizonVersionedTimeSeries) None[source]

No-op: foundation models are zero-shot and need no per-window training.

Parameters:

data (RestrictedHorizonVersionedTimeSeries)

Return type:

None

predict(data: RestrictedHorizonVersionedTimeSeries) TimeSeriesDataset | None[source]

Forecast a single backtest window through the workflow.

Returns:

The workflow forecast for the window, or None when there is no observed target history before the horizon (no reliable forecast can be produced).

Parameters:

data (RestrictedHorizonVersionedTimeSeries)

Return type:

TimeSeriesDataset | None

predict_batch(batch: list[RestrictedHorizonVersionedTimeSeries]) Sequence[TimeSeriesDataset | None][source]

Forecast a batch of backtest windows in a single backend call.

Each event becomes one window with its own forecast start; events with no usable target history are dropped and mapped back to None at their original index. The remaining windows are forecast with a single workflow.predict_batch call, then scattered back into input order.

Parameters:
  • batch (list[RestrictedHorizonVersionedTimeSeries]) – Backtest events to forecast.

  • batch

Returns:

One forecast (or None) per input event, in input order.

Return type:

Sequence[TimeSeriesDataset | None]

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'protected_namespaces': (), 'ser_json_inf_nan': 'null'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].