b34sexec options ginclude('b34sdata.mac') macro(dow)$ b34seend$ /$ bhhh method used .. residuals set to 0 for beginning obs /$ /$ user must replace gasout with user series name /$ b34sexec options open('rats.dat') unit(28) disp=unknown$ b34srun$ b34sexec options open('rats.in') unit(29) disp=unknown$ b34srun$ b34sexec options clean(28)$ b34srun$ b34sexec options clean(29)$ b34srun$ b34sexec pgmcall$ rats passasts pcomments('* ', '* data passed from b34s(r) system to rats', '* ') $ pgmcards$ * * set seriesn = djones(t) - djones(t-1) set seriesn = djones(t) compute iter = 100,isiter=100 * * arch with ma * * see page 5 31 rats manual * smpl(series=seriesn) set v = 1.0 set ra = 0.0 nonlin b0 b1 b2 mu1 a0 a1 frml regresid = seriesn - b0 - b1*seriesn{1}- b2*seriesn{2} $ + mu1*ra{1} * note: to add more series on the right place added lines before * + mu1 * ra{1} line frml archvar = a0+a1*regresid(t-1)**2 frml archlogl = (v=archvar(t)),(ra(t)=regresid(t)), $ .5*(log(v)+ra(t)**2/v) linreg seriesn # constant seriesn{1} seriesn{2} compute b0=%beta(1),b1=%beta(2),b2=%beta(3) compute a0=%seesq, a1=.05, mu1=0.0 * maximize(method=simplex,recursive,iterations=iter) archlogl 3 * nlpar(subiterations=isiter) maximize(method=bhhh,recursive,iterations=iter) archlogl 3 * smpl(series=ra) statistics ra set rssa = ra(t)*ra(t) statistics rssa smpl(series=rssa) compute sumsqra = %sum(rssa) display 'sum of squares of ra' sumsqra * * Modern code * * set seriesn = djones(t) - djones(t-1) set seriesn = djones(t) compute iter = 100,isiter=100 * * garch(1,1) * * see pages 206-211 of Version 6 Reference Manual * * garch(p=1,q=1,resids=at,hseries=fvar,regressors) / seriesn # constant seriesn{1} seriesn{2} graph(header="Residuals of Model") 1 # at ; graph(header="Conditional Volatility of Model") 1 # fvar b34sreturn$ b34srun$ b34sexec options close(28)$ b34srun$ b34sexec options close(29)$ b34srun$ b34sexec options dodos('start /w /r rats32s rats.in /run') dounix('rats rats.in rats.out')$ B34SRUN$ b34sexec options npageout writeout('Output from Rats',' ',' ') copyfout('rats.out') dodos('erase rats.in','erase rats.out','erase rats.dat') dounix('rm rats.in','rm rats.out','rm rats.dat') $ b34srun$ /$ /$ Joint GARCH Estimation using GARCHEST Subroutine b34sexec matrix ; call loaddata; djones=dif(djones); arch=array(norows(djones):)+variance(djones); call garchest(res,arch,djones,func,2,n :maxit 8000 :maxfun 8000 :maxg 8000 :steptol .1e-10 :nma 2 :ngma 1 :print ); call graph(goodrow(res)); call graph(goodrow(arch)); arch=array(norows(djones):)+variance(djones); call garchest(res,arch,djones,func,2,n :maxit 8000 :maxfun 8000 :maxg 8000 :steptol .1e-10 :nar 2 :ngma 1 :print ); call graph(goodrow(res)); call graph(goodrow(arch)); /; this fails !!! arch=array(norows(djones):)+variance(djones); call garchest(res,arch,djones,func,1,n :maxit 8000 :maxfun 8000 :maxg 8000 :steptol .1e-10 :nma 1 :ngma 1 :ngar 1 :print ); call graph(goodrow(res)); call graph(goodrow(arch)); /; call tabulate(%resobs,res,arch); call names; b34srun;