SVPosterior#

class cultivars.univariate.stochastic_volatility.SVPosterior(*, endog, mean_spec, method, mu_draws, phi_draws, sigma2_draws, mean_draws, h_draws, nu_draws, rho_draws, loglik_draws, acceptance_rate, nobs, n_draws, n_burn, thin)[source]#

A posterior over the stochastic-volatility model, from either sampler.

Deliberately absent: llf, n_params, information criteria. A posterior has none of them; loglik_draws (particle chain only) is the sequence of likelihood estimates the chain accepted.

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

  • mean_spec (str) – "constant" or "zero".

  • method (str) – "gibbs" or "particle".

  • mu_draws (NDArray[double]) – (S,) draws of the log-variance mean.

  • phi_draws (NDArray[double]) – (S,) draws of the persistence.

  • sigma2_draws (NDArray[double]) – (S,) draws of the innovation variance.

  • mean_draws (NDArray[double]) – (S,) draws of the observation mean (constant under the particle chain, which concentrates it at the sample mean).

  • h_draws (NDArray[double]) – (S, n) log-variance path draws (Gibbs) or, for the particle chain, the particle-smoothed path at the posterior mean repeated once, (1, n).

  • nu_draws (NDArray[double] | None) – (S,) draws of the Student-t degrees of freedom, or None under Gaussian noise.

  • rho_draws (NDArray[double] | None) – (S,) draws of the leverage correlation, or None without leverage.

  • loglik_draws (NDArray[double] | None) – (S,) particle likelihood estimates, or None.

  • acceptance_rate (float | None) – The chain’s acceptance rate, or None.

  • nobs (int) – Observations.

  • n_draws (int) – Total sampler iterations.

  • n_burn (int) – Burn-in discarded.

  • thin (int) – Post-burn thinning.

The model is \(y_t = c + \exp(h_t / 2)\, \varepsilon_t\) with \(h_{t+1} = \mu + \phi (h_t - \mu) + \sigma \eta_t\). The two samplers fill the record differently, and these fields mean different things under each:

  • h_draws: under Gibbs, one sampled log-variance path per kept draw. Under the particle chain, a single path, the particle-smoothed state at the posterior-mean parameters, so everything derived from it (volatility_quantiles, the bands in to_pandas) carries no path uncertainty.

  • mean_draws: sampled under Gibbs when the mean is estimated. Constant under the particle chain, which holds the mean fixed at the sample mean or at zero.

  • acceptance_rate: under the particle chain, the chain’s acceptance rate. Under Gibbs, the acceptance rate of the Metropolis step for the degrees of freedom, and None when the noise is Gaussian.

  • loglik_draws and rho_draws: particle chain only.

Point summaries are means over the kept draws. params, state_space, and simulate without a draw plug those means into the model.

See also

  • _VolatilityDrawsFit and _ParticleChainFit – the raw sampler outputs this record is assembled from.

  • _UCSVPosterior – the random-walk-volatility counterpart.

Example

>>> import numpy as np
>>> from cultivars_engine._internals._simulators import _simulate_stochastic_volatility
>>> from cultivars.univariate.stochastic_volatility import SV
>>> rng = np.random.default_rng(0)
>>> y, _ = _simulate_stochastic_volatility(
...     150, mu=-1.0, phi=0.95, sigma2=0.05, mean=0.0, rng=rng
... )
>>> post = SV(y, mean="zero").sample(n_draws=120, n_burn=40, seed=0)
>>> isinstance(post, _SVPosterior), post.method, post.n_kept
(True, 'gibbs', 80)
>>> post.h_draws.shape, post.volatility.shape
((80, 150), (150,))
>>> post.posterior_replications(5, seed=0).shape
(5, 150)

Attributes#

endog

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

mean_spec

Observation-mean specification, "constant" or "zero".

method

Sampler that produced the draws, "gibbs" or "particle".

mu_draws

Kept draws of the log-variance mean mu, (S,).

phi_draws

Kept draws of the persistence phi, (S,), each in (-1, 1).

sigma2_draws

Kept draws of the log-variance innovation variance \(\sigma^2\), (S,).

mean_draws

Draws of the observation mean c, (S,).

h_draws

(S, n) under Gibbs, (1, n) under the particle chain.

nu_draws

Kept draws of the Student-t degrees of freedom, (S,); None for Gaussian noise.

rho_draws

Kept draws of the leverage correlation, (S,); None without leverage.

loglik_draws

Particle log-likelihood estimates, one per kept draw, (S,); None under Gibbs.

acceptance_rate

Acceptance rate of whichever Metropolis step the sampler has, or None.

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.

log_variance

Posterior-mean log-variance path, (n,).

n_kept

Posterior draws retained.

observed

The series the replications are shaped like, (n,).

params

The posterior-mean parameter record.

state_space

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

volatility

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

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.

posterior_replications([n_replications, seed])

Replicated series, one per posterior draw used.

simulate([n, seed, burn, draw])

A fresh sample path at the posterior mean or at one kept draw.

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.

volatility_quantiles([levels])

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