MATLAB code for my research: three toolkits on GitHub, the code for each paper, and the code for my books.
Toolkits on GitHub
bvar-toolkit collects eleven of the packages below and factors the machinery they share — the samplers, the shrinkage priors, the marginal likelihood estimators — into a documented library, with fourteen examples to learn the methods.
statespace-toolkit collects fourteen other packages and factors the precision sampler, the integrated likelihood and the truncated normal sampler into a documented library, with ten examples to learn the methods.
trend-cycle-toolkit re-estimates six of the trend inflation and output gap models below every quarter and publishes the resulting estimates.
To learn the methods: the tutorials answer empirical questions with the settings of published papers, and the how-to guides show how to turn a model's equations into working MATLAB code, step by step.
Code for Each Paper
By topic: VARs and VARMAs · stochastic volatility and GARCH · marginal likelihood and DIC · inflation · output gap · other models. The research page lists the code with each paper, and the overviews of large Bayesian VARs, high-dimensional state space models and trend inflation models describe the main papers.
Vector Autoregressions and VARMAs
The research page on large Bayesian VARs describes the recent papers.
- A large structural VAR identified with many sign and ranking restrictions (Chan, Matthes and Yu, 2026)
- Five large Bayesian matrix autoregressions, including versions with common stochastic volatility, t errors and an outlier component (Chan and Qi, 2026)
- A new hybrid TVP-VAR with SV where each equation can have either constant or time-varying coefficients (Chan, 2023)
- A large order-invariant Bayesian VAR with SV (Chan, Koop and Yu, 2024)
- A large TVP-VAR with SV where the time-varying parameters and stochastic volatilities are formulated as a singular state space model (Chan, Eisenstat and Strachan, 2020)
- Estimation code of a standard, large reduced-form Bayesian VAR with SV (Carriero, Chan, Clark and Marcellino, 2022)
- A new family of Minnesota-type adaptive hierarchical priors for Large Bayesian VARs with SV (Chan, 2021)
- A large Bayesian VAR with a new asymmetric conjugate prior; the application estimates a 15-variable VAR identified with sign restrictions (Chan, 2022)
- Forecasting using large BVARs with various shrinkage priors (Chan, 2020)
- Large Bayesian VARs with non-Gaussian, heteroscedastic and serially dependent innovations (Chan, 2020)
- Forecasting using time-varying parameter VARMAs with stochastic volatility (Chan and Eisenstat, 2017)
- Time-varying parameter VAR with SV and stochastic model specification search (Eisenstat, Chan and Strachan, 2016)
- Time-varying parameter VAR with constant volatility (Chan and Jeliazkov, 2009)
Stochastic Volatility and GARCH Models
- Seven pairs of SV and GARCH models, including the SV in mean model and the SV model with leverage (Chan and Grant, 2016)
- Time-varying parameter VAR with SV and stochastic model specification search (Eisenstat, Chan and Strachan, 2016)
- Three univariate SV models: standard SV, SV with MA(1) Gaussian errors and SV with MA(1) Student's t errors (Chan and Hsiao, 2014)
- Stochastic volatility in mean model with time-varying parameters (Chan, 2017)
- Four stochastic volatility models with moving average errors (Chan, 2013)
Marginal Likelihood and Deviance Information Criterion
- Marginal likelihood computation for large VARs that differ in their stochastic volatility and in how they treat the COVID-19 outliers (Chan, Yu and Zhang, 2026)
- Marginal likelihood computation for large VARs with 4 different types of SV (Chan, 2023)
- Marginal likelihood computation for hybrid TVP-VARs with SV (Chan and Eisenstat, 2018)
- Marginal likelihood and DIC computation for 10 VARs, including time-varying parameter VARs with SV and regime-switching VARs (Chan and Eisenstat, 2018)
- Bayes factor computation for time-varying coefficients vs constant coefficients (Chan, 2018)
- Observed-data and conditional DICs computation for 7 SV models (Chan and Grant, 2016)
- Marginal likelihood computation for 7 SV and 7 GARCH models (Chan and Grant, 2016)
- Three variants of the DIC for three latent variable models: static factor model, TVP-VAR and semiparametric regression (Chan and Grant, 2016)
- Marginal likelihood computation for 6 models using the cross-entropy method: VAR, dynamic factor VAR, TVP-VAR, probit, logit and t-link (Chan and Eisenstat, 2015)
Models for Inflation
The research page on trend inflation models describes these models.
- A new bivariate UC model for measuring long-run inflation expectations uncertainty using both monthly inflation and daily break-even inflation data (Chan and Song, 2018).
- A new trend inflation model using both inflation data and long-run inflation expectations (Chan, Clark and Koop, 2018)
- Stock and Watson (2007) model: unobserved components model with 2 SVs (code from Chan, 2018)
- Unobserved components model with inflation volatility feedback (Chan, 2017)
- Unobserved components model with a bounded inflation trend and SV (Chan, Koop and Potter, 2013)
- Bivariate unobserved components model with bounded inflation trend and NAIRU (Chan, Koop and Potter, 2016)
- Unobserved components models with stochastic volatility and moving average errors (Chan, 2013)
Models for Output Gap
- Output gap from a trivariate unobserved components model using stochastic model specification search (Grant and Chan, 2017)
- Output gap from extensions of the HP filter by allowing serial correlation in the cyclical component (Grant and Chan, 2017)
- Output gaps from eight unobserved components models, including models with correlated trend and cycle innovations and breaks in trend output growth (Grant and Chan, 2017)
Other Models
- A regime switching skew-normal model of contagion (Chan, Fry-McKibbin and Hsiao, 2018)
- A partially identified instrumental variable model (Chan and Tobias, 2015)
Code for My Books
MATLAB and R code for Statistical Modeling and Computation (Second Edition, 2025) is at the book website, and MATLAB code for Bayesian Econometric Methods (Second Edition) is at its book website. Code for Bayesian Macroeconometrics: Methods and Applications (Chapman & Hall/CRC, forthcoming) is on GitHub, in MATLAB, R and Python for all fourteen chapters.
How to Cite
Each package page names the paper to cite, and the CITING.md files of bvar-toolkit and statespace-toolkit map each method to its paper. Please contact me if you find any errors.
Other Sources
Other econometricians, and the European Central Bank, provide MATLAB and R code for related models:
- MATLAB code associated with Gary Koop's books, papers and short courses can be found on his computer code page.
- Dimitris Korobilis provides MATLAB code on GitHub for a wide variety of models, including Bayesian VARs, panel VARs and factor models.
- Haroon Mumtaz provides MATLAB code for Markov-switching and threshold VARs, panel VARs, factor-augmented VARs and VARs with stochastic volatility in mean, along with his notes on applied Bayesian econometrics for central bankers.
- The European Central Bank's BEAR toolbox estimates Bayesian VARs in MATLAB, including time-varying, panel, factor-augmented and mixed-frequency VARs, with sign and zero restrictions and conditional forecasts.
- Jouchi Nakajima provides MATLAB and R code for estimating various stochastic volatility models, including a TVP-VAR with SV.
- Tomasz Woźniak and coauthors maintain R packages for Bayesian structural VARs identified by exclusion restrictions, heteroscedasticity, non-normality or sign restrictions; one of them, bvars, estimates four of the VARs of Chan (2020).
- Gregor Kastner and coauthors maintain the R packages stochvol, for univariate stochastic volatility models, and bayesianVARs, for VARs with stochastic volatility and hierarchical shrinkage priors.