Code covered by the BSD License  

Highlights from
MS_Regress - A Package for Markov Regime Switching Models in Matlab

4.5

4.5 | 32 ratings Rate this file 264 Downloads (last 30 days) File Size: 200.01 KB File ID: #15789
image thumbnail

MS_Regress - A Package for Markov Regime Switching Models in Matlab

by Marcelo Perlin

 

01 Aug 2007 (Updated 17 Aug 2011)

Functions to Estimate, Simulate and Forecast Markov Regime Switching Models in Matlab

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This submission provides functions (and examples scripts) for estimation, simulation and forecasting of a general Markov Regime Switching Regression.
 
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).
- Support for reduced/constrained estimation (see pdf document for details).
- Loads of example scripts.
 
Limitations of the package (so far):
- The EM algorithm is not implemented (all models are estimated by direct maximization of log likelihood function).
- It doesn’t support state space models with markov switching effects.
- It cannot estimate a model with time varying transition probabilities (TVPT).
- It doesn’t support models with garch type of filters for conditional volatility.
 
Here a few references in Markov Switching models:
   
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 http://dss.ucsd.edu/~jhamilto/palgrav1.pdf )
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.
   
Before using the package, make sure you read the pdf file (About the MS_Regress_Package.pdf) in the downloaded zip file. A copy of this paper can be found in http://ssrn.com/abstract=1714016.
   
I also wrote a R/S+ version of the package (fMarkovSwitching). It is public available in the Rmetrics project: http://r-forge.r-project.org/projects/rmetrics/. Please be aware that the R version in no longer being maintained so it is actually an older version of the package with only the basic features.
   
Fell free to send any comments/suggestions to my email.

Required Products Optimization Toolbox
Statistics Toolbox
MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (97)
07 Aug 2007 PAUL SHIWAMYA  
31 Mar 2008 Han A

Thank you. Very useful to start my own model.

12 Apr 2008 rao xhui

thank you! it is useful to me!

10 Jun 2008 tt fan

thanks!

15 Jun 2008 LONG FEI

Thanks!!!

21 Jun 2008 Anton Shishkin

This is really great. Thank you very much. Have you tried models with endogenous switching?

23 Jun 2008 Marcelo Perlin

Hi Anton,

I'm the author.
Thanks for your comments, I really apreciate it.

Regarding your question, no I haven't tried endogenous switching.

Cheers.
Marcelo.

06 Aug 2008 leo song

great!thanks your

22 Sep 2008 knani ramzi  
11 Dec 2008 Jonathan

Hi, what kind of parameter evaluation approach you are using in this package? is it the EM algorithm?

12 Dec 2008 Marcelo Perlin

Hi Jonathan,
The parameters are estimated by standard maximum likelihood procedure so, currently, the EM algorithm is not implemented.
I'll keep it in mind for the future.

Regards.
Marcelo.

12 Dec 2008 Jonathan

thanks for the quick response. Generally speaking, the code is already very useful, good work.

02 Feb 2009 Bongju

your program is useful. How can I draw the picture which compare realized y and predicted y according to data sequence?

14 Mar 2009 Elena Dumitrescu

Hi, I'm new in using matlab, but I would need to use a Markov switching model with time varying probabilities, evolving as logistic functions of the independent variables (as in Diebold and Weinbach 1994) . Can you, please, tell me how can I use your program in order to do that?
Thank you!

16 Mar 2009 Marcelo Perlin

Hi Elena,

Currently the package can't handle TVTP models as the transition matrix is assumed constant.

You'll have to modify the original code for this setup.

Regards.
Marcelo.

04 Apr 2009 Salman  
01 Aug 2009 gajd

Hi, Marcelo,

I've tried the R-package. It shows a mistake. Can we discull the mistake here or is there a special R-forum for that?

Regards, Gajd

03 Aug 2009 Marcelo Perlin

Hi gajd, fell free to contact me in my email.
Cheers.

06 Aug 2009 MehdiHK Hosseinkouchack

Nice file, thanks. Although, there are cases for which the algorithm does not work. You need to impose more structure on transition prob matrix Also if there are 2 states then there are only 2 prob's entering the search space not 4. Having more states increases the dimensions very fast.

