* * Martin, Hurn and Harris, "Econometric Modelling with Time Series" * Application 20.7.1, from pp 798-9 * DCC and DECO GARCH models * open data daily_finance.mat data(format=matlab,nolabels,sheet="yields") 1 1659 r1 r2 r3 r4 r5 r6 r7 \$ r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 \$ r26 r27 r28 r29 r30 * * Their model is estimated using de-meaned first differenced data, so * there is no mean in the GARCH instruction. * dofor s = 1 5 10 15 20 set %s("dr"+s) = 100.0*(%s("r"+s)-%s("r"+s){1}) diff(center) %s("dr"+s) / %s("cdr"+s) end do s * * CC estimates * garch(p=1,q=1,nomean,mv=cc) / cdr1 cdr5 cdr10 cdr15 cdr20 * * DCC estimates * garch(p=1,q=1,nomean,mv=dcc) / cdr1 cdr5 cdr10 cdr15 cdr20 * * DECO estimates (two step) * compute n=5 dec series[symm] uu dec vect[series] hs(n) * dec vect[series] eps(n) dec vect[series] x(n) * set x(1) = cdr1 set x(2) = cdr5 set x(3) = cdr10 set x(4) = cdr15 set x(5) = cdr20 * * Do univariate GARCH models. Save the variances into hs(i) and the * standardized residuals into eps(i). Copy the coefficients into the * proper slots in the full beta matrix. * do i=1,n garch(p=1,q=1,nomean,resids=r,hseries=hs(i)) / x(i) set eps(i) = r/sqrt(hs(i)) end do i * * Compute the covariance matrix of the standardized residuals. * vcv(matrix=rr,nocenter,noprint) # eps * * When "dotted" with a correlation matrix, the <> matrix will * compute the average of the pairwise correlations. * dec symm summer(n,n) ewise summer(i,j)=1.0/(n*(n-1))*(i<>j) * * Create a series for the sequential estimates of rho. This is * initialized to an estimate of rho given the full data set. (Not really * necessary to do the latter). * compute rhox=%dot(summer,%cvtocorr(rr)) set rho = rhox * * Set the target matrix to the equicorrelated estimate using the full * sample. * ewise rr(i,j)=%if(i==j,1.0,rhox) * * Create the series[symm] ee (outer product of standardized residuals). * Initialize the pre-sample value as its unconditional covariance matrix. * dec series[symm] ee q gset ee %regstart() %regend() = %outerxx(%xt(eps,t)) gset ee 1 %regstart()-1 = rr gset q = rr * * Compute the sums across i at t needed later * set sumsq = %sum(%xt(eps,t).^2) set sqsum = %sum(%xt(eps,t))^2 * * Log likelihood for the DECO phase, taking the standardized residuals * as given. * nonlin a b dec frml[symm] qf frml qf = (qx=(1-a-b)*rr+a*ee{1}+b*q{1}) frml logl = q=qf,rho=%dot(summer,%cvtocorr(qx)),hx=%xt(hs,t),-.5*(\$ n*log(2*%pi)+%sum(%log(hx))+(n-1)*log(1-rho)+log(1+(n-1)*rho)+\$ 1.0/(1-rho)*(sumsq-rho/(1+(n-1)*rho)*sqsum)) compute b=.80,a=.10 maximize logl 2 * * * One step (full information) DECO * * Individual GARCH model parameters, initialized to the univariate * estimates. * dec vect[series] u(n) dec vect[vect] g(n) do i=1,n garch(p=1,q=1,nomean) / x(i) compute g(i)=%beta set u(i) = %resids end do i * * Initialize pre-sample values for UU and HS * vcv(noprint) # u gset uu 1 %regend() = %sigma do i=1,n set hs(i) 1 n = uu(t)(i,i) end do i * function DECOUpdate t type vector DECOUpdate type integer t * local integer i * do i=1,n * * This model has no mean model, so the residual is just the dependent * variable. Define the diagonals of HH, the * compute u(i)(t)=x(i)(t) compute hs(i)(t)=g(i)(1)+g(i)(2)*uu(t-1)(i,i)+g(i)(3)*hs(i)(t-1) compute eps(i)(t)=u(i)(t)/sqrt(hs(i)(t)) end do i compute ee(t)=%outerxx(%xt(eps,t)) compute uu(t)=%outerxx(%xt(u,t)) compute sumsq(t)=%sum(%xt(eps,t).^2) compute sqsum(t)=%sum(%xt(eps,t))^2 compute DECOUpdate=%xt(hs,t) end * frml logl = q=qf,rho=%dot(summer,%cvtocorr(qx)),hx=DECOUpdate(t),-.5*(\$ n*log(2*%pi)+%sum(%log(hx))+(n-1)*log(1-rho)+log(1+(n-1)*rho)+\$ 1.0/(1-rho)*(sumsq-rho/(1+(n-1)*rho)*sqsum)) nonlin(parmset=decoparms) a b compute b=.80,a=.10 nonlin(parmset=uniparms) g * nlpar(derive=second) maximize(parmset=decoparms+uniparms,pmethod=simplex,piters=5,iters=500) logl 2 *