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] | None = None,
    n_state: int = None,
    n_exog: int = None,
    params_order: list[str] | None = None
) -> CompiledModel
Variable Ordering Convention

The model expects the first n_exog variables to be the exogenous components. Before solving the model either;

  • Ensure the variable ordering in the config file follows this convention.
  • Supply an order specification at compile time.
Planned Changes

Current input constraints will be eliminated as SymbolicDSGE moves towards the beta releases. n_exog and n_state will be inferred through flags in the config; and variable ordering will be managed internally.

Produces a CompiledModel object respecting the given orders. n_exog and n_state must be supplied for the current linearsolve backend.

Inputs:

Name Description
variable_order Custom ordering of variables if desired.
n_state Number of state variables.
n_exog Number of exogenous variables.
params_order Custom ordering of model parameters if desired.

 

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,
    log_linear: bool = False
) -> 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)
log_linear Indicates the model is in log-linear specification to the solver.

 

Returns:

Type Description
SolvedModel Solved model object with relevant methods attached.

 

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,
    log_linear: bool = False,
    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,
    log_linear: bool = False,
    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