07 Aug 2009 MehdiHK Hosseinkouchack

Well, I decided to recode things from the beginning. I think that the p-values are wrong which is because of the problem I mentioned before with the way you enter the probabilities into the search space. This is not just a dimension problem. When you calculate a numerical gradient, for the probability param's for example (for k=2), you change p11 while p12 is constant! In this case even if p11+p12 was 1, it will not be one when feeding it to the likelihood function!!
Another point is that you need to make sure that sum of the probabilities for state j (j=1,2,...,k) is 1. This is not guaranteed in your program.

07 Aug 2009 Marcelo Perlin

Dear MehdiHK, regarding your first comment, the way I coded the optimization problem was jsut a matter of simplicity in the algorithm. I'm fully aware that the search space could be decreased by one elemente by conducting it as a inequality optimization problem, as opposed to an equality one.

For your second comments, the p values of the coefficients are fine and so is the way I coded the transition matrix.
If you look closelly in MS_Regress_Fit, you'll see that I'm using constrained estimation so that the each column of Coeff.p is summing to 1, according to my choice of numerical convergence.

If you have any further question, feel free to drop me an email.
Marcelo.

07 Aug 2009 MehdiHK Hosseinkouchack

Dear Marcelo,

A) I am pretty sure that the probabilities do not sum up to the correct value. As a check: for a k=2 case, try to check if sum of all the elements in Coeff.p always is equal to 1 in all the cases!

B) About the search space, for a case of k=2, not that ONE parameters are more than enough, but that TWO are more than enough b/c P=[p11 p12; p21 p22] is identified if from each ROW exactly ONE element is know so 2 element is enough not 3. (you mentioned that 4 can be decreased by 1!!!)

C) ROWS should sum up to ONE not columns.

I closely looked into all of your codes. They are neat, but you have some mistakes that should be fixed.

Thanks a lot
Mehdi

08 Aug 2009 Marcelo Perlin

MehdiHK,

For A), from what you wrote it seems that the the transition matrix in the reference you used has a different notation than mine. In short, my transposed transition matrix will be equal to yours. Therefore, for my code, you should be looking at columns for the full process in each state (and not rows).

For B), I was not clear. I meant the decrease of one element in each state. So we agree.

Regards.

09 Aug 2009 MehdiHK Hosseinkouchack

Dear Marcelo,

This still does not solve the problem. I had a check on the probabilities: for k=2 I was checking if sum of the elements of the transition matrix adds up to 2, and it was not! well transposed or not transposed, rows or columns, does not matter now ...

For comment B decreasing search space based on my comment is agreed then.

Best of Wishes
MehdiHK

19 Sep 2009 MehdiHK Hosseinkouchack

Dear Marcelo,

I would like thank myself from your side for finding a little bug in your code. It is, however, excellent! I appreciate your efforts.

Best of Wishes
MehdiHK

29 Nov 2009 andrea182

great job!

I need help ...

I would like to create a function that given a vector of price variation I restore the prediction of the next price change ...

How could I do?

I think it's a very simple thing to do but this thing is making me crazy ...

thanks for any help ...

29 Nov 2009 Marcelo Perlin

Hi Andrea,

I used to have a function to calculate forecasts from a model but, with the new updates, the funcionality was lost. I shall write a compatible one once I have the free time.

In the meanwhile, have a look in the references writen in the pdf file. Its all there.

Regards.
Marcelo.

14 Jan 2010 Aaron

Awesome code. I am really trying to do something absurdly simple here, which might be the problem. I want to generate a univariate two-state Markov regime switching process, where the series is only related to a regime-dependent mean (e.g. the only independent variable is a column of ones). Can MS_Regress_Sim.m be used for this purpose>

15 Jan 2010 Marcelo Perlin

Hi Aron,

Thanks for your comments.

Yes, the code can handle your specification. For that, just set the indepMean=1 and indepStd=0. This will do the trick.

Regards.

22 Jan 2010 Aaron

Hi Marcelo,

Thanks...This is exactly as I thought...The problem is that there are no non-switching independent parameters in this case. Setting nS_param to the null vector produces an error

