Code: Solving New Keynesian Models Under Structural Change
March 2026
Here you will find MATLAB code for solving and simulating the canonical three-equation New Keynesian (NK) model when the economy undergoes a permanent structural change — specifically, a shift in the central bank's inflation target.
The code addresses a question central to disinflation episodes: does it matter whether the policy change is anticipated (pre-announced) or unanticipated (a surprise)? The toolkit compares both cases for a calibrated disinflation from 15% to 5% annual inflation, tracing the full transition paths for inflation, the nominal interest rate, and the output gap.
Methods
Rational expectations solution via Smats.m (based on Sims/gensys method ordered QZ/Schur decomposition), with Blanchard-Kahn existence and uniqueness checks.
Binder-Pesaran backward recursion for the anticipated-change case on the Kulish-Pagan structural matrices, yielding the time-varying reduced-form equilibrium over the transition window between announcement and implementation. Both stochastic (with monetary policy, demand, and cost-push shocks) and non-stochastic (deterministic) simulations are produced.
Matlab Code
The code is organized as a set of modular MATLAB functions:
var_dim_NK.m — state vector layout and index definitions
param_func_NK.m — model parameters and calibration
structural_matrices_NK.m — structural equation matrices in both Sims and Binder-Pesaran form
Smats.m — rational expectations solver
simul_NK.m — main simulation script
Download MATLAB code: link to zip