Below are the solutions to these exercises on volatility modelling.
############### # # # Exercise 1 # # # ############### library(rugarch)
## Warning: package 'rugarch' was built under R version 3.3.3
library(FinTS)
## Warning: package 'FinTS' was built under R version 3.3.3
## Warning: package 'zoo' was built under R version 3.3.3
library(forecast)
## Warning: package 'forecast' was built under R version 3.3.3
data(m.ibmspln) ############### # # # Exercise 2 # # # ############### sp <- as.ts(m.ibmspln) sp <- sp[,2] sp <- ts(sp, start = c(1926,1), end = c(1999,12), frequency = 12) garch11m = ugarchspec(variance.model = list(garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0), archm=TRUE, archpow=2)) garch11m.fit = ugarchfit(spec=garch11m,data=sp) garch11m.fit
## ## *---------------------------------* ## * GARCH Model Fit * ## *---------------------------------* ## ## Conditional Variance Dynamics ## ----------------------------------- ## GARCH Model : sGARCH(1,1) ## Mean Model : ARFIMA(0,0,0) ## Distribution : norm ## ## Optimal Parameters ## ------------------------------------ ## Estimate Std. Error t value Pr(>|t|) ## mu 0.610314 0.210963 2.89299 0.003816 ## archm 0.004054 0.008345 0.48584 0.627080 ## omega 0.651525 0.229300 2.84136 0.004492 ## alpha1 0.117855 0.020403 5.77645 0.000000 ## beta1 0.864392 0.019165 45.10286 0.000000 ## ## Robust Standard Errors: ## Estimate Std. Error t value Pr(>|t|) ## mu 0.610314 0.210606 2.8979 0.003757 ## archm 0.004054 0.007678 0.5281 0.597432 ## omega 0.651525 0.300519 2.1680 0.030159 ## alpha1 0.117855 0.027511 4.2840 0.000018 ## beta1 0.864392 0.026270 32.9046 0.000000 ## ## LogLikelihood : -2642.219 ## ## Information Criteria ## ------------------------------------ ## ## Akaike 5.9622 ## Bayes 5.9892 ## Shibata 5.9621 ## Hannan-Quinn 5.9725 ## ## Weighted Ljung-Box Test on Standardized Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 0.4816 0.4877 ## Lag[2*(p+q)+(p+q)-1][2] 0.5157 0.6863 ## Lag[4*(p+q)+(p+q)-1][5] 2.4048 0.5263 ## d.o.f=0 ## H0 : No serial correlation ## ## Weighted Ljung-Box Test on Standardized Squared Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 0.6282 0.4280 ## Lag[2*(p+q)+(p+q)-1][5] 1.2048 0.8118 ## Lag[4*(p+q)+(p+q)-1][9] 2.2790 0.8692 ## d.o.f=2 ## ## Weighted ARCH LM Tests ## ------------------------------------ ## Statistic Shape Scale P-Value ## ARCH Lag[3] 0.02715 0.500 2.000 0.8691 ## ARCH Lag[5] 0.42941 1.440 1.667 0.9042 ## ARCH Lag[7] 1.05437 2.315 1.543 0.9045 ## ## Nyblom stability test ## ------------------------------------ ## Joint Statistic: 0.9032 ## Individual Statistics: ## mu 0.06582 ## archm 0.09998 ## omega 0.08772 ## alpha1 0.19898 ## beta1 0.10427 ## ## Asymptotic Critical Values (10% 5% 1%) ## Joint Statistic: 1.28 1.47 1.88 ## Individual Statistic: 0.35 0.47 0.75 ## ## Sign Bias Test ## ------------------------------------ ## t-value prob sig ## Sign Bias 3.7923 1.594e-04 *** ## Negative Sign Bias 1.5236 1.280e-01 ## Positive Sign Bias 0.5336 5.937e-01 ## Joint Effect 23.6460 2.961e-05 *** ## ## ## Adjusted Pearson Goodness-of-Fit Test: ## ------------------------------------ ## group statistic p-value(g-1) ## 1 20 36.37 0.009505 ## 2 30 48.28 0.013732 ## 3 40 47.32 0.169488 ## 4 50 72.47 0.016282 ## ## ## Elapsed time : 0.4552021
# archm effect is not statistically significant. ############### # # # Exercise 3 # # # ############### ibm <- as.ts(m.ibmspln) ibm <- ibm[,1] ibm <- ts(ibm, start = c(1926,1), frequency = 12) ############### # # # Exercise 4 # # # ############### plot(ibm)
Acf(ibm)
Pacf(ibm)
plot(ibm^2)
Acf(ibm^2)
Pacf(ibm^2)
#AR(1)-GARCH(1,1) seems appropriate. ############### # # # Exercise 5 # # # ############### ar1egarch11 <- ugarchspec(variance.model = list(model="eGARCH", variance.targeting=TRUE, garchOrder=c(1,1)), mean.model = list(armaOrder=c(1,0)), distribution.model = "ged") ar1egarch11.fit = ugarchfit(spec=ar1egarch11,data=ibm) ar1egarch11.fit
## ## *---------------------------------* ## * GARCH Model Fit * ## *---------------------------------* ## ## Conditional Variance Dynamics ## ----------------------------------- ## GARCH Model : eGARCH(1,1) ## Mean Model : ARFIMA(1,0,0) ## Distribution : ged ## ## Optimal Parameters ## ------------------------------------ ## Estimate Std. Error t value Pr(>|t|) ## mu 1.180740 0.241462 4.8900 0.000001 ## ar1 0.062356 0.035455 1.7588 0.078620 ## alpha1 -0.041026 0.029829 -1.3754 0.169014 ## beta1 0.947395 0.033493 28.2866 0.000000 ## gamma1 0.196247 0.054669 3.5897 0.000331 ## shape 1.552891 0.102158 15.2009 0.000000 ## omega 0.200220 NA NA NA ## ## Robust Standard Errors: ## Estimate Std. Error t value Pr(>|t|) ## mu 1.180740 0.297298 3.97157 0.000071 ## ar1 0.062356 0.036165 1.72419 0.084674 ## alpha1 -0.041026 0.041530 -0.98788 0.323213 ## beta1 0.947395 0.053344 17.76026 0.000000 ## gamma1 0.196247 0.074341 2.63981 0.008295 ## shape 1.552891 0.098043 15.83889 0.000000 ## omega 0.200220 NA NA NA ## ## LogLikelihood : -2895.627 ## ## Information Criteria ## ------------------------------------ ## ## Akaike 6.5352 ## Bayes 6.5676 ## Shibata 6.5351 ## Hannan-Quinn 6.5476 ## ## Weighted Ljung-Box Test on Standardized Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 1.214 0.2706 ## Lag[2*(p+q)+(p+q)-1][2] 2.090 0.1845 ## Lag[4*(p+q)+(p+q)-1][5] 3.539 0.3086 ## d.o.f=1 ## H0 : No serial correlation ## ## Weighted Ljung-Box Test on Standardized Squared Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 0.9106 0.3399 ## Lag[2*(p+q)+(p+q)-1][5] 1.2230 0.8075 ## Lag[4*(p+q)+(p+q)-1][9] 1.9383 0.9122 ## d.o.f=2 ## ## Weighted ARCH LM Tests ## ------------------------------------ ## Statistic Shape Scale P-Value ## ARCH Lag[3] 0.1579 0.500 2.000 0.6911 ## ARCH Lag[5] 0.7142 1.440 1.667 0.8192 ## ARCH Lag[7] 1.0597 2.315 1.543 0.9037 ## ## Nyblom stability test ## ------------------------------------ ## Joint Statistic: 1.5628 ## Individual Statistics: ## mu 0.27366 ## ar1 0.07493 ## alpha1 0.05631 ## beta1 0.08893 ## gamma1 0.14076 ## shape 0.77629 ## ## Asymptotic Critical Values (10% 5% 1%) ## Joint Statistic: 1.49 1.68 2.12 ## Individual Statistic: 0.35 0.47 0.75 ## ## Sign Bias Test ## ------------------------------------ ## t-value prob sig ## Sign Bias 1.2005 0.2303 ## Negative Sign Bias 1.4693 0.1421 ## Positive Sign Bias 0.9693 0.3327 ## Joint Effect 3.1157 0.3741 ## ## ## Adjusted Pearson Goodness-of-Fit Test: ## ------------------------------------ ## group statistic p-value(g-1) ## 1 20 22.09 0.27980 ## 2 30 37.74 0.12815 ## 3 40 61.28 0.01286 ## 4 50 56.71 0.20964 ## ## ## Elapsed time : 0.51987
############### # # # Exercise 6 # # # ############### rollfore <- ugarchroll(ar1egarch11, ibm, n.start = 800, refit.every = 3, refit.window = "moving", solver = "hybrid", calculate.VaR = TRUE, VaR.alpha = c(0.01, 0.05), keep.coef = TRUE) show(rollfore)
## ## *-------------------------------------* ## * GARCH Roll * ## *-------------------------------------* ## No.Refits : 30 ## Refit Horizon : 3 ## No.Forecasts : 88 ## GARCH Model : eGARCH(1,1) ## Distribution : ged ## ## Forecast Density: ## Mu Sigma Skew Shape Shape(GIG) Realized ## Sep 1992 0.4590 7.0205 0 1.5233 0 -7.0229 ## Oct 1992 0.4996 7.4035 0 1.5233 0 -18.8537 ## Nov 1992 -0.3665 9.5152 0 1.5233 0 3.7922 ## Dec 1992 1.3284 8.8872 0 1.5235 0 -30.3676 ## Jan 1993 -1.3892 12.9611 0 1.5235 0 2.2084 ## Feb 1993 1.2024 11.4858 0 1.5235 0 6.4204 ## ## .......................... ## Mu Sigma Skew Shape Shape(GIG) Realized ## Jul 1999 1.6496 7.5668 0 1.6398 0 -2.7947 ## Aug 1999 0.9030 7.4425 0 1.6398 0 -0.8032 ## Sep 1999 1.0217 6.9637 0 1.6196 0 -2.9017 ## Oct 1999 0.9081 6.8740 0 1.6196 0 -20.8280 ## Nov 1999 -0.0625 9.2603 0 1.6196 0 4.8981 ## Dec 1999 1.3599 8.5458 0 1.6086 0 4.5633 ## ## Elapsed: 36.50807 secs
############### # # # Exercise 7 # # # ############### ar1garch11 <- ugarchspec(variance.model = list(model="sGARCH", garchOrder=c(1,1)), mean.model = list(armaOrder=c(1,0)), distribution.model = "norm") ar1garch11.fit <- ugarchfit(spec=ar1garch11,data=ibm) ar1garch11.fit
## ## *---------------------------------* ## * GARCH Model Fit * ## *---------------------------------* ## ## Conditional Variance Dynamics ## ----------------------------------- ## GARCH Model : sGARCH(1,1) ## Mean Model : ARFIMA(1,0,0) ## Distribution : norm ## ## Optimal Parameters ## ------------------------------------ ## Estimate Std. Error t value Pr(>|t|) ## mu 1.313340 0.228178 5.7558 0.000000 ## ar1 0.104059 0.035771 2.9090 0.003626 ## omega 2.924318 1.095630 2.6691 0.007606 ## alpha1 0.096184 0.024379 3.9453 0.000080 ## beta1 0.837615 0.042616 19.6550 0.000000 ## ## Robust Standard Errors: ## Estimate Std. Error t value Pr(>|t|) ## mu 1.313340 0.225933 5.8130 0.000000 ## ar1 0.104059 0.033539 3.1027 0.001918 ## omega 2.924318 1.301380 2.2471 0.024634 ## alpha1 0.096184 0.027646 3.4791 0.000503 ## beta1 0.837615 0.049108 17.0567 0.000000 ## ## LogLikelihood : -2903.965 ## ## Information Criteria ## ------------------------------------ ## ## Akaike 6.5517 ## Bayes 6.5787 ## Shibata 6.5517 ## Hannan-Quinn 6.5620 ## ## Weighted Ljung-Box Test on Standardized Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 0.01038 0.9189 ## Lag[2*(p+q)+(p+q)-1][2] 0.77765 0.8624 ## Lag[4*(p+q)+(p+q)-1][5] 2.02554 0.7040 ## d.o.f=1 ## H0 : No serial correlation ## ## Weighted Ljung-Box Test on Standardized Squared Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 0.6024 0.4377 ## Lag[2*(p+q)+(p+q)-1][5] 1.0198 0.8552 ## Lag[4*(p+q)+(p+q)-1][9] 1.6651 0.9410 ## d.o.f=2 ## ## Weighted ARCH LM Tests ## ------------------------------------ ## Statistic Shape Scale P-Value ## ARCH Lag[3] 0.2282 0.500 2.000 0.6329 ## ARCH Lag[5] 0.5572 1.440 1.667 0.8666 ## ARCH Lag[7] 1.0475 2.315 1.543 0.9057 ## ## Nyblom stability test ## ------------------------------------ ## Joint Statistic: 0.8044 ## Individual Statistics: ## mu 0.23416 ## ar1 0.06641 ## omega 0.16072 ## alpha1 0.27637 ## beta1 0.23413 ## ## Asymptotic Critical Values (10% 5% 1%) ## Joint Statistic: 1.28 1.47 1.88 ## Individual Statistic: 0.35 0.47 0.75 ## ## Sign Bias Test ## ------------------------------------ ## t-value prob sig ## Sign Bias 0.9982 0.31844 ## Negative Sign Bias 1.6486 0.09959 * ## Positive Sign Bias 1.0262 0.30510 ## Joint Effect 4.1748 0.24320 ## ## ## Adjusted Pearson Goodness-of-Fit Test: ## ------------------------------------ ## group statistic p-value(g-1) ## 1 20 26.73 0.11111 ## 2 30 47.68 0.01588 ## 3 40 54.97 0.04637 ## 4 50 66.50 0.04860 ## ## ## Elapsed time : 0.1901362
bootp <- ugarchboot(ar1garch11.fit, method = c("Partial", "Full")[2], n.ahead = 50, n.bootpred = 500) show(bootp)
## ## *-----------------------------------* ## * GARCH Bootstrap Forecast * ## *-----------------------------------* ## Model : sGARCH ## n.ahead : 50 ## Bootstrap method: full ## Date (T[0]): Dec 1999 ## ## Series (summary): ## min q.25 mean q.75 max forecast[analytic] ## t+1 -36.348 -3.6948 1.38226 6.9372 36.098 1.6515 ## t+2 -36.878 -3.3428 1.84295 7.3478 35.997 1.3485 ## t+3 -43.398 -3.7875 1.27222 6.4958 41.875 1.3170 ## t+4 -34.610 -3.8517 1.14172 5.9405 39.279 1.3137 ## t+5 -44.620 -4.3347 0.76522 5.9135 33.320 1.3134 ## t+6 -34.722 -4.5025 0.72245 5.8736 37.327 1.3133 ## t+7 -41.119 -2.8067 1.52215 6.1924 46.513 1.3133 ## t+8 -64.914 -3.5944 1.21193 6.2934 40.768 1.3133 ## t+9 -42.762 -2.7796 1.46781 5.6977 49.871 1.3133 ## t+10 -32.931 -3.7783 0.90302 5.9755 39.385 1.3133 ## ..................... ## ## Sigma (summary): ## min q0.25 mean q0.75 max forecast[analytic] ## t+1 6.8379 8.1708 8.4599 8.8167 9.601 8.6102 ## t+2 6.0477 7.8046 8.3080 8.6783 17.665 8.4942 ## t+3 5.5647 7.5697 8.2152 8.6287 18.140 8.3845 ## t+4 5.2818 7.3287 8.0803 8.5483 21.180 8.2807 ## t+5 5.1218 7.1302 7.9582 8.4918 22.229 8.1826 ## t+6 5.0579 6.9737 7.8753 8.4552 22.830 8.0899 ## t+7 4.9361 6.8474 7.8200 8.4698 23.442 8.0024 ## t+8 4.8130 6.7163 7.7680 8.4548 23.160 7.9198 ## t+9 4.6791 6.5996 7.6799 8.3402 35.070 7.8419 ## t+10 4.6785 6.4651 7.5672 8.2159 35.031 7.7684 ## .....................
############### # # # Exercise 8 # # # ############### plot(bootp, which=2)
plot(bootp, which=3)
############### # # # Exercise 9 # # # ############### dist <- ugarchdistribution(ar1garch11.fit, n.sim = 2000, n.start = 1, m.sim = 500) show(dist)
## ## *------------------------------------* ## * GARCH Parameter Distribution * ## *------------------------------------* ## Model : sGARCH ## No. Paths (m.sim) : 500 ## Length of Paths (n.sim) : 2000 ## Recursive : FALSE ## ## Coefficients: True vs Simulation Mean (Window-n) ## mu ar1 omega alpha1 beta1 ## true-coef 1.3133 0.10406 2.9243 0.096184 0.83762 ## window-2000 1.3052 0.10200 3.1698 0.095309 0.83226
################ # # # Exercise 10 # # # ################ plot(dist, which=1)
Pls i do i implement Quadratic GARCH in R. Thanks for your useful comments