23 Jan 2010 Marcelo Perlin

Aaron, yes, I got the same error. It seems to a be a simple problem whitin the code. I'll fix it and include in the new update.

Thanks for the letting me know about this.

Regards,
M. P.

06 Feb 2010 Saad

Hi,

I am currently working on the MS VAR and I was wondering if anyone of you who have been using the MS_regress_fit got a standard error of zero and a p value of zero (just below the estimation of the coeffcients). The estimations of the coefficients of the MSVAR seem intuitive to me but I am surprised to have a standard error and a pvalue of zero? Any thoughts about this issue? Thanks in advance

10 Feb 2010 Alexey M

Hi Marcelo,

I've tried to run a couple of examples from your package and got following error:
Error using ==> fmincon
FMINCON cannot continue because...
Variable 'indep_nS' is used as a command/function.

There is probably a mistake in the code with vector of n-S independent parameters in the likelihood function. Unfortunately, I could not find where the problem is.
Could you help please.

PS: Thanks a lot for this package.

10 Feb 2010 Marcelo Perlin

Hi Alexey,

I've seen this before and it is a version issue (I wrote the code in matlab 2008).

For fixing it for you version, you'll have to search for the lines where the error was found and replace with equivalent, version compatible, lines.

Cheers.
Marcelo.

25 Feb 2010 Ansgar Walther

Hi Marcelo,

I've been trying to extend your code to include time-varying transition probabilities. I think I've got it to work, which mainly involved a few changes to the coefficient structure and the Hamilton filter in the MS_Regress_Lik file. The only odd thing is that fmincon converges to local maxima that don't make sense, so I've used fminsearch instead.

It would be great if you could have a look at it to see whether what I've done makes any sense. Drop me an email (aw452@cam.ac.uk) if you're up for it.

Cheers,

Ansgar Walther

26 Feb 2010 Marcelo Perlin

Hi Ansgar,
My replies by email.

M. P.

09 Mar 2010 Jorge

Excelent! I would like to combine TVP Models with Regime Switching as Kim y Nelson, have you any model like this?

10 Mar 2010 Marcelo Perlin

Hi Jorge,

Sorry but no, I don't have the code for regime switching time varying parameter model.

Regards.

21 May 2010 Flavio

Marcelo, congratulations for your job in this package, it's the best markov switching program I saw so far!

However, I just can't find the package "fMarkovSwitching" you mentioned, it seems that it isn't available anymore in Rmetrics and in CRAN. I think it's a great lost for the R community.

Could you remake the package for the new R version and make it available ???

Thank you very much, It would be a great thing to have your package available for R.

21 May 2010 Marcelo Perlin

Hi Flavio,
Tahnks for your comments, really apreciate it.

The fMarkovSwitching is still there, but the command:

install.packages("fMarkovSwitching", repos="http://R-Forge.R-project.org")

is somehow not working for any of the packages in rmetrics.
For instanlling it, dowload the source file from:

https://r-forge.r-project.org/R/?group_id=156

and go to R and install it from local source (the file you download).

Regarding making it available for new version of R, this is not from lack of will, but because the optimizer I use in the estimation (rdnlop2) is not compatible with R>2.8.

Regards,
Marcelo.

24 May 2010 Flavio

Thank you for your reply!

But I install R 2.7.1 and try to install the package "fmarkovswitching" from the zip file you gave a link of, however i couldn't install it. It appears the following message:
"Warning in install.packages(choose.files("", filters = Filters[c("zip", : 'lib = "C:/PROGRA~2/R_2.7/R-27~1.1/library"' is not writable"

Is there any chance you change the optimizer you utilize in order to make it compatible with the new version?

At last, do you know any package or software that can do a 3 BAND-SETAR ?

Thanks again.

25 May 2010 Marcelo Perlin

Hi Flavio,

Somethign is wrogn with your installation of R. I tried it here and it worked fine for R 2.8.1:

> utils:::menuInstallLocal()
package 'fMarkovSwitching' successfully unpacked and MD5 sums checked
updating HTML package descriptions

