UCSVPosterior#

class cultivars.univariate.stochastic_volatility.UCSVPosterior(*, endog, gamma_fixed, trend_draws, h_draws, q_draws, gamma2_irregular_draws, gamma2_trend_draws, nobs, n_draws, n_burn, thin)[source]#

A posterior over the unobserved-components stochastic-volatility model.

Variables:
  • endog (NDArray[double]) – The observed series.

  • gamma_fixed (bool) – Whether the vol-of-vol was held fixed.

  • trend_draws (NDArray[double]) – (S, n) trend paths.

  • h_draws (NDArray[double]) – (S, n) log variances of the irregular.

  • q_draws (NDArray[double]) – (S, n) log variances of the trend innovation.

  • gamma2_irregular_draws – (S,) vol-of-vol variance draws of \(h\).

  • gamma2_trend_draws (NDArray[double]) – (S,) vol-of-vol variance draws of q.

  • nobs (int) – Observations.

  • n_draws (int) – Total sampler iterations.

  • n_burn (int) – Burn-in discarded.

  • thin (int) – Post-burn thinning.

Stock and Watson’s (2007) model, in the timing the sampler uses:

y_t = tau_t + exp(h_t / 2) eps_t
tau_{t+1} = tau_t + exp(q_t / 2) eta_t
h_{t+1} = h_t + gamma_h nu_t
q_{t+1} = q_t + gamma_q xi_t

Every path is sampled, so unlike _SVPosterior under the particle chain the bands here carry path uncertainty. When the vol-of-vol was held fixed, the two gamma2 arrays are constant.

See also

  • UCSVPosterior – the public name of this class.

  • UCSV.fit() – returns an instance.

  • UCSVPosterior._from_fit() – returns an instance.

Example

>>> import numpy as np
>>> from cultivars.univariate.stochastic_volatility import UCSV
>>> rng = np.random.default_rng(0)
>>> y = np.cumsum(0.2 * rng.standard_normal(120)) + 0.7 * rng.standard_normal(120)
>>> post = UCSV(y).fit(n_draws=120, n_burn=60, seed=0)
>>> isinstance(post, _UCSVPosterior), post.gamma_fixed, post.n_kept
(True, True, 60)
>>> post.trend.shape, post.trend_quantiles().shape
((120,), (3, 120))
>>> post.forecast(4, n_paths=50, seed=0).shape
(50, 4)

Attributes#

endog

The observed series, (n,); kept out of the repr.

gamma_fixed

Whether the vol-of-vol was held fixed and not sampled.

trend_draws

Kept trend paths \(\tau_t\), (S, n).

h_draws

Kept log-variance paths of the irregular, (S, n).

q_draws

Kept log-variance paths of the trend innovation, (S, n).

gamma2_irregular_draws

Kept draws of the step variance of \(h\), (S,); a variance, not a standard deviation.

gamma2_trend_draws

Kept draws of the step variance of q, (S,); a variance, not a standard deviation.

nobs

Number of observations \(n\).

n_draws

Total sampler iterations, burn-in included.

n_burn

Iterations discarded as burn-in.

thin

Thinning interval applied after burn-in.

gap

The observed series minus the posterior-mean trend.

irregular_volatility

Posterior-mean volatility of the irregular \(\mathbb{E}[\exp(h_t / 2) \mid y]\).

n_kept

Posterior draws retained.

params

The posterior-mean parameter record.

state_space

The model at the posterior mean, on the nonlinear substrate.

trend

Posterior-mean trend, (n,).

trend_volatility

Posterior-mean trend-innovation volatility, \(\mathbb{E}[\exp(q_t / 2) \mid y]\).

fittedvalues

Fitted values of the host record.

resid

Residuals of the host record.

Methods#

convergence(*chains[, include, exclude, ...])

Assess the sampler's convergence over the retained draws.

forecast(steps, *[, n_paths, seed])

Predictive draws of the series, (n_paths, steps).

summary()

The estimation summary, renderable as text, HTML, or a dataframe.

to_dict()

The aligned per-observation outputs as plain numpy arrays.

to_pandas(*[, index])

The aligned per-observation outputs as a pandas.DataFrame.

to_polars()

The aligned per-observation outputs as a polars.DataFrame.

trend_quantiles([levels])

Pointwise posterior quantiles of the trend, (len(levels), n).