MacroModelling.jl
Author: Thore Kockerols (@thorek1)
MacroModelling.jl is a Julia package for developing and solving dynamic stochastic general equilibrium (DSGE) models.
These kinds of models describe the behaviour of a macroeconomy and are particularly suited for counterfactual analysis (economic policy evaluation) and exploring / quantifying specific mechanisms (academic research). Due to the complexity of these models, efficient numerical tools are required, as analytical solutions are often unavailable. MacroModelling.jl serves as a tool for handling the complexities involved, such as forward-looking expectations, nonlinearity, and high dimensionality.
The goal of this package is to reduce coding time and speed up model development by providing functions for working with discrete-time DSGE models. The user-friendly syntax, automatic variable declaration, and effective steady state solver facilitate fast prototyping of models. Furthermore, the package allows the user to work with nonlinear model solutions (up to third order (pruned) perturbation) and estimate the model using gradient based samplers (e.g. NUTS, or HMC). Currently, DifferentiableStateSpaceModels.jl is the only other package providing functionality to estimate using gradient based samplers but they use the start-of-period timing convention instead of the end-of-period timing convention used in most other packages. The target audience for the package includes central bankers, regulators, graduate students, and others working in academia with an interest in DSGE modelling.
As of now the package can:
- parse a model written with user friendly syntax (variables are followed by time indices
...[2], [1], [0], [-1], [-2]..., or[x]for shocks) - (tries to) solve the model only knowing the model equations and parameter values (no steady state file needed; possibility to define custom steady state function)
- calculate first, second, and third order (pruned) perturbation solutions (see Villemot (2011), Andreasen et al. (2017) and Levintal (2017)) using symbolic derivatives
- handle occasionally binding constraints for linear and nonlinear solutions
- calculate (generalised) impulse response functions, simulate the model, or do conditional forecasts for linear and nonlinear solutions
- calibrate parameters using (non-stochastic) steady state relationships
- calculate variance decompositions: unconditional decompositions at first order and at pruned second- and third-order, and conditional / forecast-error decompositions at first order. For pruned higher-order unconditional decompositions, the cross-shock interaction term can either be reported as a separate component or allocated across the individual shocks as marginal contributions (Shapley values)
- compute shock decompositions of filtered data via the Kalman or inversion filter, including pruned second- and third-order solutions where the nonlinear interaction term can optionally be allocated across shocks via marginal contributions (Shapley values)
- match model moments (also for pruned higher order solutions)
- estimate the model on data (Kalman filter using first order perturbation; see Durbin and Koopman (2012)) with gradient based samplers (e.g. NUTS, HMC), estimate nonlinear models using the inversion filter, or the filter-free joint likelihood
- differentiate the model solution, loglikelihood (Kalman filter, inversion filter, or filter free joint loglikelihood), model moments, and steady state with respect to the parameters using forward-mode AD (ForwardDiff.jl) and reverse-mode AD (Mooncake.jl recommended; other ChainRules-compatible backends such as Zygote.jl also work via custom rrules)
- modify a model after it has been defined — model and calibration equations can be updated, added, or removed in place (
update_equations!,add_equation!,remove_equation!, and the*_calibration_equation!variants) without re-running the@model/@parametersmacros. A chronological revision history is kept (get_revision_history) and the revised model can be saved to a Julia source file (write_julia_model_file); this mirrors the equation-revision workflow fromTROLL. See the how-to guide on modifying models.
The package is not:
- guaranteed to find the non-stochastic steady state (solving systems of nonlinear equations is an active area of research)
- the fastest package around if there is already a fast way to find the NSSS (time to first plot is long, time to second plot (with new parameters) is very short)
The former has to do with the fact that solving systems of nonlinear equations is hard (an active area of research). Especially in cases where the values of the solution are far apart (have a high standard deviation - e.g. sol = [-46.324, .993457, 23523.3856]), the algorithms have a hard time finding a solution. The recommended way to tackle this is to set bounds in the @parameters part (e.g. r < 0.2), so that the initial points are closer to the final solution (think of steady state interest rates not being higher than 20% - meaning not being higher than 0.2 or 1.2 depending on the definition).
The latter has to do with the fact that julia code is fast once compiled, and that the package can spend more time finding the non-stochastic steady state. This means that it takes more time from executing the code to define the model and parameters for the first time to seeing the first plots than with most other packages. But, once the functions are compiled and the non-stochastic steady state has been found the user can benefit from the object oriented nature of the package and generate outputs or change parameters very fast.
The package contains the following models in the models folder:
- Aguiar and Gopinath (2007)
Aguiar_Gopinath_2007.jl - Ascari and Sbordone (2014)
Ascari_Sbordone_2014.jl - Backus, Kehoe, and Kydland (1992)
Backus_Kehoe_Kydland_1992.jl - Baxter and King (1993)
Baxter_King_1993.jl - Caldara et al. (2012)
Caldara_et_al_2012.jl - Gali (2015) - Chapter 3
Gali_2015_chapter_3_nonlinear.jl - Gali and Monacelli (2005) - CPI inflation-based Taylor rule
Gali_Monacelli_2005_CITR.jl - Federal Reserve Board U.S. model (FRB/US) - LINVER (2024))
FRBUS.jl - Gerali, Neri, Sessa, and Signoretti (2010)
GNSS_2010.jl - Ghironi and Melitz (2005)
Ghironi_Melitz_2005.jl - Ireland (2004)
Ireland_2004.jl - Jermann and Quadrini (2012) - RBC
JQ_2012_RBC.jl - New Area-Wide Model (2008) - Euro Area - US
NAWM_EAUS_2008.jl - QUEST3 (2009)
QUEST3_2009.jl - Schmitt-Grohé and Uribe (2003) - debt premium
SGU_2003_debt_premium.jl - Schorfheide (2000)
FS2000.jl - Smets and Wouters (2003)
SW03.jl - Smets and Wouters (2007)
SW07.jl
Speed
MacroModelling.jl is genuinely faster than Dynare at computing perturbation solutions, which makes it well suited for tasks where runtime matters most — in particular estimation.
For first-order solves, Dynare is most competitive when using compiled MATLAB mex files. MacroModelling.jl is still faster in that case, but the gap narrows as model size grows and the QZ decomposition starts to dominate the runtime; at that point performance is largely determined by the underlying BLAS/LAPACK rather than by the surrounding code.
For higher-order perturbation the gap widens substantially. MacroModelling.jl is typically close to an order of magnitude faster at second order, and around two orders of magnitude faster at third order (roughly 40x–115x on the bundled third-order timings for Caldara_et_al_2012 and Gali_2015_chapter_3_nonlinear). Derivative construction (Jacobians and Hessians) shows even larger relative speedups — often 100x–1000x — but because those operations take only microseconds in absolute terms for most models, they are not the main driver of end-to-end runtime. The speedups that actually change the user experience are in the solve steps themselves.
See the Speed Benchmarks page for full per-model timings across operating systems and CPU architectures.
Wall-clock user experience is a different story. MacroModelling.jl inherits Julia's just-in-time compilation cost: time-to-first-output can take a minute or more on a small model while the relevant functions are compiled. Once compiled, every subsequent call is fast. Dynare, being built on a compiled host - MATLAB, has the edge on the first call, but this advantage erodes as model size grows and disappears entirely as soon as functions are reused.
In practice: if the goal is a single output from a model run once, Dynare will deliver it sooner. For iterative work — changing parameters or equations interactively, running estimation, or anything that calls the solvers many times — MacroModelling.jl is the better fit, thanks to its interactive design, the speed of precompiled functions, and its compatibility with Julia's rich ecosystem of gradient-based samplers.
Comparison with other packages
| MacroModelling.jl | dynare | DSGE.jl | dolo.py | SolveDSGE.jl | DifferentiableStateSpaceModels.jl | StateSpaceEcon.jl | IRIS | RISE | NBTOOLBOX | gEcon | GDSGE | Taylor Projection | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Host language | julia | MATLAB | julia | Python | julia | julia | julia | MATLAB | MATLAB | MATLAB | R | MATLAB | MATLAB |
| Non-stochastic steady state solver | symbolic or numerical solver of independent blocks; symbolic removal of variables redundant in steady state; inclusion of calibration equations in problem; custom steady state function can be provided | numerical solver of independent blocks or user-supplied values/functions | numerical solver of independent blocks or user-supplied values/functions | numerical solver | numerical solver or user supplied values/equations | numerical solver of independent blocks or user-supplied values/functions | numerical solver of independent blocks or user-supplied values/functions | numerical solver of independent blocks or user-supplied values/functions | user-supplied steady state file or numerical solver | numerical solver; inclusion of calibration equations in problem | |||
| Automatic declaration of variables and parameters | yes | ||||||||||||
| Derivatives wrt parameters | yes | yes | |||||||||||
| Perturbation solution order | 1, 2, 3 | k | 1 | 1, 2, 3 | 1, 2, 3 | 1, 2 | 1 | 1 | 1 to 5 | 1 | 1 | 1 to 5 | |
| Pruning | yes | yes | yes | yes | |||||||||
| Automatic derivation of first order conditions | yes | ||||||||||||
| Occasionally binding constraints | yes | yes | yes | yes | yes | yes | yes | ||||||
| Global solution | yes | yes | yes | ||||||||||
| Estimation | yes | yes | yes | yes | yes | yes | yes | yes | |||||
| Balanced growth path | yes | yes | yes | yes | yes | yes | |||||||
| Model input | macro (julia) | text file | text file | text file | text file | macro (julia) | module (julia) | text file | text file | text file | text file | text file | text file |
| Timing convention | end-of-period | end-of-period | end-of-period | start-of-period | start-of-period | end-of-period | end-of-period | end-of-period | end-of-period | end-of-period | start-of-period | start-of-period |
Bibliography
- Andreasen, M. M.; Fernández-Villaverde, J. and Rubio-Ramírez, J. F. (2017). The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications. The Review of Economic Studies 85, 1–49, arXiv:https://academic.oup.com/restud/article-pdf/85/1/1/23033725/rdx037.pdf.
- Durbin, J. and Koopman, S. J. (2012). Time Series Analysis by State Space Methods, 2nd edn (Oxford University Press).
- Galı́, J. (2015). Monetary policy, inflation, and the business cycle: an introduction to the new Keynesian framework and its applications (Princeton University Press).
- Villemot, S. (2011). Solving rational expectations models at first order: what Dynare does (Dynare Working Papers 2, CEPREMAP).