Regarding making it compatible for newer versions, I tried it in the past by working in the optimization fucntion, but the problem is that it is not writen in R native code, so this makes it difficult.

Regarding setar models, no, I'm not aware of any available package.

Regards,
Marcelo.

25 May 2010 Flavio

Now I tried with R 2.8.1 version and it works.
Thank you very much.
I hope you keep making so useful and smart packages like this!
Regards.

28 May 2010 Muneer

Hi,

Thanks for the package, it looks grreat! Is it possible to do a simple MS-ARMA or ARIMA with this? I'm a little new to matlab so sorry if the answer is obvious!

Also, are there any nice simple clean commands to do forecasting, or do I need to forecast manually? I couldnt see any examples using forecasting in the pdf.

Thanks again for a great package!

28 May 2010 Marcelo Perlin

Hi Munner,

No, MS ARMA models are not supported, but MS AR models are.
I'll keep it in mind for introducing MA terms in upcoming new version.

Regarding forecasting, I'm working on a new forecasting function as we speak. Should be up in a few days.

Regards,
Marcelo.

28 May 2010 Muneer

Hi Marcelo,

Thanks for the prompt reply! Glad to hear it is still being worked on and look forward to the update!

You wouldn't happen to know of any MS models that can handle MA terms would you? :)

Thanks for the great work!
Muneer

28 May 2010 Marcelo Perlin

Hi Muneer,
No, I'm not aware of any software that can handle this type of specifications.
Perhaps you should contact the authors of the paper on MS-ARMA models. They might give you the code if you're convincing enough..

Cheers.

07 Jul 2010 Salman

Excellent package...indeed a great service to matlab users

09 Jul 2010 Salman

Would you be going foe VECM as well?

09 Jul 2010 Marcelo Perlin

Hi Salman,

I have a greater plan of designing a proper interface for time series MS models which should include support for VECM specificatinos.

But, this is not in my short term agenda. Time is scarse this days and I don't know when I'll have the time for developing it.

Marcelo.

25 Aug 2010 Wei

Thanks for providing this excellent package. It has been a starting point of my research.

26 Aug 2010 Alex Nikolov

Marcelo, I would like first to thank you for the incredible package. I have a few questions though. I'm trying to generate a univariate two-state Markov regime switching process, where the series has a regime-dependent mean and regime-dependent variance. I set stock market returns in the first column of the input file (dependent variable), but I am not sure what should I set in the other columns of the input file? And can you tell me what should I give as input to the S in order to get what I have described above. Probably S = [1 1 1 1]? Thank you in advance for your help.

07 Sep 2010 Alex Nikolov

Hi Marcelo. I'm sorry for the stupid questions, I figured them out myself. I just wanted to express my gratitude once again. The package just rocks!!!

07 Sep 2010 Marcelo Perlin

Hi Alex.

I'm glad it all worked out.

All the best,
Marcelo.

07 Oct 2010 luching

Hi Marcelo,

I am trying to estimate a structural VAR where both the coefficients and Var-Cov matrix are regime dependent. It looks like MS_VAR_fit always assumes that the reduced form error terms are independent of each other. Are there options that relax this assumption to allow for a more general Var-Cov matrix with non-zeros for the off-diagonal elements?

Luching.

12 Oct 2010 Marcelo Perlin

Hi Luching,

There is a option in the algorithm for using a full covariance matrix in the estimation. Just use:

advOpt.diagCovMat=0;

meaning that you dont want a diagonal covariance matrix.

Cheers.
Marcelo.

22 Oct 2010 ss4johnny Hall

In my experience the full covariance matrix estimation was quite slow, especially as the covariance matrix got bigger.

Anyway, is there any way to do a weighted markov regime-switching regression? For instance, if I have S&P500 data going back to 1929 and want to exponentially weight it so that the earlier data is less important.

Thanks

26 Oct 2010 Marcelo Perlin

Hi Johnny,

Yes, it is natural that the algorithm is slower for a high number of equations in the system.

Regarding the smoothing, no, the package does not have a support for such procedure.

Regards,
Marcelo.

02 Nov 2010 luching

Hi Marcelo,

