> library(fSeries) > source("garchoxfit.R") % Modification needed to make the program working. *** R output for Problem A *** > da=read.table("d-wmtsp9604.txt") > sp=log(da[,3]+1) % log returns > sp=sp*100 % percentage log returns > basicStats(sp) Value nobs 2267.00000000 NAs 0.00000000 Minimum -7.11383857 Maximum 5.57326757 1. Quartile -0.62887327 3. Quartile 0.70168244 Mean 0.02985619 Median 0.04568956 Sum 67.68399177 SE Mean 0.02515274 LCL Mean -0.01946861 UCL Mean 0.07918100 Variance 1.43424053 Stdev 1.19759782 Skewness -0.09391320 Kurtosis 2.68237315 > sp[2266:2267] [1] 0.008199664 -0.134390263 > a1=acf(sp,lag.max=12) > a1$acf [,1] [1,] 1.000000000 [2,] -0.012562223 [3,] -0.028218829 [4,] -0.028975278 [5,] 0.006141760 [6,] -0.044138323 [7,] -0.010934041 [8,] -0.041636270 [9,] 0.012313152 [10,] 0.006658828 [11,] 0.016649509 [12,] -0.028357374 [13,] 0.053670290 > Box.test(sp,lag=10,type='Ljung') Box-Ljung test data: sp X-squared = 13.8858, df = 10, p-value = 0.1783 > Box.test(sp^2,lag=12,type='Ljung') Box-Ljung test data: sp^2 X-squared = 490.2651, df = 12, p-value < 2.2e-16 *** Problem B *** > da=read.table("eps-pg.txt") > dim(da) [1] 45 4 > pg=log(da[,4]) > a1=acf(pg,lag.max=12) > a1$acf [,1] [1,] 1.00000000 [2,] -0.02829666 [3,] 0.01487769 [4,] -0.03396941 [5,] 0.86175766 [6,] -0.07049624 [7,] -0.03984440 [8,] -0.07397695 [9,] 0.72522941 [10,] -0.10735125 [11,] -0.08885623 [12,] -0.11096427 [13,] 0.59824685 > a2=acf(diff(pg,4)) > a2$acf [,1] [1,] 1.000000000 [2,] 0.374095844 [3,] 0.280694488 [4,] 0.173713711 [5,] -0.125247632 [6,] 0.001933294 [7,] 0.138442146 [8,] -0.006117635 [9,] 0.028825614 [10,] 0.147182792 [11,] -0.004992584 [12,] 0.143262428 [13,] 0.003193902 [14,] -0.285925323 [15,] -0.186450023 [16,] -0.294633027 [17,] -0.292910368 > a2=pacf(diff(pg,4)) > a2$acf [,1] [1,] 0.37409584 [2,] 0.16364910 [3,] 0.02947467 [4,] -0.27877066 [5,] 0.10261804 [6,] 0.25351712 [7,] -0.11026785 [8,] -0.13799524 [9,] 0.22221453 [10,] 0.04158391 [11,] 0.03846564 [12,] -0.24270757 [13,] -0.30928132 [14,] 0.07672117 [15,] -0.03399360 [16,] -0.19714015 > ct=diff(pg,4) > length(ct) [1] 41 > m1=arima(ct,order=c(1,0,0),seasonal=list(order=c(0,0,1),period=4)) > m1 Call: arima(x = ct, order = c(1, 0, 0), seasonal = list(order = c(0, 0, 1), period = 4)) Coefficients: ar1 sma1 intercept 0.4620 -0.3016 0.0969 % The constant term is (1-.462)*.0969 s.e. 0.1476 0.1628 0.0103 % which is approximately 0.052. sigma^2 estimated as 0.00246: log likelihood = 64.68, aic = -121.36 > tsdiag(m1) > Box.test(m1$residuals,lag=12,type='Ljung') Box-Ljung test data: m1$residuals X-squared = 8.956, df = 12, p-value = 0.7067 > predict(m1,4) $pred Start = 42 [1] 0.08273106 0.09647717 0.08558412 0.09848709 $se [1] 0.04959974 0.05463677 0.05565277 0.05586722 > pg[41:45] [1] 0.0295588 -0.1743534 1.2781522 0.1133287 0.1222176 > -.1743534+.08273106 % pg(t)=pg(t-4)+ct(t) --- 1-step ahead forecast [1] -0.09162234 > 1.2781522+.09647717 % 2-step ahead forecast, etc. [1] 1.374629 *** Problem 3 *** > da=read.table("d-wmtsp9904.txt") > dim(da) [1] 1508 3 > wmt=log(da[,2]+1)*100 > sp=log(da[,3]+1)*100 > m1=lm(wmt~sp) > summary(m1) lm(formula = wmt ~ sp) Residuals: Min 1Q Median 3Q Max -8.28150 -0.88964 -0.05316 0.88161 9.11967 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.02052 0.04631 0.443 0.658 sp 0.96058 0.03699 25.967 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.798 on 1506 degrees of freedom Multiple R-Squared: 0.3093, Adjusted R-squared: 0.3088 F-statistic: 674.3 on 1 and 1506 DF, p-value: < 2.2e-16 > Box.test(m1$residuals^2,lag=10,type='Ljung') Box-Ljung test data: m1$residuals^2 X-squared = 302.6946, df = 10, p-value < 2.2e-16 *** Because R > wmt1=m1$residuals > m2=garchOxFit(formula.mean=~arma(0,0),formula.var=~garch(1,1),series=wmt1,cond.dist="t") ******************** ** SPECIFICATIONS ** ******************** Dependent variable : X Mean Equation : ARMA (0, 0) model. No regressor in the mean Variance Equation : GARCH (1, 1) model. No regressor in the variance The distribution is a Student distribution, with 6.40737 degrees of freedom. Strong convergence using numerical derivatives Log-likelihood = -2738.14 Please wait : Computing the Std Errors ... Maximum Likelihood Estimation (Std.Errors based on Numerical OPG matrix) Coefficient Std.Error t-value t-prob Cst(M) -0.024723 0.031133 -0.7941 0.4273 Cst(V) 0.000726 0.0033282 0.2181 0.8274 ARCH(Alpha1) 0.037774 0.0080962 4.666 0.0000 GARCH(Beta1) 0.963024 0.0075286 127.9 0.0000 Student(DF) 6.407375 1.0046 6.378 0.0000 No. Observations : 1508 No. Parameters : 5 Mean (Y) : -0.00000 Variance (Y) : 3.22967 Skewness (Y) : 0.28672 Kurtosis (Y) : 6.27966 Log Likelihood : -2738.141 Alpha[1]+Beta[1]: 1.00080 The positivity constraint for the GARCH (1,1) is observed. Estimated Parameters Vector : -0.024723; 0.000726; 0.037774; 0.963024; 6.407375 *************** ** FORECASTS ** *************** Number of Forecasts: 15 Horizon Mean Variance 1 -0.02472 0.6675 2 -0.02472 0.6688 3 -0.02472 0.67 4 -0.02472 0.6713 5 -0.02472 0.6726 .... 15 -0.02472 0.6852 --------------- *********** ** TESTS ** *********** Statistic t-Test P-Value Skewness -0.091915 1.4586 0.14467 Excess Kurtosis 2.3739 18.848 3.0356e-079 Jarque-Bera 356.21 .NaN 4.4700e-078 --------------- Information Criterium (to be minimized) Akaike 3.638117 Shibata 3.638096 Schwarz 3.655752 Hannan-Quinn 3.644685 --------------- Q-Statistics on Standardized Residuals Q( 10) = 13.0875 [0.2188181] Q( 15) = 16.2718 [0.3642227] Q( 20) = 20.6698 [0.4167908] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] -------------- Q-Statistics on Squared Standardized Residuals --> P-values adjusted by 2 degree(s) of freedom Q( 10) = 10.4324 [0.2359799] Q( 15) = 18.7210 [0.1320124] Q( 20) = 23.3448 [0.1776841] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] *** GJR(1,2) model > m3=garchOxFit(formula.mean=~arma(0,0),formula.var=~gjr(1,2),series=wmt1,cond.dist="t") ******************** ** SPECIFICATIONS ** ******************** Dependent variable : X Mean Equation : ARMA (0, 0) model. No regressor in the mean Variance Equation : GJR (1, 2) model. No regressor in the variance The distribution is a Student distribution, with 6.9035 degrees of freedom. Strong convergence using numerical derivatives Log-likelihood = -2730.8 Please wait : Computing the Std Errors ... Maximum Likelihood Estimation (Std.Errors based on Numerical OPG matrix) Coefficient Std.Error t-value t-prob Cst(M) -0.021390 0.030987 -0.6903 0.4901 Cst(V) 0.000413 0.0030766 0.1344 0.8931 ARCH(Alpha1) 0.039674 0.038105 1.041 0.2980 ARCH(Alpha2) 0.000000 0.038930 0.00 1.0000 GARCH(Beta1) 0.966470 0.0071661 134.9 0.0000 GJR(Gamma1) 0.190446 0.071050 2.680 0.0074 GJR(Gamma2) -0.201474 0.069977 -2.879 0.0040 Student(DF) 6.903501 1.1867 5.817 0.0000 No. Observations : 1508 No. Parameters : 8 Mean (Y) : -0.00000 Variance (Y) : 3.22967 Skewness (Y) : 0.28672 Kurtosis (Y) : 6.27966 Log Likelihood : -2730.799 The condition for existence of the second moment of the GJR is not observed. Estimated Parameters Vector : -0.021390; 0.000413; 0.039674; 0.000000; 0.966470; 0.190446;-0.201474; 6.903501 *************** ** FORECASTS ** *************** Number of Forecasts: 15 Horizon Mean Variance 1 -0.02139 0.5486 2 -0.02139 0.5836 3 -0.02139 0.5879 4 -0.02139 0.5891 5 -0.02139 0.59 ..... 15 -0.02139 0.5987 --------------- *********** ** TESTS ** *********** Statistic t-Test P-Value Skewness 0.015524 0.24636 0.80541 Excess Kurtosis 1.6726 13.280 3.0292e-040 Jarque-Bera 175.83 .NaN 6.5803e-039 --------------- Information Criterium (to be minimized) Akaike 3.632360 Shibata 3.632304 Schwarz 3.660575 Hannan-Quinn 3.642868 --------------- Q-Statistics on Standardized Residuals Q( 10) = 13.6223 [0.1909289] Q( 15) = 16.5580 [0.3459644] Q( 20) = 21.4022 [0.3738102] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] -------------- Q-Statistics on Squared Standardized Residuals --> P-values adjusted by 3 degree(s) of freedom Q( 10) = 3.73428 [0.8098242] Q( 15) = 11.7801 [0.4634946] Q( 20) = 17.5847 [0.4154824] *** Problem D **** > m1=garchOxFit(formula.mean=~arma(0,0),formula.var=~garch(1,1),series=hd,cond.dist="t") ******************** ** SPECIFICATIONS ** ******************** Dependent variable : X Mean Equation : ARMA (0, 0) model. No regressor in the mean Variance Equation : GARCH (1, 1) model. No regressor in the variance The distribution is a Student distribution, with 6.15487 degrees of freedom. Strong convergence using numerical derivatives Log-likelihood = -5395.89 Maximum Likelihood Estimation (Std.Errors based on Numerical OPG matrix) Coefficient Std.Error t-value t-prob Cst(M) 0.079285 0.035827 2.213 0.0270 Cst(V) 0.037225 0.014835 2.509 0.0122 ARCH(Alpha1) 0.046064 0.0080230 5.742 0.0000 GARCH(Beta1) 0.947291 0.0086536 109.5 0.0000 Student(DF) 6.154866 0.57019 10.79 0.0000 No. Observations : 2519 No. Parameters : 5 Mean (Y) : 0.05873 Variance (Y) : 5.70040 Skewness (Y) : -1.19522 Kurtosis (Y) : 21.48088 Log Likelihood : -5395.886 Alpha[1]+Beta[1]: 0.99336 The positivity constraint for the GARCH (1,1) is observed. The unconditional variance is 5.60228 Estimated Parameters Vector : 0.079285; 0.037225; 0.046064; 0.947291; 6.154866 *************** ** FORECASTS ** *************** Number of Forecasts: 15 Horizon Mean Variance 1 0.07928 1.506 2 0.07928 1.533 3 0.07928 1.56 4 0.07928 1.587 .... 15 0.07928 1.871 --------------- *********** ** TESTS ** *********** Statistic t-Test P-Value Skewness -0.94682 19.412 6.1433e-084 Excess Kurtosis 12.725 130.49 0.00000 Jarque-Bera 17372. .NaN 0.00000 --------------- Information Criterium (to be minimized) Akaike 4.288119 Shibata 4.288112 Schwarz 4.299695 Hannan-Quinn 4.292320 --------------- Q-Statistics on Standardized Residuals Q( 10) = 14.6228 [0.1464295] Q( 15) = 17.9851 [0.2634521] Q( 20) = 23.1795 [0.2800667] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] -------------- Q-Statistics on Squared Standardized Residuals --> P-values adjusted by 2 degree(s) of freedom Q( 10) = 2.03337 [0.9799717] Q( 15) = 2.36172 [0.9994284] Q( 20) = 3.14363 [0.9999604] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] EGARCH model is hard to estimate using R. Thus, I fit a GJR model instead. **GJR Model *** > m3=garchOxFit(formula.mean=~arma(0,0),formula.var=~gjr(1,2),series=hd,cond.dist="t") ******************** ** SPECIFICATIONS ** ******************** Dependent variable : X Mean Equation : ARMA (0, 0) model. No regressor in the mean Variance Equation : GJR (1, 2) model. No regressor in the variance The distribution is a Student distribution, with 6.39631 degrees of freedom. Strong convergence using numerical derivatives Log-likelihood = -5386.04 Maximum Likelihood Estimation (Std.Errors based on Numerical OPG matrix) Coefficient Std.Error t-value t-prob Cst(M) 0.063879 0.035896 1.780 0.0753 Cst(V) 0.039602 0.014121 2.805 0.0051 ARCH(Alpha1) 0.021861 0.030547 0.7157 0.4743 ARCH(Alpha2) 0.000000 0.030068 0.00 1.0000 GARCH(Beta1) 0.949051 0.0086888 109.2 0.0000 GJR(Gamma1) 0.165060 0.054419 3.033 0.0024 GJR(Gamma2) -0.120167 0.053321 -2.254 0.0243 Student(DF) 6.396308 0.62465 10.24 0.0000 No. Observations : 2519 No. Parameters : 8 Mean (Y) : 0.05873 Variance (Y) : 5.70040 Skewness (Y) : -1.19522 Kurtosis (Y) : 21.48088 Log Likelihood : -5386.038 The condition for existence of the second moment of the GJR is observed. Estimated Parameters Vector : 0.063879; 0.039602; 0.021861; 0.000000; 0.949051; 0.165060;-0.120167; 6.396308 *************** ** FORECASTS ** *************** Number of Forecasts: 15 Horizon Mean Variance 1 0.06388 1.534 2 0.06388 1.628 3 0.06388 1.662 4 0.06388 1.693 5 0.06388 1.723 ..... 15 0.06388 2.013 --------------- *********** ** TESTS ** *********** Statistic t-Test P-Value Skewness -0.68919 14.130 2.4852e-045 Excess Kurtosis 8.2741 84.851 0.00000 Jarque-Bera 7384.9 .NaN 0.00000 --------------- Information Criterium (to be minimized) Akaike 4.282682 Shibata 4.282662 Schwarz 4.301202 Hannan-Quinn 4.289403 --------------- Q-Statistics on Standardized Residuals Q( 10) = 16.2664 [0.0922567] Q( 15) = 19.6073 [0.1875190] Q( 20) = 24.1431 [0.2361970] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] -------------- Q-Statistics on Squared Standardized Residuals --> P-values adjusted by 3 degree(s) of freedom Q( 10) = 2.40258 [0.9342527] Q( 15) = 2.90935 [0.9961508] Q( 20) = 3.92686 [0.9995436] H0 : No serial correlation ==> Accept H0 when prob. is High [Q < Chisq(lag)] -------------- ARCH 1-2 test: F(2,2511)= 0.047077 [0.9540] ARCH 1-5 test: F(5,2505)= 0.12096 [0.9878] ARCH 1-10 test: F(10,2495)= 0.23995 [0.9922] *** ARCH-in-Mean > m4=garchOxFit(formula.mean=~arma(0,0),formula.var=~garch(1,1),series=hd,arch.in.mean=T,cond.dist="t") ******************** ** SPECIFICATIONS ** ******************** Dependent variable : X Mean Equation : ARMA (0, 0) model. No regressor in the mean Variance Equation : GARCH (1, 1) model. in-mean No regressor in the variance The distribution is a Student distribution, with 6.16098 degrees of freedom. Strong convergence using numerical derivatives Log-likelihood = -5395.78 Maximum Likelihood Estimation (Std.Errors based on Numerical OPG matrix) Coefficient Std.Error t-value t-prob Cst(M) 0.056788 0.063994 0.8874 0.3750 Cst(V) 0.037369 0.014874 2.512 0.0121 ARCH(Alpha1) 0.046304 0.0080416 5.758 0.0000 GARCH(Beta1) 0.947040 0.0086698 109.2 0.0000 Student(DF) 6.160984 0.57088 10.79 0.0000 ARCH-in-mean(var) 0.005939 0.013829 0.4295 0.6676 No. Observations : 2519 No. Parameters : 6 Mean (Y) : 0.05873 Variance (Y) : 5.70040 Skewness (Y) : -1.19522 Kurtosis (Y) : 21.48088 Log Likelihood : -5395.778 Alpha[1]+Beta[1]: 0.99334 The unconditional variance is 5.61409 Estimated Parameters Vector : 0.056788; 0.037369; 0.046304; 0.947040; 6.160984; 0.005939 *************** ** FORECASTS ** *************** Number of Forecasts: 15 Horizon Mean Variance 1 0.06572 1.505 2 0.06589 1.532 3 0.06605 1.559 4 0.06621 1.586 5 0.06637 1.613 ..... 15 0.0679 1.871 --------------- *********** ** TESTS ** *********** Statistic t-Test P-Value Skewness -0.94372 19.348 2.1083e-083 Excess Kurtosis 12.685 130.09 0.00000 Jarque-Bera 17263. .NaN 0.00000 --------------- Information Criterium (to be minimized) Akaike 4.288828 Shibata 4.288816 Schwarz 4.302718 Hannan-Quinn 4.293869 --------------- Q-Statistics on Standardized Residuals Q( 10) = 14.4126 [0.1549888] Q( 15) = 17.7450 [0.2763073] Q( 20) = 23.0938 [0.2842119] -------------- Q-Statistics on Squared Standardized Residuals --> P-values adjusted by 2 degree(s) of freedom Q( 10) = 1.99956 [0.9810252] Q( 15) = 2.34104 [0.9994554] Q( 20) = 3.11588 [0.9999629]