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.
Twelve of the packages below are also collected on GitHub as bvar-toolkit. Each is archived there exactly as it is distributed here, and the machinery they share — the samplers, the shrinkage priors, the marginal likelihood estimators — is factored into a single documented library. Download a zip below to reproduce a particular paper; use the toolkit to build on the code.
Start here
If you use code from this page, please cite the most relevant default reference(s) below. These papers form a coherent toolkit for scalable Bayesian time series and state space methods.
- Precision-based state space simulation (computational engine): Chan and Jeliazkov (2009), Efficient Simulation and Integrated Likelihood Estimation in State Space Models, International Journal of Mathematical Modelling and Numerical Optimisation, 1, 101-120 (code | Examples)
- SV specification choice for large Bayesian VARs: Chan (2023), Comparing Stochastic Volatility Specifications for Large Bayesian VARs, Journal of Econometrics, 235(2): 1419-1446 (code)
- Order-invariant Bayesian VARs with SV: Chan, Koop and Yu (2024), Large Order-Invariant Bayesian VARs with Stochastic Volatility, Journal of Business and Economic Statistics, 42(2): 825-837 (code)
- Default shrinkage prior for large BVARs: Chan (2021), Chan (2021), Minnesota-Type Adaptive Hierarchical Priors for Large Bayesian VARs, International Journal of Forecasting, 37(3): 1212-1226 (code)
- Large conditionally Gaussian state space models with mixed-frequency data: Chan, Poon and Zhu (2023), High-Dimensional Conditionally Gaussian State Space Models with Missing Data, Journal of Econometrics, 236(1): 105468
- Trend inflation with long-run inflation expectations: Chan, Clark and Koop (2018), A New Model of Inflation, Trend Inflation, and Long-Run Inflation Expectations Journal of Money, Credit and Banking, 50(1), 5-53 (code)
Research overviews: Large Bayesian VARs | High-dimensional state space models | Trend inflation models.
If you want to download the code associated with a particular paper, it will be easier to locate it at my research page. Below I organize the code by topics.
Please contact me if you find any errors.
Vector Autoregressions and VARMAs
See here for more information about my recent projects on large Bayesian VARs.
- A new hybrid TVP-VAR with SV where each equation can have either constant or time-varying coefficients
- A large order-invariant Bayesian VAR with SV
- A large TVP-VAR with SV where the time-varying parameters and stochastic volatilities are formulated as a singular state space model
- Estimation code of a standard, large reduced-form Bayesian VAR with SV
- A new family of Minnesota-type adaptive hierarchical priors for Large Bayesian VARs with SV
- A large Bayesian VAR with a new asymmetric conjugate prior; the application estimates a 15-variable VAR identified with sign restrictions
- Forecasting using large BVARs with various shrinkage priors
- Large Bayesian VARs with non-Gaussian, heteroscedastic and serially dependent innovations
- Forecasting using time-varying parameter VARMAs with stochastic volatility
- Time-varying parameter VAR with SV and stochastic model specification search
- Time-varying parameter VAR with constant volatility
Stochastic Volatility and GARCH Models
- Seven pairs of SV and GARCH models, including the SV in mean model and the SV model with leverage
- Time-varying parameter VAR with SV and stochastic model specification search
- Three univariate SV models: standard SV, SV with MA(1) Gaussian errors and SV with MA(1) Student's t errors
- Stochastic volatility in mean model with time-varying parameters
- Four stochastic volatility models with moving average errors
Marginal Likelihood and Deviance Information Criterion
- Marginal likelihood computation for large VARs with 4 different types of SV
- Marginal likelihood computation for hybrid TVP-VARs with SV
- Marginal likelihood and DIC computation for 10 VARs, including time-varying parameter VARs with SV and regime-switching VARs
- Bayes factor computation for time-varying coefficients vs constant coefficients
- Observed-data and conditional DICs computation for 7 SV models
- Marginal likelihood computation for 7 SV and 7 GARCH models
- Three variants of the DIC for three latent variable models: static factor model, TVP-VAR and semiparametric regression
- Marginal likelihood computation for 6 models using the cross-entropy method: VAR, dynamic factor VAR, TVP-VAR, probit, logit and t-link
Models for Inflation
See here for more information about my research on trend inflation models.
- A new bivariate UC model for measuring long-run inflation expectations uncertainty using both monthly inflation and daily break-even inflation data.
- A new trend inflation model using both inflation data and long-run inflation expectations
- Stock and Watson (2007) model: unobserved components model with 2 SVs
- Unobserved components model with inflation volatility feedback
- Unobserved components model with a bounded inflation trend and SV
- Bivariate unobserved components model with bounded inflation trend and NAIRU
- Unobserved components models with stochastic volatility and moving average errors
Models for Output Gap
- Output gap from a trivariate unobserved components model using stochastic model specification search
- Output gap from extensions of the HP filter by allowing serial correlation in the cyclical component
- Output gaps from eight unobserved components models, including models with correlated trend and cycle innovations and breaks in trend output growth
Other Models
- A regime switching skew-normal model of contagion
- A partially identified instrumental variable model
Other Sources
A number of econometricians have provided code associated with their books or papers:
- MATLAB code associated with Gary Koop's books, papers and short courses can be found on his website.
- Dimitris Korobilis provides code for estimating a wide variety of models, including Bayesian VARs, TVP-VARs and factor models.
- Jouchi Nakajima provides MATLAB and R code for estimating various stochastic volatility models, including a TVP-VAR with SV.