* G05HKF Example Program Text * Mark 22 Release. NAG Copyright 2008. * .. Parameters .. INTEGER NOUT PARAMETER (NOUT=6) INTEGER NPARMX, LDCOVR, NUM DOUBLE PRECISION ZERO PARAMETER (NPARMX=10,LDCOVR=NPARMX,NUM=1500,ZERO=0.0D0) INTEGER NUM1, NREGMX PARAMETER (NUM1=3000,NREGMX=10) * .. Local Scalars .. DOUBLE PRECISION DF, FAC1, GAMMA, HP, LGF, MEAN, TOL, XTERM INTEGER I, IFAIL, IGEN, IP, IQ, ISYM, K, LDX, LWORK, + MAXIT, MN, NPAR, NPAR2, NREG, NT LOGICAL FCALL CHARACTER DIST * .. Local Arrays .. DOUBLE PRECISION BX(10), COVR(LDCOVR,NPARMX), CVAR(100), + ETM(NUM1), HT(NUM1+10), HTM(NUM1), PARAM(NPARMX), + RVEC(40), RWSAV(9), SC(NPARMX), SE(NPARMX), + THETA(NPARMX), WORK(NUM1*3+NPARMX+NREGMX*NUM1+20* + 20+1), X(NUM1,10), YT(NUM1+10) INTEGER ISEED(4) LOGICAL COPTS(2) * .. External Subroutines .. EXTERNAL G05HKF, G05KBF, G13FAF, G13FBF * .. Intrinsic Functions .. INTRINSIC DBLE, SIN * .. Executable Statements .. WRITE (NOUT,*) 'G05HKF Example Program Results' WRITE (NOUT,*) * * Initialize the generator ISEED(1) = 111 IGEN = 0 CALL G05KBF(IGEN,ISEED) * * Example using Normal errors NREG = 0 LDX = NUM1 BX(1) = 1.5D0 BX(2) = 2.5D0 BX(3) = 3.0D0 MEAN = 3.0D0 DO 20 I = 1, NUM FAC1 = DBLE(I)*0.01D0 X(I,1) = 0.01D0 + 0.7D0*SIN(FAC1) X(I,2) = 0.5D0 + FAC1*0.1D0 X(I,3) = 1.0D0 20 CONTINUE * ISYM = 1 MN = 1 GAMMA = -0.4D0 IP = 0 IQ = 3 PARAM(1) = 0.8D0 PARAM(2) = 0.6D0 PARAM(3) = 0.2D0 PARAM(4) = 0.1D0 NPAR = 1 + IQ + IP LWORK = NREG*NUM + 3*NUM + NPAR + ISYM + MN + NREG + 403 DIST = 'N' * * First call to routine FCALL = .TRUE. IFAIL = 0 CALL G05HKF(DIST,NUM,IP,IQ,PARAM,GAMMA,DF,HT,YT,FCALL,RVEC,IGEN, + ISEED,RWSAV,IFAIL) * Discard the first NUM values and call the routine again FCALL = .FALSE. IFAIL = 0 CALL G05HKF(DIST,NUM,IP,IQ,PARAM,GAMMA,DF,HT,YT,FCALL,RVEC,IGEN, + ISEED,RWSAV,IFAIL) * DO 60 I = 1, NUM XTERM = ZERO DO 40 K = 1, NREG XTERM = XTERM + X(I,K)*BX(K) 40 CONTINUE IF (MN.EQ.1) THEN YT(I) = MEAN + XTERM + YT(I) ELSE YT(I) = XTERM + YT(I) END IF 60 CONTINUE * DO 80 I = 1, NPAR THETA(I) = PARAM(I)*0.5D0 80 CONTINUE * IF (ISYM.EQ.1) THEN THETA(NPAR+ISYM) = GAMMA*0.5D0 END IF * * Fit a GARCH model to the generated data COPTS(1) = .TRUE. COPTS(2) = .TRUE. MAXIT = 200 TOL = 1.0D-5 NPAR2 = 1 + IQ + IP + ISYM + MN + NREG IFAIL = 0 CALL G13FAF(DIST,YT,X,LDX,NUM,IP,IQ,NREG,MN,ISYM,NPAR2,THETA,SE, + SC,COVR,LDCOVR,HP,ETM,HTM,LGF,COPTS,MAXIT,TOL,WORK, + LWORK,IFAIL) * Display the output WRITE (NOUT,*) WRITE (NOUT,*) 'Normal distribution' WRITE (NOUT,*) WRITE (NOUT,*) ' Correct Parameter Standard' WRITE (NOUT,*) ' values estimates errors' DO 100 I = 1, NPAR WRITE (NOUT,99998) 'PARAM(', I, ')', PARAM(I), THETA(I), SE(I) 100 CONTINUE IF (ISYM.EQ.1) THEN WRITE (NOUT,99999) 'Gamma ', GAMMA, THETA(NPAR+1), SE(NPAR+1) END IF IF (MN.EQ.1) THEN WRITE (NOUT,99999) 'Mean ', MEAN, THETA(NPAR+ISYM+1), + SE(NPAR+ISYM+1) END IF DO 120 I = 1, NREG WRITE (NOUT,99998) 'BX(', I, ') ', BX(I), + THETA(NPAR+ISYM+MN+I), SE(NPAR+ISYM+MN+I) 120 CONTINUE * NT = 4 IFAIL = 0 CALL G13FBF(NUM,NT,IP,IQ,THETA,GAMMA,CVAR,HTM,ETM,IFAIL) WRITE (NOUT,*) WRITE (NOUT,99997) 'Volatility forecast = ', CVAR(NT) WRITE (NOUT,*) * * Example using Students T errors DIST = 'T' NREG = 2 MN = 1 DF = 4.1D0 IP = 1 IQ = 2 ISYM = 1 GAMMA = -0.2D0 * NPAR = IQ + IP + 1 LWORK = NREG*NUM + 3*NUM + NPAR + ISYM + MN + NREG + 404 * PARAM(1) = 0.1D0 PARAM(2) = 0.2D0 PARAM(3) = 0.3D0 PARAM(4) = 0.4D0 * IGEN = 0 ISEED(1) = 111 CALL G05KBF(IGEN,ISEED) * * First call to the routine IFAIL = 0 FCALL = .TRUE. CALL G05HKF(DIST,NUM,IP,IQ,PARAM,GAMMA,DF,HT,YT,FCALL,RVEC,IGEN, + ISEED,RWSAV,IFAIL) * Second call to the routine FCALL = .FALSE. CALL G05HKF(DIST,NUM,IP,IQ,PARAM,GAMMA,DF,HT,YT,FCALL,RVEC,IGEN, + ISEED,RWSAV,IFAIL) * Discard the previously generated values, and call the routine again FCALL = .FALSE. CALL G05HKF(DIST,NUM,IP,IQ,PARAM,GAMMA,DF,HT,YT,FCALL,RVEC,IGEN, + ISEED,RWSAV,IFAIL) * DO 160 I = 1, NUM XTERM = ZERO DO 140 K = 1, NREG XTERM = XTERM + X(I,K)*BX(K) 140 CONTINUE IF (MN.EQ.1) THEN YT(I) = MEAN + XTERM + YT(I) ELSE YT(I) = XTERM + YT(I) END IF 160 CONTINUE * COPTS(1) = .TRUE. COPTS(2) = .TRUE. * MAXIT = 200 TOL = 1.0D-5 * DO 180 I = 1, NPAR THETA(I) = PARAM(I)*0.5D0 180 CONTINUE * THETA(NPAR+ISYM) = GAMMA*0.5D0 THETA(NPAR+ISYM+1) = DF*0.65D0 * NPAR2 = 2 + IP + IQ + ISYM + MN + NREG IFAIL = 0 CALL G13FAF(DIST,YT,X,LDX,NUM,IP,IQ,NREG,MN,ISYM,NPAR2,THETA,SE, + SC,COVR,LDCOVR,HP,ETM,HTM,LGF,COPTS,MAXIT,TOL,WORK, + LWORK,IFAIL) * WRITE (NOUT,*) WRITE (NOUT,*) 'Students t distribution' WRITE (NOUT,*) WRITE (NOUT,*) ' Correct Parameter Standard' WRITE (NOUT,*) ' values estimates errors' DO 200 I = 1, NPAR WRITE (NOUT,99998) 'PARAM(', I, ')', PARAM(I), THETA(I), SE(I) 200 CONTINUE IF (ISYM.EQ.1) THEN WRITE (NOUT,99999) 'Gamma ', GAMMA, THETA(NPAR+ISYM), + SE(NPAR+ISYM) END IF WRITE (NOUT,99999) 'DF ', DF, THETA(NPAR+ISYM+1), + SE(NPAR+ISYM+1) IF (MN.EQ.1) THEN WRITE (NOUT,99999) 'Mean ', MEAN, THETA(NPAR+ISYM+2), + SE(NPAR+ISYM+2) END IF DO 220 I = 1, NREG WRITE (NOUT,99998) 'BX(', I, ') ', BX(I), + THETA(NPAR+ISYM+1+MN+I), SE(NPAR+ISYM+1+MN+I) 220 CONTINUE * NT = 4 IFAIL = 0 CALL G13FBF(NUM,NT,IP,IQ,THETA,GAMMA,CVAR,HTM,ETM,IFAIL) * WRITE (NOUT,*) WRITE (NOUT,99997) 'Volatility forecast = ', CVAR(NT) * 99999 FORMAT (1X,A,3(F10.2,2X)) 99998 FORMAT (1X,A,I1,A,3(F10.2,2X)) 99997 FORMAT (1X,A,F12.2) END