PerturbationDSGEResult#

class cultivars.multivariate.structural.perturbation.PerturbationDSGEResult(*, data, parameter_names, theta, solution, llf, filter, order, nobs, n_params, filtered_state, _engine)[source]#

A point-estimated perturbation model.

The structural parameters \(\theta\) that maximize one filter’s likelihood of the observables under the perturbation solution

\[x_{t+1} = h(x_t; \theta) + \eta(\theta)\, \varepsilon_{t+1}, \qquad y_t = g(x_t; \theta), \qquad z_t = Z\,(x_t, y_t) + d + e_t,\]

with \(h\) and \(g\) the first- or pruned second-order policy functions and \(z_t\) the observables. The record carries the estimate, the solution at it, the criterion value, the filter that produced it and the filtered state path; the engine is kept so the solution can be re-emitted on its substrate and fresh samples drawn.

Note

llf is whichever criterion was maximized and only that: exact under "kalman", the extended or unscented filter’s Gaussian approximation on the pruned second-order system, or a particle estimate under common random numbers. Values across filters are not comparable, and a particle value with few particles is biased downward – severely so when the measurement noise is small relative to the state innovations, because the bootstrap filter degenerates. No standard errors are carried: the inferential surface of this family is PerturbationDSGE.sample().

Variables:
  • data – The observables.

  • parameter_names – Structural parameter labels.

  • theta – The estimate, in the model’s own space.

  • solution – The perturbation solution at theta.

  • llf – The criterion at the optimum: exact under "kalman", a Gaussian approximation under "extended" / "unscented", a particle estimate under "particle".

  • filter – Which filter produced llf.

  • order – Perturbation order.

  • nobs – Observations.

  • n_params – Structural parameters.

  • filtered_state – Filtered state means.

See also

References

Fernández-Villaverde, J., & Rubio-Ramírez, J. F. (2007). Estimating macroeconomic models: A likelihood approach. Review of Economic Studies, 74(4), 1059-1087.

Schmitt-Grohé, S., & Uribe, M. (2004). Solving dynamic general equilibrium models using a second-order approximation to the policy function. Journal of Economic Dynamics and Control, 28(4), 755-775.

Example

The smallest admissible specification: one state following an AR(1), one control equal to it, observed with negligible noise. The exact first-order fit recovers the persistence and the innovation scale, and the solution at the estimate is the AR(1) itself:

>>> import numpy as np
>>> class Latent:
...     parameter_names, bounds = ("rho", "sigma"), ((0.0, 0.99), (0.01, 1.0))
...     n_states, n_controls = 1, 1
...     def equations(self, th, y_next, y, x_next, x):
...         return np.array([y[0] - x[0], x_next[0] - th[0] * x[0]])
...     def steady_state(self, th):
...         return np.zeros(1), np.zeros(1)
...     def shock_loading(self, th):
...         return np.array([[th[1]]])
...     def observation(self, th):
...         return np.array([[0.0, 1.0]]), np.zeros(1), np.array([[1e-4]])
...     def log_prior(self, th):
...         return 0.0
>>> rng = np.random.default_rng(0)
>>> x = np.zeros(200)
>>> for t in range(1, 200):
...     x[t] = 0.8 * x[t - 1] + 0.5 * rng.standard_normal()
>>> res = PerturbationDSGE(Latent(), x, order=1).fit([0.5, 0.3], filter="kalman")
>>> res.filter, res.order, res.nobs, res.n_params, res.parameter_names
('kalman', 1, 200, 2, ('rho', 'sigma'))
>>> {name: round(value, 2) for name, value in res.params.items()}
{'rho': 0.82, 'sigma': 0.48}
>>> res.solution.h_x.round(2).tolist(), res.solution.is_stable, res.filtered_state.shape
([[0.82]], True, (200, 1))

Attributes#

data

The (nobs, p) observables as supplied, nan rows missing.

parameter_names

Structural parameter labels, in the specification's order.

theta

The (n_params,) estimate, in the model's own (constrained) space.

solution

The perturbation solution at theta.

llf

The maximized criterion; exact only under "kalman".

filter

"kalman", "extended", "unscented" or "particle".

order

Perturbation order, 1 or 2.

nobs

Observations, including rows that are nan.

n_params

Structural parameters.

filtered_state

The (nobs, n_x) filtered state means.

params

The estimate by name.

state_space

The solution at the estimate on its substrate.

Methods#

impulse_responses(*[, horizon, size])

Responses to each structural shock.

simulate([n, seed, burn])

A fresh sample of the observables at the estimate.

summary()

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