FoundationModelBacktestForecaster#
- class openstef_foundation_models.integrations.beam.FoundationModelBacktestForecaster(**data: Any) None[source]
Bases:
BaseModel,BacktestBatchForecasterMixin,BacktestForecasterMixinBacktest wrapper around a single, shared forecasting workflow.
The wrapped
workflowis built once and reused for every prediction window (load-once). Each window is forecast throughpredict()with the window horizon as the forecast start, so the adapter never reaches into the workflow’s model.Setting
batch_sizegreater than 1 makes beam’s pipeline route consecutive prediction windows throughpredict_batch(), which issues a single batchedworkflow.predict_batchcall (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
- 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.Noneor1forecasts one window at a time.workflow
predict_length
predict_context_length
batch_size
- Returns:
A configured adapter wrapping workflow.
- Return type:
Self
- fit(data: RestrictedHorizonVersionedTimeSeries) None[source]
No-op: foundation models are zero-shot and need no per-window training.
- Parameters:
data (
RestrictedHorizonVersionedTimeSeries)- Return type:
- predict(data: RestrictedHorizonVersionedTimeSeries) TimeSeriesDataset | None[source]
Forecast a single backtest window through the workflow.
- Returns:
The workflow forecast for the window, or
Nonewhen there is no observed target history before the horizon (no reliable forecast can be produced).- Parameters:
data (
RestrictedHorizonVersionedTimeSeries)- Return type:
- 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
Noneat their original index. The remaining windows are forecast with a singleworkflow.predict_batchcall, 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:
- 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].