## Multivariate MS GARCH

Discussion of models with structural breaks or endogenous switching.

### Multivariate MS GARCH

I am trying to develop a CCC bivariate version of Gray's(1996) MS-GARCH with single-regime mean equations for stock returns. I think the general logic of my code is fine, it draws heavily on the Gray(1996) paper replication example. For some reason however, the following error message pops up during the maximisation (the final line of code):
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 196, Line 19 of %MSPROB

I have tried to change the estimation range, but this does not help so far.
The code is as below.
Any help on the possible causes of this error message would be appreciated.

Regards,
Daniel King

Code: Select all
`OPEN DATA "C:\Users\daniel\Desktop\MSCIDaily.xlsx"CALENDAR(D) 2002:6:3DATA(FORMAT=XLSX,ORG=COLUMNS,SHEET="Returns") 2002:06:03 2011:12:30 Nigeria SA Kenya Egypt*Standardise series names for easy changesset y = saset x = egypt*@MSSetup(states=4)*linreg(robust) y# constant y{1}**Store initial parameter values for y  compute olsvar1 = %seesqcompute coeff11 = %beta(1)compute coeff12 = %beta(2)*linreg(robust) x# constant x{1}**Store  initial parameter values for xcompute olsvar2 = %seesqcompute coeff21 = %beta(1)compute coeff22 = %beta(2)** Get some initial values for the MV-GARCH processgarch(p=1,q=1,mv=cc)   /y x***Declare all variables and assign initial values* b(coefficient no.,series) - mean equations;*a(coefficient no., regime, series) and rho – variance equationsnonlin b0y b1y b0x b1x a01y a02y a11y a12y a21y a22y a01x a02x a11x a12x a21x a22x rho1 rho2 pcompute b0y=coeff11, b1y=coeff12, b0x=coeff21, b1x=coeff22compute a01y=%beta(3),a02y=3*%beta(3), a11y=%beta(5), a12y=3*%beta(5), a21y=%beta(7), a22y=3*%beta(7)compute a01x=%beta(4), a02x=3*%beta(4), a11x=%beta(6), a12x=3*%beta(6), a21x=%beta(8), a22x=3*%beta(8)compute rho1=0.5*%beta(9), rho2=2*%beta(9)compute p=||.8,.1,.0,.0|.1,.8,.1,.1|.1,.1,.8,.1||**Assign initial values to squared residuals and conditional variancesset uu1 = olsvar1set uu2 = olsvar2set h1 = olsvar1set h2 = olsvar2*function RegimeGARCHF ttype vector RegimeGARCHFtype integer tlocal real h11 h21 cov1 h12 h22 cov2 muy muxlocal rectangular HH1(2,2) HH2(2,2) HH3(2,2) HH4(2,2)local vector U**Define variance-covariance equations for each series, each regimecompute h11= a01y+a11y*uu1(t-1)+a21y*h1(t-1)compute h12 = a02y+a12y*uu1(t-1)+a22y*h1(t-1)compute h21 = a01x+a11x*uu2(t-1)+a21x*h2(t-1)compute h22 = a02x+a12x*uu2(t-1)+a22x*h2(t-1)compute cov1 = rho1*sqrt(h11)*sqrt(h21)compute cov2 = rho1*sqrt(h11)*sqrt(h22)compute cov3 =rho2*sqrt(h12)*sqrt(h21)compute cov4 =rho2*sqrt(h12)*sqrt(h22)**Define mean equations for each seriescompute muy=b0y+b1y*y(t-1)compute mux=b0x+b1x*x(t-1)**Fill covariance matricescompute HH1 = ||h11, cov1|cov1,h21||compute HH2 = ||h11, cov2|cov2,h22||compute HH3 = ||h12, cov3|cov3,h21||compute HH4 = ||h12, cov4|cov4,h22||**Fill residuals vectorcompute U = ||y(t)-muy,x(t)-mux|| **Fill vector of raw density functionscompute RegimeGARCHF=||exp(%logdensity(HH1,U)), exp(%logdensity(HH2,U)), exp(%logdensity(HH3,U)), exp(%logdensity(HH4,U))||**Update variable valuescompute uu1(t)= (y(t)-muy)^2compute uu2(t)= (x(t)-mux)^2compute h1(t)=(pstar(1)+pstar(2))*(muy^2+h11)+(pstar(3)+pstar(4))*(muy^2+h12)-muy^2compute h2(t)=(pstar(1)+pstar(3))*(mux^2+h21)+(pstar(2)+pstar(4))*(mux^2+h22)-mux^2*endfrml logl = f=RegimeGARCHF(t),fpt=%MSProb(t,f),log(fpt)nonlin b0y b1y b0x b1x a01y a02y a11y a12y a21y a22y a01x a02x a11x a12x a21x a22x rho1 rho2 pmaximize(start=(pstar=%MSInit()),method=bfgs,iters=100) logl %regstart() %regend()`
DanielKing

Posts: 8
Joined: Fri May 25, 2012 9:08 am

### Re: Multivariate MS GARCH

Daniel,

