Updated MRS-GARCH Matlab code (January 2011)
Many people and students have emailed me asking about a revised version of the two main Matlab programs used in my paper "Forecasting Stock Market Volatility with Regime-Switching GARCH Models" by J. Marcucci (Studies in Nonlinear Dynamics and Econometrics, 2005). To some I have replied right away, to others I have replied maybe too late. However, to fix all the issues I had to find some time to fix and re-run all the programs with the new versions of Matlab. I hope this updated code will work for everybody. And sorry for being so late in fixing the bugs.
To run the programs you should still get the zip file with data and Matlab code from the "new" SNDE website (http://www.degruyter.com/view/j/snde.2005.9.4/snde.2005.9.4.1145/snde1145_supplementary_1.zip) on the right side of the webpage.If for some reasons that link does not work, you can download the file from here.
There were some issues in the program mrsgarchestfor_con_all.m, especially for the MRS-GARCH models with Student's t distribution. In the new versions that you can download below I fixed the lower and upper bounds for the shape parameter of the t distribution. For some reasons, in the Matlab version I used to compute the results published in my paper the previous bounds worked fine. With the newer versions of Matlab, those bounds were "too close" to 0 and had one tried to run the code she/he would have ended up with an error and a program halt.
In the current updated versions I have fixed these and other minor problems. I have tested both codes (for GARCH models and for MRS-GARCH models) with different versions of Matlab (2008a, 2009a, 2010a) and on different platforms (Windows, Linux/Mac) and they work fine.
Be aware that, to reduce computing times, for the MRS-GARCH model you might want to change max_st_v to have a lower number of starting values and/or change the main loop (line 37)
for errortype = [1 2 4 5];
with for errortype = [k]; where k=(1,2,4,5) to estimate one model at a time.
Updated Matlab main programs:
mrsgarchestfor_con_all.m
garchestfor_con_all.m
Should you have any problems with these updated versions of the code, please let me know.
Old instructions to fix the typos in the MRS-GARCH Matlab code
These are the old instructions for the MRS-GARCH code used in the paper "Forecasting Stock Market Volatility with Regime-Switching GARCH Models" by J. Marcucci (Studies in Nonlinear Dynamics and Econometrics, 2005).
Get the code from the SNDE website (http://www.bepress.com/snde/vol9/iss4/art6/) at the bottom left of the webpage. Unfortunately the uploaded programs came out with some typos. Below you can find the instructions to slightly change the main program so that it can give you the results without any errors. Please, consider that I ran the programs with Matlab 6 and if you want to "exactly" replicate my results, some could be slightly different. It already happened to other people/students who tried to exactly replicate the results in my paper.
Things to do to have the programs run fine:
There are a couple of typos in the programs downloadable from the SNDE
website that should be fixed. For some unknown reasons a few lines came up
unnecessarily commented or didn't appear at all. Please, follow these instructions and everything should work just fine:
Replace in the main program the following lines after the fmincon call
[...]
% ADDED THE FOLLOWING 2 LINES FOR STD ERR WITH HESSIAN FROM
% OPTIMIZATION. they were disappeared and I don't know why
stder_HESS = sqrt(diag((HESSIAN)^(-1)));
tstat_HESS = parameters./stder_HESS;
[...]
... after se_rob_hess
[...]
%%%%%%%%%%%%%%%%%%%%%%%%%
% ADDED THE FOLLOWING 3 LINES FOR SE_rob_HESS
A2=(1/T)*HESSIAN;
SE_rob_HESS=sqrt((1/T)*diag((A2^(-1))*B*(A2^(-1)))); % hessian from OPTIMIZATION
tstat_HESS_rob = parameters./SE_rob_HESS; % hessian from calculation
[...]
... after tstats
[...]
tstats = parameters./stderrors;
% Printing everything % COMMENTED THE NEXT 5 LINES. THEY WOULD
WRONGLY SET THE GRAD, STDER AND TSTAT TO [] BEFORE STORING THEM!
%GRAD=[];
%stder_HESS=[];
%SE_rob_HESS=[];
%tstat_HESS=[];
%tstat_HESS_rob=[];
If you don't do that, you can get an error because before storing the values, GRAD and the other values are wrongly set to [].
With these corrections, everything should work. Also, you should change the matrix called Parameters in such a way that it can store vectors with different lengths otherwise you will get another error (the dimension mismatch error). It's sufficient to set the number of columns of Parameters to the maximum number of parameters. After fixing this everything should work. Please, email me if it doesn't.