MS-XGARCH-M

Discussions of ARCH, GARCH, and related models
yanne1224
Posts: 2
Joined: Wed Jul 18, 2012 3:33 am

MS-XGARCH-M

Unread post by yanne1224 »

Hello everyone,

I am programing a Markov switching XGARCH in mean right now, but i have three questions:

first, how can i add a std.variance in the mean equation;

second, can anyone tell me that is there any criterion on how to add an exogenous variable in the variance equation;

third, how can we realise the forecast with this kind of models, it is rather hard, i am just at the end of my capacity :( .

Any suggestions will be welcomed!

Thanks a lot.

yansong :)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: MS-XGARCH-M

Unread post by TomDoan »

Have you tried estimating an XGARCH-M model without the MS first? Have you tried estimating an MS-GARCH model without the X and the M? Until you've done those, you really shouldn't be trying to do a full bells and whistles model. Markov Switching GARCH models are extremely hard to make work successfully.
yanne1224
Posts: 2
Joined: Wed Jul 18, 2012 3:33 am

Re: MS-XGARCH-M

Unread post by yanne1224 »

Hello TomDoan,

Thanks for your suggestions. But in fact, i have indeed done what you've said.

I have successfully create a MS-GARCH with two regimes, thanks to your code written in 2005 for M.Gray's paper.

And, I know how to create a X-GARCH in mean, but i don't know how to add a std. variance.

I don't need to hide, yes, my knowledge in writing the program with rats is rather poor, and i am eager to learn that in the next school year.

So can you guide me to finish this model? :)

sincerely

yansong

Code: Select all

  MSGARCH
******************   linreg********
linreg(robust) y
# constant y{1} y{3}
***********************
compute olsvar=%seesq
compute olsbeta=%beta
**************************
*****************************
source markov.src
compute nstates=2
********************
dec rect p(nstates-1,nstates)
********************
dec vect pstar(nstates)

dec series[vect] pt_t pt_t1 psmooth
gset pt_t 1 3328 = %zeros(nstates,1)
gset pt_t1 1 3328 = %zeros(nstates,1)
gset psmooth 1 3328 = %zeros(nstates,1)

************************************SWGARCH(2,1,1)***********************************
garch(p=1,q=1,reg,resids=u,hseries=h) / y
# constant y{1} y{3}
compute onestate=%beta

*********************************************************************
set ustd = u/sqrt(h)
set ustdsq = ustd^2
@regcorrs(qstat,number=40,dfc=1,title="GARCH-LB Test") ustd
@regcorrs(qstat,number=40,dfc=2,title="GARCH-McLeod_Li Test") ustdsq
*
* Regime-switching GARCH
*
nonlin a01 a02 a03 a11 a12 a13 b01 b02 b03 b11 b12 b13 p
compute a01=%beta(1),a02=%beta(2),a03=%beta(3),b01=%beta(7),b02=%beta(8),b03=%beta(9)
compute a11=%beta(4),a12=%beta(5),a13=%beta(6),b11=%beta(10),b12=%beta(11),b13=%beta(12)
compute p=||.95,.05||
*
set uu = olsvar
set h  = olsvar
*
* RegimeGARCHF returns the 2 vector of densities in the two states.
* Again, many lines in this are specific to the problem at hand.
*
function RegimeGARCHF t
type vector RegimeGARCHF
type integer t
local real hh1 hh2 mu1 mu2 mu
*
* Compute state dependent variances
*
compute hh1=b01+b02*uu(t-1)+b03*h(t-1)
compute hh2=b11+b12*uu(t-1)+b13*h(t-1)
*
* Compute state dependent means
*
compute mu1=a01+a02*y(t-1)+a03*y(t-3)
compute mu2=a11+a12*y(t-1)+a13*y(t-3)
*
* Compute the return vector (densities in the two states)
*
compute RegimeGARCHF=||%density((y(t)-mu1)/sqrt(hh1))/sqrt(hh1),$
                       %density((y(t)-mu2)/sqrt(hh2))/sqrt(hh2)||
