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:
- Home
- Lectures
- Getting Started - A Simple RBC Model
- Comparison with OccBin: A Simple Model with an Occasionally Binding Interest Rate ZLB
- An RBC Model with Irreversible Investment
- Heaton and Lucas (1996): Incomplete Markets with Portfolio Choices
- Guvenen (2009): Asset Pricing with Heterogeneous IES
- Bianchi (2011): Sudden Stops in Open Economies
- Barro et al. (2017): Safe Assets with Rare Disasters
- Guerrieri et al. (2022): Negative Supply Shocks That Cause Demand Shortages
- A Multi-country Business Cycle Model
- A New-Keynesian Model with an Occasionally Binding Interest Rate Zero Lower Bound
- Toolbox API
- Additional Examples
- Huggett (1997): Steady States and Transition Paths in Heterogeneous Agent Models
- Krusell and Smith (1998): Heterogeneous Agent Models with Aggregate Uncertainty
- Mendoza (2010): Sudden Stops with Asset Price Deflation
- Cao and Nie (2017): Amplification and Asymmetry without Collateral Constraint
- Cao (2018): Speculation and Wealth Distribution under Beliefs Heterogeneity
- Cao (2020): Continuum versus Finite Agents in Krusell and Smith (1998)
- Contributed Examples