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:
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, orNoneunder Gaussian noise.rho_draws (
NDArray[double] |None) –(S,)draws of the leverage correlation, orNonewithout leverage.loglik_draws (
NDArray[double] |None) –(S,)particle likelihood estimates, orNone.acceptance_rate (
float|None) – The chain’s acceptance rate, orNone.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 into_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, andNonewhen the noise is Gaussian.loglik_drawsandrho_draws: particle chain only.
Point summaries are means over the kept draws.
params,state_space, andsimulatewithout adrawplug those means into the model.See also
_VolatilityDrawsFitand_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#
The observed series, |
|
Observation-mean specification, |
|
Sampler that produced the draws, |
|
Kept draws of the log-variance mean |
|
Kept draws of the persistence |
|
Kept draws of the log-variance innovation variance \(\sigma^2\), |
|
Draws of the observation mean |
|
|
|
Kept draws of the Student-t degrees of freedom, |
|
Kept draws of the leverage correlation, |
|
Particle log-likelihood estimates, one per kept draw, |
|
Acceptance rate of whichever Metropolis step the sampler has, or |
|
Number of observations \(n\). |
|
Total sampler iterations, burn-in included. |
|
Iterations discarded as burn-in. |
|
Thinning interval applied after burn-in. |
|
Posterior-mean log-variance path, |
|
Posterior draws retained. |
|
The series the replications are shaped like, |
|
The posterior-mean parameter record. |
|
The model at the posterior mean, on the nonlinear substrate. |
|
Posterior-mean volatility \(\mathbb{E}[\exp(h_t / 2) \mid y]\), |
|
Fitted values of the host record. |
|
Residuals of the host record. |
Methods#
|
Assess the sampler's convergence over the retained draws. |
|
Replicated series, one per posterior draw used. |
|
A fresh sample path at the posterior mean or at one kept draw. |
|
The estimation summary, renderable as text, HTML, or a dataframe. |
|
The aligned per-observation outputs as plain numpy arrays. |
|
The aligned per-observation outputs as a |
The aligned per-observation outputs as a |
|
|
Pointwise posterior quantiles of the volatility, |