/* AR-GARCH_t(nu) */ new; cls; phi={0.8,0.1}; a0=0.001; a={0.2,0.1,0.1}; b={0.2,0.1,0.1,0.1}; nu=20; /* ~t(nu) */ n=1000; x=argarch_t(phi,a0,a,b,nu,n); library pgraph; graphset; title("AR-GARCH_t(nu)"); t=seqa(1,1,n); xy(t,x); proc argarch_t(phi,a0,a,b,nu,n); local cutn,p,e,x; cutn=100; /* first some data to cut off */ p=rows(phi); print "AR parameter:"; print/lz "p=" rows(phi); e=garch_t(a0,a,b,nu,cutn+n); /* Now, e~GARCH_t. */ x=zeros(cutn+n,1); t=p+1; do while t<=cutn+n; x[t]=rev(phi)'x[t-p:t-1]+e[t]; t=t+1; endo; x=x[cutn+1:cutn+n]; retp(x); endp; proc garch_t(a0,a,b,nu,n); local cutn,e,s2,q,p,u,h,max,t; if a0<=0; errorlog "ERROR:Parameter a0 must be positive."; retp("."); endif; if not a>=0; errorlog "ERROR:Each element of a must be non negative."; retp("."); endif; if not b>=0; errorlog "ERROR:Each element of b must be non negative."; retp("."); endif; if nu<=0 or (nu-floor(nu))/=0; errorlog "ERROR: Parameter nu must be positive integer."; retp("."); endif; cutn=100; /* first some data to cut off */ e=cdftci(1-rndu(cutn+n,1),nu); /* Now, e~t(nu). */ s2=a0/(1-sumc(a)-sumc(b)); q=rows(a); p=rows(b); print "GARCH parameter:"; print/lz "q=" q;; print/lz "p=" p; u=zeros(cutn+n,1); h=zeros(cutn+n,1); max=maxc(q|p); u[1:max]=sqrt(s2)*e[1:max]; h[1:max]=s2*ones(max,1); t=max+1; do while t<=cutn+n; h[t]=a0+rev(a)'(u[t-q:t-1]^2)+rev(b)'h[t-p:t-1]; u[t]=sqrt(h[t])*e[t]; t=t+1; endo; u=u[cutn+1:cutn+n]; retp(u); endp;