macrostat.models.NK3E#
New Keynesian 3-Equation (NK3E) Model - https://macrosimulation.org/a_new_keynesian_3_equation_model
The macrostat.models.NK3E module consists of the following classes
|
NK3E model class for the New Keynesian 3-Equation model. |
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). |
|
Parameters class for the New Keynesian 3-Equation (NK3E) model. |
|
Scenarios class for the New Keynesian 3-Equation (NK3E) model. |
|
Variables class for the New Keynesian 3-Equation (NK3E) model. |
- class macrostat.models.NK3E.BehaviorNK3E(parameters: ParametersNK3E | None = None, scenarios: ScenariosNK3E | None = None, variables: VariablesNK3E | None = None, scenario: int = 0, debug: bool = False)[source]#
Bases:
BehaviorSimulation 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 fromparams.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:
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 (soparamsreflects current-time values), 3) callstep()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:
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:
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:
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:
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:
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.
- version = 'NK3E'#
- class macrostat.models.NK3E.NK3E(parameters: ~macrostat.models.NK3E.parameters.ParametersNK3E | None = <macrostat.models.NK3E.parameters.ParametersNK3E object>, variables: ~macrostat.models.NK3E.variables.VariablesNK3E | None = None, scenarios: ~macrostat.models.NK3E.scenarios.ScenariosNK3E | None = None, *args, **kwargs)[source]#
Bases:
ModelNK3E model class for the New Keynesian 3-Equation model.
Description: A compact three-equation New Keynesian framework with an IS curve (goods demand), a New Keynesian Phillips curve (price-setting), and a monetary policy rule. Together these describe the joint dynamics of output, inflation, and the real interest rate.
Source: A New Keynesian 3-Equation Model — https://macrosimulation.org/a_new_keynesian_3_equation_model
- version = 'NK3E'#
- class macrostat.models.NK3E.ParametersNK3E(parameters: dict | None = None, hyperparameters: dict | None = None, bounds: dict | None = None, *args, **kwargs)[source]#
Bases:
ParametersParameters for the NK3E model.
Economic meaning: - a1 (>0): sensitivity of demand to the real rate (steeper => interest rate
moves output more).
a2 (>0): sensitivity of inflation to the output gap.
b (>0): central bank weight on inflation deviations in its loss.
A: autonomous demand (times multiplier).
pi_T: inflation target.
y_e: equilibrium (potential) output.
Hyperparameters control the simulation environment, not the economics, e.g., number of timesteps and progress bar usage.
- get_default_hyperparameters()[source]#
Return the default hyperparameters.
The hyperparameters are the parameters that are not directly used in the model, but rather for the simulation and calibration. They must include: 1. The number of timesteps to simulate 2. The scenario trigger, i.e. the timestep at which the scenario starts 3. The seed for the random number generator 4. The device to use for the simulation 5. May include other parameters, such as flags for the model
- get_default_parameters()[source]#
Return the default parameter values for NK3E.
Notes
a3 is not a primitive; it is derived each step as
1 / (a1 * (1/(a2*b) + a2)).The three scenarios modify A, pi_T, or y_e around these baselines.
- version = 'NK3E'#
- class macrostat.models.NK3E.ScenariosNK3E(scenario_info: dict | None = None, parameters: ParametersNK3E | None = None, *args, **kwargs)[source]#
Bases:
ScenariosScenarios class for the New Keynesian 3-Equation (NK3E) model.
- version = 'NK3E'#
- class macrostat.models.NK3E.VariablesNK3E(variable_info: dict | None = None, timeseries: dict | None = None, parameters: ParametersNK3E | None = None, *args, **kwargs)[source]#
Bases:
VariablesVariables class for the NK3E model.
- get_default_variables()[source]#
Return the default variables information dictionary.
This function returns a dictionary of the variable information with their default values. Users should implement this function in their model class, and it should return a dictionary with the variable names as keys and the variable information as values. The variable information should contain at least the following keys:
“history”: int - The number of periods that the variable requires information from.
“sectors”: list - The sectors that the variable is associated with.
“unit”: str - The unit of the variable.
“notation”: str - The notation of the variable.
- version = 'NK3E'#