macrostat.models.NK3E.behavior#

Behavior classes for the New Keynesian 3-Equation (NK3E) model. Reference equations:

y_t = A - a1 * r_{t-1} pi_t = pi_{t-1} + a2 * (y_t - y_e) r_s = (A - y_e) / a1 r_t = r_s + a3 * (pi_t - pi_T)

Where a3 = 1 / [a1 * (1/(a2*b) + a2)].

Reference: Carlin & Soskice (2014); implementation aligned with Source: A New Keynesian 3-Equation Model — https://macrosimulation.org/a_new_keynesian_3_equation_model

Classes

BehaviorNK3E([parameters, scenarios, ...])

Simulation logic for the NK3E model.

class macrostat.models.NK3E.behavior.BehaviorNK3E(parameters: ParametersNK3E | None = None, scenarios: ScenariosNK3E | None = None, variables: VariablesNK3E | None = None, scenario: int = 0, debug: bool = False)[source]#

Bases: Behavior

Simulation logic for the NK3E model.

This class advances the model one period at a time using the three core equations: - IS (goods demand): y_t = A - a1 * r_{t-1} - Phillips (inflation): pi_t = pi_{t-1} + a2 * (y_t - y_e) - Monetary policy: r_t = r_s + a3 * (pi_t - pi_T), with r_s = (A - y_e)/a1

The central bank response slope a3 is computed from structural parameters each step: a3 = 1 / [a1 * (1/(a2*b) + a2)], so you only specify a1, a2, b.

Design notes: - We treat parameters as potentially time-varying via the scenarios system.

Any parameter shocks are applied upstream in apply_parameter_shocks, so the step reads already-shocked values from params.

  • We keep a minimal state: output (y), inflation (pi), real rate (r) and the stabilizing real rate (r_s). Both pi and r use one-period lags, so they are configured with history=1 in the variables.

central_bank_slope(t: int, scenario: dict, params: dict | None = None)[source]#

Compute the monetary policy reaction slope a3 from structural parameters.

Parameters:
  • t (int) – Current period (for bookkeeping only).

  • scenario (dict) – Scenario dictionary (not used).

  • params (dict | None) – Parameter values for time t with scenario shocks already applied.

Equations

\[a_3 = \frac{1}{a_1\left(\frac{1}{a_2 b} + a_2\right)}\]

Dependency

  • parameters: a1

  • parameters: a2

  • parameters: b

Sets

  • a3

forward()[source]#

Run the full simulation, optionally with a tqdm progress bar.

This mirrors the base class implementation but adds a progress bar when parameters.hyper['use_tqdm'] is True. At each step we: 1) build the scenario slice for time t, 2) apply parameter shocks (so params reflects current-time values), 3) call step() to update the state, 4) record the new state into the timeseries and history buffers.

initialize()[source]#

Set the model at its steady state before shocks start.

At steady state, by definition y = y_e, r = r_s and pi = pi_T. We use the current (pre-shock) parameter values to compute r_s and then set all state variables accordingly. The base class will record this initial state for the required number of initialization timesteps.

is_curve_output(t: int, scenario: dict, params: dict | None = None)[source]#

IS curve: output as a function of demand shifter and lagged real rate.

Parameters:
  • t (int) – Current period (for bookkeeping only).

  • scenario (dict) – Scenario dictionary (not used).

  • params (dict | None) – Parameter values for time t with scenario shocks already applied.

Equations

\[y_t = A - a_1 r_{t-1}\]

Dependency

  • parameters: A

  • parameters: a1

  • prior: r

Sets

  • y

monetary_policy_rate(t: int, scenario: dict, params: dict | None = None)[source]#

Monetary policy rule: real rate reacts to inflation deviations.

Parameters:
  • t (int) – Current period (for bookkeeping only).

  • scenario (dict) – Scenario dictionary (not used).

  • params (dict | None) – Parameter values for time t with scenario shocks already applied.

Equations

\[r_t = r_s + a_3 (\pi_t - \pi^T)\]

Dependency

  • state: r_s

  • state: a3

  • state: pi

  • parameters: pi_T

Sets

  • r

phillips_curve_inflation(t: int, scenario: dict, params: dict | None = None)[source]#

Phillips curve: inflation responds to the output gap.

Parameters:
  • t (int) – Current period (for bookkeeping only).

  • scenario (dict) – Scenario dictionary (not used).

  • params (dict | None) – Parameter values for time t with scenario shocks already applied.

Equations

\[\pi_t = \pi_{t-1} + a_2 (y_t - y_e)\]

Dependency

  • prior: pi

  • state: y

  • parameters: a2

  • parameters: y_e

Sets

  • pi

stabilizing_real_rate(t: int, scenario: dict, params: dict | None = None)[source]#

Compute the stabilizing real rate r_s consistent with output at potential.

Parameters:
  • t (int) – Current period (for bookkeeping only).

  • scenario (dict) – Scenario dictionary (not used).

  • params (dict | None) – Parameter values for time t with scenario shocks already applied.

Equations

\[r_s = \frac{A - y_e}{a_1}\]

Dependency

  • parameters: A

  • parameters: y_e

  • parameters: a1

Sets

  • r_s

step(t: int, scenario: dict, params: dict | None = None, **kwargs)[source]#

Advance the model by one period using the 3-equation system.

Parameters:
  • t (int) – Current period (for bookkeeping only; equations are time-homogeneous).

  • scenario (dict) – Vectorized scenario values at time t (not directly used here since parameter shocks are already reflected in params).

  • params (dict) – Parameter values for time t with scenario shocks already applied.

Notes

  • We re-compute a3 every period from (a1, a2, b) in case those are shocked over time.

  • IS uses the lagged real rate from self.prior['r'] to produce y_t.

  • The Phillips curve uses the output gap to update inflation.

  • The policy rule sets the real rate relative to the stabilizing rate.

training: bool#
version = 'NK3E'#