Skip to content

DSGESolver

class DSGESolver(model_config: ModelConfig, kalman_config: KalmanConfig)

Class responsible for model compilation and solution.

Attributes:

Name Type Description
model_config ModelConfig Configuration object to be compiled/solved.
kalman_config KalmanConfig Kalman Filter configuration object.
t sp.Symbol Time symbol used in model components.

Methods:

DSGESolver.compile(
    *,
    variable_order: list[sp.Function | str] | None = None,
    n_state: int | None = None,
    n_exog: int | None = None,
    params_order: list[str] | None = None,
    linearize: bool = False,
) -> CompiledModel
Inferred Variable Layout

DSGESolver.compile(...) infers the solver layout from the model config. Shock-map targets define the shocked/exogenous state block, dynamic equations define the remaining state variables, and the rest are treated as controls.

If variable_order, n_state, or n_exog are supplied, they are treated as explicit expectations. The compiler sanity-checks them against the config-derived layout and raises if they disagree.

Produces a CompiledModel object using the inferred canonical variable layout unless an explicit, validated order is supplied.

Inputs:

Name Description
variable_order Optional expected variable order. If supplied, it must agree with the config-derived state/exogenous grouping.
n_state Optional expected number of state variables. Raises if it disagrees with inference.
n_exog Optional expected number of shocked/exogenous state variables. Raises if it disagrees with inference.
params_order Custom ordering of model parameters if desired.
linearize Apply symbolic linearization to a copied model config before compilation.

 

Returns:

Type Description
CompiledModel Numerically compiled model components returned as an object.
DSGESolver.solve(
    compiled: CompiledModel,
    parameters: dict[str, float] = None,
    steady_state: ndarray[float] | dict[str, float] = None
) -> SolvedModel

Solves the given compiled model and returns a SolvedModel object.

Inputs:

Name Description
compiled The CompiledModel to solve.
parameters parameter values as dict to override the calibration config.
steady_state model variables' steady state. Defaults to zeroes. (often used in gap models)

 

Returns:

Type Description
SolvedModel Solved model object with relevant methods attached.

 

Linearized Inputs

DSGESolver.solve(...) expects a compiled linearized model. If your original model is nonlinear, pass linearize=True to DSGESolver.compile(...) or apply SymbolicDSGE.core.linearize_model(...) before compilation.

DSGESolver.estimate(
    *,
    compiled: CompiledModel,
    y: np.ndarray | pd.DataFrame,
    method: str = "mle",
    theta0: np.ndarray | Mapping[str, float] | None = None, # (1)!
    observables: list[str] | None = None,
    estimated_params: list[str] | None = None,
    priors: Mapping[str, Any] | None = None,
    steady_state: np.ndarray | dict[str, float] | None = None,
    x0: np.ndarray | None = None,
    p0_mode: str | None = None,
    p0_scale: float | None = None,
    jitter: float | None = None,
    symmetrize: bool | None = None,
    R: np.ndarray | None = None, # (2)!
    **method_kwargs: Any,
) -> MCMCResult | OptimizationResult
  1. If theta0 is passed as a dictionary, it is reordered internally to the estimator's canonical parameter order.
  2. If R is not supplied, the estimator attempts to infer R from data before optimization/sampling (MAP on full R, with MLE fallback on failure).
Note

Filter mode is inferred internally (linear if all selected measurement equations are affine, otherwise extended).

Method kwargs:

  • method="mle": forwarded to Estimator.mle(...)
  • method="map": forwarded to Estimator.map(...)
  • method="mcmc": forwarded to Estimator.mcmc(...)

 

DSGESolver.estimate_and_solve(
    *,
    compiled: CompiledModel,
    y: np.ndarray | pd.DataFrame,
    method: str = "mle",
    theta0: np.ndarray | Mapping[str, float] | None = None,
    posterior_point: str = "mean",
    observables: list[str] | None = None,
    estimated_params: list[str] | None = None,
    priors: Mapping[str, Any] | None = None,
    steady_state: np.ndarray | dict[str, float] | None = None,
    x0: np.ndarray | None = None,
    p0_mode: str | None = None,
    p0_scale: float | None = None,
    jitter: float | None = None,
    symmetrize: bool | None = None,
    R: np.ndarray | None = None,
    **method_kwargs: Any,
) -> tuple[MCMCResult | OptimizerResult, SolvedModel]

Runs estimation and then solves the model at the estimated parameter point.

For method="mcmc", posterior_point selects the parameter point used for solving:

  • "mean": posterior sample mean
  • "last": last retained sample
  • "map": sample with the highest posterior likelihood
  • "mode": equivalent to "map" by definition