I think with large no. of variables and/or lags, "MS_Regress_Fit_MSVAR" as expected does not really give precise estimates. I am trying to circumvent this problem by imposing certain restrictions on the coefficients, but NOT on the variance covariance matrix of the VAR. I see that "MS_Regress_Fit_MultiVar" on the other hand always imposes a diagonal variance covariance matrix. Is there a straightforward approach to resolve this?

Luching.

03 Nov 2010 Marcelo Perlin

Hi Luching,

There is an option in MS_VAR_Fit for estimating the non diagonal elements of the covariance matrix. For the mentioned script, change line 15 to :

advOpt.diagCovMat=0;

Regards,
Marcelo.

03 Nov 2010 luching

So, I was wondering if there is any way either using "MS_Regress_Fit_MultiVar" OR "MS_VAR_Fit" where I can have both features:
(1) non-diagonal elements on the var-cov
(2) restrictions on the coefficients, say for instance I want some coefficients not to be regime dependent.

03 Nov 2010 Marcelo Perlin

Yes, it is possible because the main function MS_Regress_Fit has support for such. Have a look inside MS_VAR_Fit and you'll see that it just builds the lagged variables and pass the options and data to MS_Regress_Fit.

In order to place the constraints, which by way, have to be scalar values (e.g. beta_1=0) and not intervals (e.g. beta_1>0), you'll just have to implement the option structure inside MS_VAR_Fit.

Regards,
Marcelo.

25 Jan 2011 Ajax

Hi Macelo,

I'm wondering why in "MS_Regress_Fit_MultiVar.m" when I impose a diagonal matrix (advOpt.diagCovMat=0) I'm receiving errors like:"input to SVD must not contain NaN or Inf".

Many Thanks
Apostolos

17 Mar 2011 Djibril TOGOLA

Hi Marcelo,
I was very happy to see your code is referenced by hamilton (http://dss.ucsd.edu/~jhamilto/software.htm). So you have my best congratulations !
nevertheless it would be good to provide more details about your implementation process. It is easy to use your programs but difficult to know why you have created some functions and why you use them into some loops. So according to me more comments is all you need to be perfect.

Thank you so much !!!

Best regards,

Djibril

17 Mar 2011 Marcelo Perlin

Hi Djibril,

Thanks for the rating.

Regarding the programming, the package became quite complex with the additional functionalities I implemented such as constrained estimation and multivariate models.

There are comments in the code, but I understand that these are not exactly helpful. I'll keep it in mind for the next update.

Regards,
Marcelo.

28 Mar 2011 Zack

Thanks for the code,

could you please tell me what the conditionnal Std from the output graph is supposed to be
is that from a GARCH model?

28 Mar 2011 Marcelo Perlin

Hi Zack,

The output in the plot is the standard deviation conditional on the states of the world. No, it is not from a garch model.

Marcelo.

29 Mar 2011 Shichang  
29 Mar 2011 Fuzhi Cheng

Thank you very much for the code. Would you please advise (through an example) how to use this model to set up a trading rule and show how the trading results are (in terms of P/L, Sharpe ratio, etc) as compared to a random walk or other models?
Regards,
Fuzhi

29 Mar 2011 Marcelo Perlin

Hi Fuzhi,

Thanks for the rating. You can find information about using ms models in a trading enviroment in the web. For example, have a look in this paper:

http://ideas.repec.org/a/eee/jbfina/v31y2007i2p279-296.html

Cheers,
Marcelo.

30 Mar 2011 Zack

Hi Marcelo

Could you please give me the methode to calculate this conditionnal std deviation

Thanks a lot

30 Mar 2011 Marcelo Perlin

Hi Zack, you can find this information in the references (see pdf file).

Cheers.
Marcelo.

30 Mar 2011 Zack

thanks

30 Mar 2011 Fuzhi Cheng

Obrigado Marcelo!

10 May 2011 Grigoras Veaceslav

Hi Marcelo.
I was wondering if it is possible to do an impulse response analysis with MSVAR in this package.

10 May 2011 Marcelo Perlin

Hi Grigoras,

Yes, it is possible since all estimated parameters are available to the user.

But this as well as others diagnostic procedures are not included in the package.

Marcelo.

27 May 2011 Sverrir

Dear Marcelo

Thank you for pstoing your code, it is working really well!

I'm however having a slight problem regarding the covariance matrix.
Why in "MS_Regress_Fit_MultiVar.m" when I impose "advOpt.diagCovMat=0" I receive the following error:"input to SVD must not contain NaN or Inf".

Best regards
Sverrir

05 Jun 2011 Marcelo Perlin

Hi Sverrir,

Sorry for the (very) late reply. I have been working on different things and time is scarse these days...

The error you got can be the combination of many thigns. Basically it says that the optimizer got stuck in a part of the log likelihood function and could not get out on its own. This can be the result of:

- bad starting coefficients
- data badly shaped (e.g. outliers)

So, my suggestion for you would be to check the data you are running the code.

Regards,
Marcelo.

25 Jun 2011 Giancarlo

Thanks!

28 Jun 2011 Marie Bunckenburg

Dear Marcelo,

First of all, thank you for posting your code.

I am very new in Matlab so I hope the question is ok.

I am trying to estimate a markov switching model to detect shift-contagion in financial markets.
Using your framework, is it possible to:
a) Decompose the errors into common and idiosyncratic structural shocks in order to test for cantagion
b) ensure that the timing of changes in volatility is endogenously estimated

