MacroModelling.jl

Documentation: Documentation

codecovCI

Author: Thore Kockerols (@thorek1)

MacroModelling.jl is a package for developing and solving dynamic stochastic general equilibrium (DSGE) models. The package provides functions for creating, calibrating, simulating and estimating discrete-time DSGE models.

The goal of MacroModelling.jl is to reduce coding time and speed up model development.

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)
  • calculate first, second, and third order perturbation solutions using (forward or reverse-mode) automatic differentiation (AD)
  • calculate (generalised) impulse response functions, simulate the model, or do conditional forecasts
  • calibrate parameters using (non stochastic) steady state relationships
  • match model moments
  • estimate the model on data (Kalman filter using first order perturbation)
  • differentiate (forward AD) the model solution, Kalman filter loglikelihood (reverse-mode AD), model moments, steady state, with respect to the parameters

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 you already have a fast way to find the NSSS (time to first plot is long, time to second plot (with new parameters) is very short)

For more details have a look at the documentation.

Getting started

Installation

MacroModelling.jl requires julia version 1.8 or higher and an IDE is recommended (e.g. VS Code with the julia extension).

Once set up you can install MacroModelling.jl (and StatsPlots in order to plot) by typing the following in the Julia REPL:

using Pkg; Pkg.add(["MacroModelling", "StatsPlots"])

Example

See below an implementation of a simple RBC model. You can find more detailed tutorials in the documentation.

using MacroModelling
import StatsPlots

@model RBC begin
    1  /  c[0] = (β  /  c[1]) * (α * exp(z[1]) * k[0]^(α - 1) + (1 - δ))
    c[0] + k[0] = (1 - δ) * k[-1] + q[0]
    q[0] = exp(z[0]) * k[-1]^α
    z[0] = ρ * z[-1] + std_z * eps_z[x]
end;

@parameters RBC begin
    std_z = 0.01
    ρ = 0.2
    δ = 0.02
    α = 0.5
    β = 0.95
end;

plot_irf(RBC)

RBC IRF

The package contains the following models in the models folder:

Comparison with other packages

MacroModelling.jldynareRISENBTOOLBOXIRISDSGE.jlStateSpaceEcon.jlSolveDSGE.jldolo.pyDifferentiableStateSpaceModels.jlgEconGDSGETaylor Projection
Host languagejuliaMATLABMATLABMATLABMATLABjuliajuliajuliaPythonjuliaRMATLABMATLAB
Non stochastic steady state solversymbolic or numerical solver of independent blocks; symbolic removal of variables redundant in steady state; inclusion of calibration equations in problemnumerical solver of independent blocks or user-supplied values/functionsnumerical solver of independent blocks or user-supplied values/functionsuser-supplied steady state file or numerical solvernumerical solver of independent blocks or user-supplied values/functionsnumerical solver of independent blocks or user-supplied values/functionsnumerical solvernumerical solver or user supplied values/equationsnumerical solver or user supplied values/equationsnumerical solver; inclusion of calibration equations in problem
Automatic declaration of variables and parametersyes
Derivatives (Automatic Differentiation) wrt parametersyesyes - for all 1st, 2nd order perturbation solution related output if user supplied steady state equations
Perturbation solution order1, 2, 3k1 to 511111, 2, 31, 2, 31, 211 to 5
Automatic derivation of first order conditionsyes
Handles occasionally binding constraintsyesyesyesyesyesyes
Global solutionyesyesyes
Estimationyesyesyesyesyesyesyes
Balanced growth pathyesyesyesyesyesyes
Model inputmacro (julia)text filetext filetext filetext filetext filemodule (julia)text filetext filemacro (julia)text filetext filetext file
Timing conventionend-of-periodend-of-periodend-of-periodend-of-periodend-of-periodend-of-periodstart-of-periodend-of-periodstart-of-periodend-of-periodstart-of-periodstart-of-period

Bibliography

Durbin, J, and Koopman, S. J. (2012), "Time Series Analysis by State Space Methods, 2nd edn", Oxford University Press.

Levintal, O., (2017), "Fifth-Order Perturbation Solution to DSGE models", Journal of Economic Dynamics and Control, 80, pp. 1---16.

Villemot, S., (2011), "Solving rational expectations models at first order: what Dynare does", Dynare Working Papers 2, CEPREMAP.