Backtest._forecast#
- Backtest._forecast(result, seed)[source]#
One origin’s forecast as
(n_draws, H, k)draws or(H, k)points.Applies the forecasting convention and normalizes what comes back. The
predicthook is called when given; otherwise a result satisfyingPredictiveResultis asked forforecast_paths(H, seed=seed)and any other forforecast(H). The raw array is then read by shape, in this order: a(H, k, 3)low/mean/high summary, theforecast()of the sampled families, keeps its middle column; an(H,)vector for a single series becomes(H, 1); an(H, k)array is a point forecast; an(S, H)array for a single series becomes(S, H, 1); and an(S, H, k)array is a set of draws.- Parameters:
- Return type:
- Returns:
The normalized forecast; three-dimensional for draws, two-dimensional for points.
- Raises:
SpecificationError – If no hook was given and the result offers neither
forecast_pathsnor a callableforecast.DimensionError – If the forecast has none of the recognized shapes.
Example
>>> import numpy as np >>> from cultivars.multivariate.reduced_form.vector_autoregression import VAR >>> from cultivars.multivariate.large_dim.bayesian import BVAR >>> y = np.random.default_rng(0).standard_normal((130, 2)) >>> harness = Backtest(y, lambda w: w, horizons=2, start=100) >>> harness._forecast(VAR(y, order=1).fit(), None).shape (2, 2) >>> harness._forecast(BVAR(y, order=1).fit(n_draws=20, seed=0), 0).shape (20, 2, 2) >>> harness._forecast(object(), None) Traceback (most recent call last): ... cultivars.exceptions.SpecificationError: object offers neither forecast_paths() ...