My model draws on Gravelle, Kichian and Morley (2006).

Best regards,
Marie Louise

01 Jul 2011 Marcelo Perlin

Hi Marie,

Sorry for the late reply.

I'm not familiar with the methodology, but if you can send me the equations of the model in pdf by email, I promiss to have a look.

Regards,
Marcelo.

07 Jul 2011 Thorsten Schmidt

Marcelo,
I'm very excited about the prospect of using fMarkovSwitching for R.

I have installed it for R 2.8.1, unfortunately I can't run the package as I get "Error: package 'Rdonlp2' could not be loaded."

It seems that Rdonlp2 is no longer available for download at http://arumat.net/Rdonlp2/
due to some licensing issues between Rdonlp2 and DONLP2.

Do you have any recommendations as to what to do in this case...would fMarkovSwitching work with any other optimizers?
Rgds,
Thorsten Schmidt

07 Jul 2011 Marcelo Perlin

Replied by email.

Cheers.

15 Jul 2011 Maria Sole

Hi Marcelo.
Thanks for this code, it is very useful. By the way, I would like to know if it is possible to introduce some identification assumption concerning the errors (hence if I can run an MS SVAR).
Moreover, I would like to ask you why, whenever I try to use a full VarCov Matrix, I get this error for every type of data I may use:"input to SVD must not contain NaN or Inf".
Thanks,
Best
Maria Sole Pagliari

15 Jul 2011 Marcelo Perlin

Hi Maria,

From the pdf file you can find a section on this error. Basically the problem is with the optimizaer. One simple solution I have seen to work is to divide the dependent variable by 100.

Regarding imposing identification, it is not possible unless you know the values beforehand.

Regards,
Marcelo.

15 Jul 2011 Maria Sole

I tried to adopt that solution, but it keeps on giving me the same error. I think that this depends upon the type of data I'm using actually. Furthermore I noticed that if I use 4 variables in the model, the process simply gets stuck at a certain point and the optimization process simply stops without producing any output or error...

07 Aug 2011 Rendi Prasetya

I tried to adopth this code for regime switching with chartist and fundamental model. like as at stefan reitz paper titled "central bank intervention and exchange rate expectations - evidence from the daily DM/US Dollar exchange rate". can you help me to use your code in that problem.

19 Aug 2011 Jiaqi Zhu

It is of great help to me! Thank you a lot!

01 Sep 2011 Gilbert

Hi Marcelo,
I am using your package to estimate a bivariate model. However, I use returns which are not normally distributed so I think I need to use t-distribution. Do you plan an update for the multivariate case with non-normal errors soon? Is there a modification I could make to use a different distribution for the multivariate case?
Thanks,
Gilbert.

02 Sep 2011 Marcelo Perlin

Hi Gilbert,

