BacktestResult._density_losses#

BacktestResult._density_losses(kind)[source]#

(T, H, k) CRPS or log scores, one origin at a time.

Each cell scores the \(S\) draws at that origin, horizon, and series against the outcome: the CRPS as the sample estimate

\[\mathrm{CRPS} = \frac{1}{S} \sum_{s} |x_s - y| - \frac{1}{2 S^2} \sum_{s, s'} |x_s - x_{s'}|,\]

and the log score as the negative log of a kernel density of the draws at the outcome. Both are computed for every horizon at once because the loop over origins dominates and the per-horizon slices are cheap.

Parameters:

kind (str) – "crps" or "log".

Return type:

NDArray[double]

Returns:

The (T, H, k) array, negatively oriented.

Raises:

SpecificationError – If the backtest recorded no draws.

Example

>>> import numpy as np
>>> from cultivars.multivariate.large_dim.bayesian import BVAR
>>> y = np.random.default_rng(0).standard_normal((140, 2))
>>> fit = lambda w: BVAR(w, order=1).fit(n_draws=50, seed=0)
>>> record = Backtest(y, fit, horizons=2, start=130, step=5).run()
>>> record._density_losses("crps").shape
(2, 2, 2)