GDSGE: A Toolbox for Solving DSGE Models with Global Methods

Welcome to GDSGE’s documentation!

GDSGE is a toolbox that solves nonlinear Dynamic Stochastic General Equilibrium (DSGE) models with a global method based on the Simultaneous Transition and Policy Function Iteration (STPFI) algorithm introduced in Cao, Luo, and Nie (2023). It allows users to define economic models in compact and intuitive scripts, called gmod files (gmod stands for global model). It parses the script into dynamic libraries which implement the actual computations (policy function iterations and Monte Carlo simulations) efficiently in C++, and provides a convenient MATLAB interface to researchers.

The toolbox can be used to solve models in macroeconomics, international finance, asset pricing, and related fields.

To get started, run in the MATLAB command window

websave('gdsge.zip','https://github.com/gdsge/gdsge/archive/refs/heads/main.zip')
unzip gdsge.zip
mex -setup c++
cd gdsge-main/tests
runtests

These commands download the latest version of the toolbox, set up the mex compiler, and run the test examples. This works on Windows, macOS, and MATLAB Online (Linux). These produce all results in the companion paper Cao, Luo, and Nie (2023).

Then try the leading example, Heaton and Lucas (1996). Its gmod file HL1996.gmod ships with the toolbox under tests/HeatonLucas1996. Continuing from the tests folder above, run in MATLAB

cd HeatonLucas1996
gdsge_codegen('HL1996')              % parse the gmod file, generate code, compile the mex file
IterRslt = iter_HL1996;              % policy iterations
SimuRslt = simulate_HL1996(IterRslt); % Monte Carlo simulations

Compiling a model

gmod files are compiled locally, on your own machine, by the C++ compiler that mex -setup c++ configured; there is no separate compiler to install or service to upload to. To compile your own model, add the toolbox’s src folder to the MATLAB search path once per session (runtests does this for you), change directory to the folder that contains <model>.gmod, and run

addpath('path/to/gdsge-main/src')
gdsge_codegen('model')

This generates iter_model.m, simulate_model.m and mex_model.cpp in the current folder and compiles the mex file mex_model (e.g., mex_model.mexw64 on Windows). Compiling again is fast if the model’s C++ code has not changed, because the mex file is reused. Then call iter_model to solve the model and simulate_model to simulate it (see Toolbox API). Alternatively, gdsge('model') compiles, solves and simulates in one call.

Optionally, run gdsge_setup_sympy once to enable the SymPy backend, which computes analytic Jacobians and requires Python (the command installs it for you through uv). The default backend needs only MATLAB and a C++ compiler.

Note

Since version 0.2 the toolbox has been rebuilt from the ground up, and all gmod files still run unchanged. The old online compiler has been retired. All compilation now happens locally with gdsge_codegen. See the toolbox README for what’s new. The original toolbox is archived on the legacy-0.1.x branch.

The toolbox source code is hosted at: https://github.com/gdsge/gdsge, where you can download the latest version of the toolbox, find detailed instructions for setting up the compiler, and submit issues.

Examples and documentation of the toolbox are provided below.

Lectures on the toolbox can be found at Lectures.

If you have comments, suggestions or coding questions for us, or would like to contribute GDSGE examples, please reach out to us at: gdsge.cln2020@gmail.com


Contents:

Indices and tables