Sorry but no plans for a multivariate t distribution so far.

If you are going to implement it, all you need to do place the new likelihood function for the mv t distribution in the code and also add the new parameters in the estimation process. The first part is trivial, the second will require some good coding skills.

Marcelo.

02 Sep 2011 Gilbert

Hi Marcelo,
Thanks, will attempt to make the changes and see what happens. If I succeed, I will let you know so you can check if I did it correctly.
Once again thanks. Great program.
Gilbert.

02 Sep 2011 Marcelo Perlin

Glad to help"

Btw, you can always check if the new code is working by comparing the results against simulated data. That is, simulate a bivariate process with t-dist innovations, fit with with the new function and check whether the parameters from the simulation and estimation match.

Regards,
Marcelo.

23 Sep 2011 ss4johnny Hall

Marcelo,
I just ran across a paper by Gatumel and Ielpo called "The Number of Regimes Across Asset Returns: Identification and Economic Value". They use a rather simple test statistic to identify the number of regimes. Might be something simple to add to the program.

28 Sep 2011 Marcelo Perlin

Thanks Johnny, I'll keep it in mind for future releases.

Cheers.

02 Nov 2011 yuxia zhang  
03 Jan 2012 Tim Kenyon

Hi,

I have the same problem as Thorsten Schmidt above regarding DONLP2 for the fMarkovSwitching program in R. Is there any way around this problem?

Thanks,

Tim

06 Jan 2012 Marcelo Perlin

Hi Tim,

I made an update to the package a while ago. I just tested it with R 2.14.2 and it is working fine.

Best,
Marcelo.

Please login to add a comment or rating.
Updates
30 Aug 2007

* Fixed Description and organized the m files in folders

19 Sep 2007

* Added simulation and forecasting functions and scripts

08 Oct 2007

* Changed output format of transition Matrix

05 Nov 2007

Fixed small bug with MS_AR_FOR.m (I changed the probabilities name at Spec struct and forgot to also change it at MS_AR_FOR.m)

21 Nov 2007

* Added choice of distribution for estimation (normal or t) with example scripts. * Added a pdf document (details at summary). * added calculation of conditional mean and conditional std at output

26 Nov 2007

* Fixed gramatical errors at description

16 Jan 2008

* Fixed a Bug at MS_Regress_For (thanks Mr. Panagiotis Papanastasiou-Ballis). * Added a spreadsheet with different outputs from different matlab versions

16 Jan 2008

Change in description of the submission and inclusion of data (and script) for Professor's Hardy MS spreadsheet (more detais at description)

21 Jan 2008

Added calculation of standard errors by White (1984) and Newey and West (1987) and also changed a lot of the inputs structure (check the new example files).

05 Mar 2008

Fixed some grammatical errors at pdf documentation and also fixed small bug at calculation of smoothed (and not filtered) probabilities

21 Apr 2008

Fixed some name clashes with the other ms package. Changed a couple of other things, nothing special.

29 Apr 2008

Implemented mex version of hamilton's filter. The gain in speed is quite impressive (5x-8x times the original version). For instructions of how to use it, please check pdf documentation.

09 Jun 2008

Fixed but at standard error calculation. Thanks Axel Gro

22 Jul 2008

Added a few for features and fixed major bug at calculation of standard errors. All merits to Steve Guo for finding and fixing it. Thanks for the code you sended, they were of great help.

25 Jul 2008

Resend the files (last update didnt went through)

05 Aug 2008

Fixed the code for cases where a very small transition probability led the partial derivatives to zero. This means no more NaN values at the standard errors.

07 Aug 2008

fixed small mistake at the display of results

29 Sep 2008

Added the p values of coefficients in the output

09 Nov 2008

Changed a few things in pdf file, along with output to screen format of transition matrix.

15 Dec 2008

Small change at description (link to R version of package)

25 Feb 2009

* Added GED Distribution in MS_Regress_fit.m. * Added the flexibility of choosing wheter distribution parameters will switch state or not.

25 Feb 2009

* added GED distribution to MS_regress_fit, * Added the possibility of choosing if distribution parameters will switch or not.

23 Mar 2009

