nlpar(subit=200) * * GARCHUV.PRG * * This program is the companion to the article written by * Rob Trevor in the May 1994 RATSletter. It provides full code * for various types of univariate GARCH specifications. The * "regression" part of the model simply allows a non-zero mean. * For a more complex regression, change the "B" parameter list, * the definitions for RESID and the LINREG and initialization * code for the B parameters. * * This uses Y as the dependent variable. If you want to simplify * recoding, just add * * SET Y = your dependent variable * * after doing your data input and transformation. * * You may need to do a bit of fiddling with the METHOD and ITERS * options for MAXIMIZE to get your models to converge. * * The main numerical issue encountered in estimating GARCH models is * convergence of the BHHH algorithm. This is not always obvious from * published work on GARCH models, partly since much of it uses a * convergence criteria based on the R**2 of a regression of a vector of * ones on the scores in the BHHH algorithm. This is equivalent to a * criteria based on the function value only. The default criterion in RATS * is typically more stringent, requiring stabilised parameter values as * well as a stabilized function value. (See the NLPAR instruction.) * * Convergence can be seriously affected by a bad choice of initial values * of the parameters, residuals or covariance matrix. The SIMPLEX algorithm * can be helpful in refining the initial values of the parameters. Initial * values for the residuals can be conveniently generated by a prior * estimation of the conditional mean equation. An estimate of the * unconditional covariance matrix can then be generated by a VCV * instruction applied to these residuals in the case of multivariate * models, or by using the %SEESQ value in univariate cases. This may be * used as an estimate of the initial conditional covariance matrix, * provided behavior at the beginning of the sample period is well * represented by average behavior. Alternatively, if the data are high * frequency, the START option on the MAXIMISE instruction could be helpful. * * Convergence can also be affected if the algorithm strays into an area * where the conditional covariance matrix is no longer positive * semi-definite. (This is more likely to happen with multivariate * specifications.) In such cases the algorithm can be restarted with * different initial values, or a penalty function could be incorporated * into the LOGL function. * * See GARCHMV.PRG for the multivariate GARCH code * * We have not used the %LOGDENSITY function in this code, as the * %LOGDENSITY function in RATS 4.10 does not work correctly for scalars * (It works fine in the matrix case, as in GARCHMV.PRG, where it is * much more valuable anyway). * cal 59 1 4 all 0 84:2 open data glosser.dat data(format=prn,org=obs) SET Y = y1 * * Starting and ending points for GARCH estimation. GSTART must * be at least entry 2. * COMPUTE GSTART=2,GEND=84:2 * * The code for each technique is self-contained. * * * GARCH(1,1) * DECLARE SERIES U ;* Residuals DECLARE SERIES H ;* Variances NONLIN B0 VC VA VB FRML RESID = Y - B0 FRML HF = VC + VA*H{1} + VB*U{1}**2 FRML LOGL = (H(T)=HF(T)),(U(T)=RESID(T)),-.5*(LOG(H(T))+U(T)*U(T)/H(T)) LINREG(NOPRINT) Y / U # CONSTANT COMPUTE B0=%BETA(1) COMPUTE VC=%SEESQ,VA=.05,VB=.05 SET H = %SEESQ MAXIMIZE(METHOD=SIMPLEX,ITERS=5,NOPRINT) LOGL GSTART GEND MAXIMIZE(TRACE,METHOD=BHHH,RECURSIVE,ITERS=100) LOGL GSTART GEND * * GARCH(1,1) with estimated pre-sample variance * DECLARE SERIES U ;* Residuals DECLARE SERIES H ;* Variances NONLIN B0 VC VA VB H0 FRML RESID = Y - B0 FRML HF = VC + VA*H{1} + VB*U{1}**2 FRML LOGL = (H(T)=HF(T)),(U(T)=RESID(T)),-.5*(LOG(H(T))+U(T)*U(T)/H(T)) FRML INIT = (H{1}=H0) LINREG(NOPRINT) Y / U # CONSTANT COMPUTE B0=%BETA(1) COMPUTE H0=%SEESQ,VC=%SEESQ,VA=.05,VB=.05 SET H = %SEESQ MAXIMIZE(METHOD=SIMPLEX,START=INIT,ITERS=5,NOPRINT) LOGL GSTART GEND MAXIMIZE(TRACE,METHOD=BHHH,RECURSIVE,START=INIT,ITERS=100) LOGL GSTART GEND * * EGARCH(1,1) * DECLARE SERIES U ;* Residuals DECLARE SERIES H ;* Variances NONLIN B0 VC VA VB VD FRML RESID = Y - B0 FRML G = ABS(U(T)/SQRT(H(T))) - SQRT(2.0/%PI) - VD*U(T)/SQRT(H(T)) FRML HF = EXP(VC + VA*LOG(H{1}) + VB*G{1}) FRML LOGL = (H(T)=HF(T)),(U(T)=RESID(T)),-.5*(LOG(H(T))+U(T)*U(T)/H(T)) LINREG(NOPRINT) Y / U # CONSTANT COMPUTE B0=%BETA(1) COMPUTE VC=LOG(%SEESQ),VA=.05,VB=.05,VD=.05 SET H = %SEESQ MAXIMIZE(METHOD=SIMPLEX,ITERS=5,NOPRINT) LOGL GSTART GEND MAXIMIZE(TRACE,METHOD=BHHH,RECURSIVE,ITERS=100) LOGL GSTART GEND * * GJR * DECLARE SERIES U ;* Residuals DECLARE SERIES H ;* Variances NONLIN B0 VC VA VB VD FRML RESID = Y - B0 FRML HF = VC + VA*H{1} + VB*U{1}**2 + %IF(U{1}<0.0,VD*U{1}**2,0.0) FRML LOGL = (H(T)=HF(T)),(U(T)=RESID(T)),-.5*(LOG(H(T))+U(T)*U(T)/H(T)) LINREG(NOPRINT) Y / U # CONSTANT COMPUTE B0=%BETA(1) COMPUTE VC=%SEESQ,VA=.05,VB=.05,VD=.05 SET H = %SEESQ MAXIMIZE(METHOD=SIMPLEX,ITERS=5,NOPRINT) LOGL GSTART GEND MAXIMIZE(TRACE,METHOD=BHHH,RECURSIVE,ITERS=100) LOGL GSTART GEND * * T-distribution * DECLARE SERIES U ;* Residuals DECLARE SERIES H ;* Variances NONLIN B0 VC VA VB VD FRML RESID = Y - B0 FRML HF = VC + VA*H{1} + VB*U{1}**2 FRML LOGL = (H(T)=HF(T)),(U(T)=RESID(T)),$ %LNGAMMA(0.5*(VD+1.0)) - %LNGAMMA(0.5*VD) - $ 0.5*LOG(VD-2) - 0.5*LOG(H(T)) - $ 0.5*(VD+1.0)*LOG(1.0+U(T)**2/(H(T)*(VD-2))) LINREG(NOPRINT) Y / U # CONSTANT COMPUTE B0=%BETA(1) COMPUTE VC=%SEESQ,VA=.05,VB=.05,VD=4.0 SET H = %SEESQ MAXIMIZE(METHOD=SIMPLEX,ITERS=15,PRINT) LOGL GSTART GEND MAXIMIZE(TRACE,METHOD=BHHH,RECURSIVE,ITERS=100) LOGL GSTART GEND