Can you post the data file, or email it to support@estima.com? That would make debugging this easier.

Regards,
Tom Maycock
Estima
moderator

Posts: 306
Joined: Thu Oct 19, 2006 4:33 pm

### Re: Multivariate MS GARCH

Dear Tom,

Apparently the file is too big to be posted, so I will e-mail it.
Thank you for your help.

Regards,
Daniel King
DanielKing

Posts: 8
Joined: Fri May 25, 2012 9:08 am

### Re: Multivariate MS GARCH

Email sent. Looks like the issue was a missing @MSFilterInit call, and an issue with the start period on MAXIMIZE.

Tom Maycock
Estima
moderator

Posts: 306
Joined: Thu Oct 19, 2006 4:33 pm

### Re: Multivariate MS GARCH

DanielKing wrote:I am trying to develop a CCC bivariate version of Gray's(1996) MS-GARCH with single-regime mean equations for stock returns. I think the general logic of my code is fine, it draws heavily on the Gray(1996) paper replication example.

I'm not a fan of Gray's procedure/model. It uses a fairly crude approximation and is too loosely parameterized to give good results. (It's too easy to get both branches being unstable GARCH models). The Dueker approach (http://www.estima.com/forum/viewtopic.php?f=8&t=1190) seems to work better, both because it has a more accurate approximation (waiting longer to collapse the states) and also because it is more tightly parameterized.
TomDoan

Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Multivariate MS GARCH

Thanks for the advice, I will definitely look into it.

In my attempt to build an equivalent Multivariate version of Hamilton and Susmel's SWARCH (as in Ramchand and Susmel, 1998; Edwards and Susmel, 2001, 2003), I have written the code below. However, early on in the maximisation it gives the error message "## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points".

I have changed the estimation range and initial values but cannot see any obvious reason why these are a problem. I am using the same data as above.
Any help is appreciated greatly,

Regards,
Daniel King
Code: Select all
`OPEN DATA "C:\Users\daniel\Desktop\MSCIDaily.xlsx"CALENDAR(D) 2002:6:3DATA(FORMAT=XLSX,ORG=COLUMNS,SHEET="Returns") 2002:06:03 2011:12:30 Nigeria SA Kenya Egypt****set y = saset x = nigeria@MSSetup(lags=1,states=4)*dec rectangular Zdec vect gvy(2)dec vect gvx(2)dec real a1y a1xdec vect rho(2)dec real alphay betay alphax betax*nonlin(parmset=meanparms) alphay betay alphax betaxnonlin(parmset=archparms) a1y gvy a1x gvx rhononlin(parmset=msparms)   thetacompute Z=%zeros(2,2)*clear uuy uy uux uxfunction ARCHRegime time ey extype vector ARCHRegimetype real ey extype integer time*local rectangular HHlocal vector Ulocal integer    ilocal real hy hx vary varx cov*dim ARCHRegime(nexpand)do i=1, nexpand*if %MSLagstate(i,1)==1{compute hy=1+a1y*uuy(time-1)/gvy(1)compute hx=1+a1x*uux(time-1)/gvx(1)compute cov=rho(1)*sqrt(hy)*sqrt(hx)}\$else if %MSLagState(i,1)==2{compute hy=1+a1y*uuy(time-1)/gvy(1)compute hx=1+a1x*uux(time-1)/gvx(2)compute cov=rho(1)*sqrt(hy)*sqrt(hx)}\$else if %MSLagState(i,1)==3{compute hy=1+a1y*uuy(time-1)/gvy(2)compute hx=1+a1x*uux(time-1)/gvx(1)compute cov=rho(2)*sqrt(hy)*sqrt(hx)}\$else {compute hy=1+a1y*uuy(time-1)/gvy(2)compute hx=1+a1x*uux(time-1)/gvx(2)compute cov=rho(2)*sqrt(hy)*sqrt(hx)}end if*if %MSLagstate(i,0)==1{compute vary=hy*gvy(1)compute varx=hx*gvx(1)}\$else if %MSLagState(i,0)==2{compute vary=hy*gvy(1)compute varx=hx*gvx(2)}\$else if %MSLagState(i,0)==3{compute vary=hy*gvy(2)compute varx=hx*gvx(1)}\$else {compute vary=hy*gvy(2)compute varx=hx*gvx(2)}end if*compute HH=||vary, cov|cov,varx||compute U=||ey,ex||**Check that variance terms are positiveif HH(1,1)>Z(1,1){if HH(2,2)>Z(2,2){ARCHRegime(i)= exp(%logdensity(HH,U)}else{ ARCHRegime(i)=0.0}}else{ ARCHRegime(i)=0.0}end ifend do iend*****linreg y# constant y{1}compute alphay=%beta(1),betay=%beta(2)compute gvy=%seesq*||0.2,5.0||compute a1y=0.05set uuy = %seesqset uy  = %residsfrml ufy = y-alphay-betay*y{1}*linreg x# constant x{1}compute alphax=%beta(1),betax=%beta(2)compute gvx=%seesq*||0.2,5.0||compute a1x=0.05set uux = %seesqset ux  = %residsfrml ufxx = x-alphax-betax*x{1}*compute rho=||0.1,0.5||compute p = ||0.8,0.2,0.1,0.0|0.1,0.6,0.2,0.0|0.1,0.1,0.6,0.2||compute theta=%msplogistic(p)***compute gstart=%regstart()+1,gend=%regend()*frml logl = uy(t)=ufy(t),uuy(t)=uy(t)^2, ux(t)=ufxx(t), uux(t)=ux(t)^2, f=ARCHRegime(t,uy(t), ux(t)), fpt=%MSProb(t,f),log(fpt)@MSFilterInitmaximize(parmset=meanparms+archparms+msparms,\$  start=%(p=%mslogisticp(theta),pstar=%MSInit()),\$ method=bfgs,iters=400,pmethod=simplex,piters=5) logl gstart gend`
DanielKing

Posts: 8
Joined: Fri May 25, 2012 9:08 am

### Re: Multivariate MS GARCH

I'm not 100% sure how RATS was interpreting the tangle of {..}'s at the end of your ARCHRegime function, but the following seems to work better:

if HH(1,1)>Z(1,1) {
if HH(2,2)>Z(2,2) {
compute ARCHRegime(i)= exp(%logdensity(HH,U))
}
else {
compute ARCHRegime(i)=0.0
}
}
else {
compute ARCHRegime(i)=0.0
}

though actually that can be simplified still further to

compute ARCHRegime(i)=%if(HH(1,1)>Z(1,1).and.HH(2,2)>Z(2,2),exp(%logdensity(HH,U)),0.0)
TomDoan

Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Multivariate MS GARCH

Thanks very much, the latter if statement does sort out that problem.

However, a new problem has arisen. The maximisation runs as normal for a few minutes, followed by the error message: "## MAT14 Non-invertible matrix. Using Generalised Inverse for Symmetric. The Error occorred at Location 170, Line 13 of %MSINIT", a few hundred times. This is then followed by results in which all the transition probabilities are all highly insignificant.

I have checked that the p matrix is invertible and have experimented with different initial values, but this does not help so far.

Thank you for all the help.

Regards,
Daniel King
DanielKing

Posts: 8
Joined: Fri May 25, 2012 9:08 am

### Re: Multivariate MS GARCH

Your covariance is computed wrong - you're applying the correlation to the "deflated" variances, not to the ones that are reflated by the GV values. The following simplifies and corrects your ARCHRegime function. You also might want to play with your guess values for P a bit. States 1 and 4 aren't as "distant" from each other as they might be if this were an ordered 4 regime model so forcing guesses of 0 probabilities for transitions isn't a good idea.

Code: Select all
`function ARCHRegime time ey extype vector ARCHRegimetype real ey extype integer time*local rectangular HHlocal vector Ulocal integer    ilocal real hy hx vary varx covlocal integer xstate ystate*dim ARCHRegime(nexpand)do i=1,nexpand   *   * Do calculations based upon lagged regime   *   compute xstate=1+(%MSLagState(i,1)==2.or.%MSLagState(i,1)==4)   compute ystate=1+(%MSLagState(i,1)==3.or.%MSLagState(i,1)==4)   *   compute hy=1+a1y*uuy(time-1)/gvy(ystate)   compute hx=1+a1x*uux(time-1)/gvx(xstate)   *   * Do calculations based upon current regime   *   compute xstate=1+(%MSLagState(i,0)==2.or.%MSLagState(i,0)==4)   compute ystate=1+(%MSLagState(i,0)==3.or.%MSLagState(i,0)==4)   compute vary=hy*gvy(ystate)   compute varx=hx*gvx(xstate)   compute cov=rho(ystate)*sqrt(vary)*sqrt(varx)   *   compute HH=||vary, cov|cov,varx||   compute U=||ey,ex||   *   compute ARCHRegime(i)=%if(HH(1,1)>Z(1,1).and.HH(2,2)>Z(2,2),exp(%logdensity(HH,U)),0.0)end do iend`
TomDoan

Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

### Re: Multivariate MS GARCH

Thanks very much for all the help - especially regarding the more elegant characterisation of states. It seems that the model is producing sensible results in general.

For some data sets, the Non-invertible matrix error message arises for particular guess values of the p-matrix. It seems very sensitive to this. Mostly though, a little bit of tinkering leads to results.

Thanks again.

Daniel King
DanielKing

Posts: 8
Joined: Fri May 25, 2012 9:08 am

### Re: Multivariate MS GARCH

DanielKing wrote:Thanks very much for all the help - especially regarding the more elegant characterisation of states. It seems that the model is producing sensible results in general.

For some data sets, the Non-invertible matrix error message arises for particular guess values of the p-matrix. It seems very sensitive to this. Mostly though, a little bit of tinkering leads to results.

Thanks again.

Daniel King

The non-invertible matrix is actually just a warning, and should be occurring only on some of the early function evaluations. Could you post your finished product?
TomDoan

Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Return to Structural Breaks and Switching Models

### Who is online

Users browsing this forum: No registered users and 0 guests