*
* Compute the values of uu (squared residual) and h (variance) to be
* used for the period following
*
compute mu=mu1*pstar(1)+mu2*pstar(2)
compute uu(t)=(y(t)-mu)^2
compute h(t)=pstar(1)*(mu1^2+hh1)+pstar(2)*(mu2^2+hh2)-mu^2
end
*
frml logl = f=RegimeGARCHF(t),$
    pt_t1=%mcstate(p,pstar),pt_t=pstar=%msupdate(f,pt_t1,fpt),log(fpt)
*
* This combination is able to locate Gray's results - the first MAXIMIZE
* works with the "p" matrix fixed at a fairly high level of persistence,
* and tries to get estimates which separate the two states. The second
* then adds the p matrix to the parmset.
*
nonlin a01 a02 a03 a11 a12 a13 b01 b02 b03 b11 b12 b13
maximize(start=(pstar=%mcergodic(p)),method=bfgs,iters=100,piters=10) logl 5 *
nonlin a01 a02 a03 a11 a12 a13 b01 b02 b03 b11 b12 b13 p
maximize(start=(pstar=%mcergodic(p)),method=bfgs,iters=100,piters=10) logl 5 *
********************************************which doesn't work*******************************************
compute a01=%beta(1),a02=%beta(2),a03=%beta(3),b01=%beta(7),$
b02=%beta(8),b03=%beta(9),a11=%beta(4),a12=%beta(5),a13=%beta(6),$
b11=%beta(10),b12=%beta(11),b13=%beta(12)
compute p=||.9576,.11||

frml hfrml ht = pstar(1)*((a01+a02*y(1)+a03*y(3))^2+b01+b02*uu(1)+b03*h(1))+$
                        pstar(2)*((a11+a12*y(1)+a13*y(3))^2+b11+b12*uu(1)+b13*h(1))-$
                        (pstar(1)*(a01+a02*y(1)+a03*y(3))+pstar(2)*(a11+a12*y(1)+a13*y(3)))
frml uufrml uu = ht
group garchmod hfrml>>ht uufrml>>uu

uforeerror(model=garchmod) yfore y 1 2489

simulate(from=2489,to=3328,model=garchmod)  yfore
set  yfore 1 2489 = y

graph(footer="Forecasts of spread",key=upl,klabels=||"spreadestime","spreal reel"||) 2
# yfore 1 3328
# y
************************************************************************************
@%mssmooth p pt_t pt_t1 psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
spgraph(vfields=3,samesize)
graph(style=line,maximum=1.0,picture="##.##",header="Smoothed Probabilities of Variance States",$
  key=upl,klabels=||"Low Variance"||) 1
# p1
graph(style=line,maximum=1.0,picture="##.##",header="Smoothed Probabilities of Variance States",$
  key=upl,klabels=||"High Variance"||) 1
# p2
graph(picture="##.##",header="Spread")
# y
spgraph(done)

spgraph(vfields=2,samesize)
graph(style=stacked,maximum=1.0,picture="##.##",header="Smoothed Probabilities of Variance States",$
  key=upl,klabels=||"Low Variance","High Variance"||) 2
# p1
# p2
graph(picture="##.##",header="Spread")
# y
spgraph(done)











Code: Select all

**********************estimation GARCH(1,1)-GJR-M
declare series u h
nonlin a1 a2 a3 b1 b2 b3
frml uf = y - b1*y{1} - b2*y{3} - b3*sqrt(h)
frml hf = (%if(u<0,1,0))*(a0 + a1*u{1}**2 + a2*u**2 + a3*h{1})+$
             %if(u>=0,1,0)* (a0 + a1*u{1}**2 + a3*h{1})

lin(noprint) y
# constant y{1} y{3}
set u = %resids
set h = %seesq
compute b0=%beta(1),b1=.05,b2=.05,b3=.0
compute a0=%seesq(1),a1=.05,a2=.05,a3=-.05
frml garhm = h=hf,u=uf,%logdensity(h,u)
maximize(method=bfgs) garchm 10 *

graph(key=upl,header='variance conditionnelle',subheader='GARCH(1,1)-GJR-M') 1 ; #h
Post Reply