gEconpy.model.perturbation.linearize_model#

gEconpy.model.perturbation.linearize_model(variables, equations, shocks, cache=None, loglin_variables=None, order=1, eq_order=None, var_order=None)#

Compute the log-linearized Jacobian matrices of a DSGE model using pytensor autodiff.

Builds four Jacobian matrices A, B, C, D representing the first-order approximation of the model around its steady state:

\[A \hat{y}_{t-1} + B \hat{y}_t + C \hat{y}_{t+1} + D \varepsilon_t = 0\]

Log-linearization applies the chain rule directly: \(\partial F / \partial (\log y) = (\partial F / \partial y) \cdot y_{ss}\). Each Jacobian is built by symbolic differentiation of the model equations, evaluated at the steady state, with the column for every log-linearized variable scaled by its steady-state value. Variables not in the loglin set keep their bare derivatives (scale factor one).

For a log-linearized variable whose steady-state sign is not statically known from the GCN Assumptions block, the column scale is guarded as \(\mathrm{switch}(y_{ss} > 0,\; y_{ss},\; 1)\), so a non-positive steady state falls back to a level (un-logged) derivative rather than implying \(\log\) of a non-positive value.

Parameters:
variableslist of TimeAwareSymbol

Model variables, expressed at time t.

equationslist of sp.Expr

Model equations as sympy expressions.

shockslist of TimeAwareSymbol

Exogenous shocks.

cachedict, optional

Sympytensor cache mapping (name, assumptions) tuples to pytensor nodes. If provided, sympy-to-pytensor conversion reuses existing nodes. If None, a new cache is created.

loglin_variableslist of TimeAwareSymbol, optional

Variables to log-linearize. If None, all variables are log-linearized.

orderint, default 1

Order of approximation. Only order=1 is currently supported.

eq_orderndarray of int, optional

Permutation of equation indices placing equations in [static | lag-only | lead-only | both] order so A’s and C’s structural-zero row blocks become contiguous. Computed from the equations if not supplied.

var_orderndarray of int, optional

Permutation of variable indices placing variables in [static | predetermined-only | mixed | forward-only] order so A’s and C’s structural-zero column blocks become contiguous. Computed from the equations if not supplied.

Returns:
jacobianslist of TensorVariable

Four pytensor matrix graph nodes [A, B, C, D]. Rows are in eq_order and the variable axis (cols of A/B/C) is in var_order; D’s columns are shocks (no permutation).

ss_input_nodeslist of TensorVariable

Steady-state variable input nodes needed to evaluate the Jacobians. Parameter nodes are also embedded in the graph but must be discovered by the caller via explicit_graph_inputs.

eq_order_outndarray of int

The equation permutation actually applied (same as eq_order if supplied).

var_order_outndarray of int

The variable permutation actually applied (same as var_order if supplied).