Added the possibility of contrained estimation (see pdf for details)

07 Apr 2009

Changed Description of Package.

16 Apr 2009

Fixed bug on MS_Regress_Fit

03 May 2009

Increased the robustness of the estimation function regarding different scales of variables. Changed a few things in manual and FEX description.

28 May 2009

fix in reference link

04 Jun 2009

Added a section in the Manual (and scripts) for estimating Hamilton's model

11 Jun 2009

Fixed small typo in MS_Regress_Fot and added a few things in manual.

13 Jun 2009

Fixed another typo due to update in notation

21 Jun 2009

A couple of improvements in Manual.

27 Oct 2009

Added support for multivariate models and autoregressive specifications, including MS VAR. See pdf for details.

31 Jan 2010

Fixed bug for the cases where simulation model only had switching variables. Included a missing script for comparison against hamilton's model.

01 Feb 2010

Fixed cases where there was an error for a simulation model with no non switching parameters (see comments by Aaron). Added a couple of more things in input checking.

20 Mar 2010

* Changed all example .mat data files to .txt format. * added p values in output structure * added more error checks for constrained estimation inputs.

28 May 2010

Update on forecasting function for new algorithm structure.

04 Jun 2010

Fixed typo in manual.

18 Jul 2010

Changed method for calculation of small change in numerical approximation of partial derivatives (standard error calculation).

19 Nov 2010

Fixed bug for when adding constraints with the t (and GED) distribution.

19 Nov 2010

Implemented better solution to previous bug.

24 Nov 2010

Added MS_Regress paper to zip file (and SSRN link in description)

28 Jan 2011

Long due update in the package (many thanks for all the people that emailed me). * Added option for intercept in VAR estimation. * Many other changes

01 Mar 2011

Update in pdf.

17 Mar 2011

Fixed bug in screen output of MSVAR models. This bug only happened when intercept=1.

09 Jun 2011

Fixed bug in example script for MS_Regress_For.

15 Jun 2011

Update in pdf manual.

03 Aug 2011

Fixed bug in MS_Regress_For.m in the cases of multivariate models.

17 Aug 2011

Update in manual.

Tag Activity for this File
Tag Applied By Date/Time
finance Marcelo Perlin 22 Oct 2008 09:21:33
modeling Marcelo Perlin 22 Oct 2008 09:21:33
analysis Marcelo Perlin 22 Oct 2008 09:21:33
econometrics Marcelo Perlin 22 Oct 2008 09:21:33
regression Marcelo Perlin 22 Oct 2008 09:21:33
markov switching Marcelo Perlin 22 Oct 2008 09:21:33
statistics Marcelo Perlin 09 Nov 2008 19:50:04
optimization Marcelo Perlin 09 Nov 2008 19:50:04
optimization Cristina McIntire 10 Nov 2008 10:29:48
statistics Cristina McIntire 10 Nov 2008 10:29:51
analysis Cristina McIntire 10 Nov 2008 10:30:38
modeling Cristina McIntire 10 Nov 2008 10:30:41
regression Rodolphe Sitter 07 Dec 2008 10:16:54
econometrics Kihyun Park 23 Jun 2009 12:12:39
finance jhgespinosa@gmail.com GOMEZ ESPINOSA 02 Jul 2009 10:22:37
markov switching gajd 07 Aug 2009 06:26:53
markov switching Elvis Casco 25 Aug 2009 13:42:38
statistics Paul Brown 30 Nov 2009 09:01:34
econometrics John Valica 22 Feb 2010 14:51:25
markov switching Maxim 05 May 2010 04:31:48
vecm Salman 09 Jul 2010 11:30:46
markov switching fei yejun 01 Dec 2010 02:07:34
potw Lindsay Coutinho 25 Feb 2011 10:37:26
pick of the week Lindsay Coutinho 25 Feb 2011 10:37:26
analysis Giorgio Foresti 28 Feb 2011 09:11:20
econometrics Giorgio Foresti 28 Feb 2011 09:11:25
markov switching Patrick Anderson 01 Mar 2011 20:14:12
optimization James Chang 30 Jan 2012 16:48:01

Contact us at files@mathworks.com