Matlab Code‎ > ‎

MS_Regress - A Package for Markov Regime Switching Models in Matlab


This submission provides functions (and examples scripts) for estimation, simulation and forecasting of a general Markov Regime Switching Regression. 

Before using the package, make sure you read the pdf file (About the MS_Regress_Package.pdf) in the downloaded zip file (or link below). A copy of this paper can also be found in
Features of the package: 
  • Support for univariate and multivariate models;
  • Support of any number of states and any number of explanatory variables;
  • Estimation, by maximum likelihood, of any type of switching setup for the model. This means that you can choose which coefficients in the model, including distribution parameters, are switching states over time;
  • A wrapper function for the estimation of regime switching autoregressive models, including multivariate case (MS-VAR) is included in the package;
  • The values of parameter's standard errors can be calculated with 2 different methods;
  • Includes a C version of hamilton’s filter that may be used for speeding up the estimation function (see pdf for details);
  • Possibility of three distinct distribution assumptions for residual vector (Normal, t or GED);
  • The user can choose the optimizing function to be used in the estimation of the model (fminsearch, fmincon or fminunc);
  • Support for reduced/constrained estimation (see pdf document for details);
  • Several example scripts that show how to use the code;
Limitations of the package (so far): 
  • The EM algorithm is not implemented (all models are estimated by direct maximization of log likelihood function);
  • It does not support state space models with markov switching effects;
  • It cannot estimate a model with time varying transition probabilities (TVPT). But, Zhuanxin Ding has developed a matlab package for TVTP models based on MS_Regress. You can access it here;
  • It does not support models with garch type of filters for conditional volatility;
I also wrote a R/S+ version of the package (fMarkovSwitching). It is public available in the R Metrics project and in R Code section of this website. Please be aware that the R version in no longer being maintained so it is actually an older version of the matlab package with only the basic features.    

Required Products:  

Optimization, Statistics

Alexander, C. (2008) ‘Market Risk Analysis: Practical Financial Econometrics’ Wiley. 
Brooks, C. (2002) ‘Introduction to Econometrics’ Cambridge University Press. 
Hamilton, J., D. (2005) Regime Switching Models. Palgrave Dictionary of Economics, (available at ) 
Hamilton , J., D. (1994) ‘Time Series Analysis’ Princeton University Press. 
Kim, C., J., Nelson, C., R. (1999) State Space Model with Regime Switching: Classical and Gibbs-Sampling Approaches with Applications. The MIT press. 
Marcelo Perlin,
Apr 19, 2015, 6:26 PM
Marcelo Perlin,
Feb 24, 2014, 6:54 AM
Marcelo Perlin,
Oct 30, 2014, 9:04 AM
Marcelo Perlin,
Apr 19, 2015, 6:33 PM
Marcelo Perlin,
Apr 19, 2015, 6:33 PM