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
data("dmbp") rets <- ts(dmbp$V1) ############### # # # Exercise 2 # # # ############### garch1.mod = ugarchspec(variance.model = list(garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)), fixed.pars=list(mu=0, omega=0.2, alpha1=0.2, beta1=0.6)) garch1.mod
## ## *---------------------------------* ## * GARCH Model Spec * ## *---------------------------------* ## ## Conditional Variance Dynamics ## ------------------------------------ ## GARCH Model : sGARCH(1,1) ## Variance Targeting : FALSE ## ## Conditional Mean Dynamics ## ------------------------------------ ## Mean Model : ARFIMA(0,0,0) ## Include Mean : TRUE ## GARCH-in-Mean : FALSE ## ## Conditional Distribution ## ------------------------------------ ## Distribution : norm ## Includes Skew : FALSE ## Includes Shape : FALSE ## Includes Lambda : FALSE
############### # # # Exercise 3 # # # ############### garch1.sim = ugarchpath(garch1.mod,n.sim=500) ############### # # # Exercise 4 # # # ############### plot(garch1.sim, which=2)
plot(garch1.sim, which=1)
############### # # # Exercise 5 # # # ############### acf(garch1.sim@path$seriesSim, main="returns")
acf(garch1.sim@path$seriesSim^2, main="squared returns")
############### # # # Exercise 6 # # # ############### Box.test(garch1.sim@path$seriesSim^2, type = "Ljung-Box", lag = 12)
## ## Box-Ljung test ## ## data: [email protected]$seriesSim^2 ## X-squared = 51.587, df = 12, p-value = 7.335e-07
# There is significant residual correlation. ############### # # # Exercise 7 # # # ############### garch11.spec = ugarchspec(variance.model = list(garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0))) dmbp.garch11.fit = ugarchfit(spec=garch11.spec,data=rets) dmbp.garch11.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.006185 0.008462 -0.73094 0.464813 ## omega 0.010760 0.002853 3.77155 0.000162 ## alpha1 0.153407 0.026581 5.77124 0.000000 ## beta1 0.805880 0.033567 24.00821 0.000000 ## ## Robust Standard Errors: ## Estimate Std. Error t value Pr(>|t|) ## mu -0.006185 0.009017 -0.68594 0.492752 ## omega 0.010760 0.006498 1.65582 0.097758 ## alpha1 0.153407 0.049390 3.10606 0.001896 ## beta1 0.805880 0.069163 11.65196 0.000000 ## ## LogLikelihood : -1106.587 ## ## Information Criteria ## ------------------------------------ ## ## Akaike 1.1252 ## Bayes 1.1365 ## Shibata 1.1252 ## Hannan-Quinn 1.1294 ## ## Weighted Ljung-Box Test on Standardized Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 5.061 0.02447 ## Lag[2*(p+q)+(p+q)-1][2] 5.167 0.03671 ## Lag[4*(p+q)+(p+q)-1][5] 6.468 0.06964 ## d.o.f=0 ## H0 : No serial correlation ## ## Weighted Ljung-Box Test on Standardized Squared Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 2.501 0.1137 ## Lag[2*(p+q)+(p+q)-1][5] 3.575 0.3120 ## Lag[4*(p+q)+(p+q)-1][9] 5.474 0.3632 ## d.o.f=2 ## ## Weighted ARCH LM Tests ## ------------------------------------ ## Statistic Shape Scale P-Value ## ARCH Lag[3] 1.668 0.500 2.000 0.1965 ## ARCH Lag[5] 1.673 1.440 1.667 0.5481 ## ARCH Lag[7] 3.603 2.315 1.543 0.4075 ## ## Nyblom stability test ## ------------------------------------ ## Joint Statistic: 0.6641 ## Individual Statistics: ## mu 0.1673 ## omega 0.3550 ## alpha1 0.2635 ## beta1 0.3349 ## ## Asymptotic Critical Values (10% 5% 1%) ## Joint Statistic: 1.07 1.24 1.6 ## Individual Statistic: 0.35 0.47 0.75 ## ## Sign Bias Test ## ------------------------------------ ## t-value prob sig ## Sign Bias 1.3192 0.1873 ## Negative Sign Bias 0.2434 0.8077 ## Positive Sign Bias 0.6660 0.5055 ## Joint Effect 2.8773 0.4109 ## ## ## Adjusted Pearson Goodness-of-Fit Test: ## ------------------------------------ ## group statistic p-value(g-1) ## 1 20 109.9 8.208e-15 ## 2 30 137.9 4.003e-16 ## 3 40 137.4 6.866e-13 ## 4 50 160.5 8.747e-14 ## ## ## Elapsed time : 0.3322191
############### # # # Exercise 8 # # # ############### plot(dmbp.garch11.fit,which="all")
## ## please wait...calculating quantiles...
############### # # # Exercise 9 # # # ############### garch11.spec = ugarchspec(variance.model = list(garchOrder=c(1,1)), mean.model = list(armaOrder=c(1,0))) dmbp.garch11.fit = ugarchfit(spec=garch11.spec,data=rets) dmbp.garch11.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 -0.006338 0.008853 -0.71596 0.474016 ## ar1 0.051381 0.025645 2.00354 0.045119 ## omega 0.011190 0.002834 3.94879 0.000079 ## alpha1 0.157664 0.026397 5.97288 0.000000 ## beta1 0.799852 0.033047 24.20310 0.000000 ## ## Robust Standard Errors: ## Estimate Std. Error t value Pr(>|t|) ## mu -0.006338 0.009090 -0.6973 0.485618 ## ar1 0.051381 0.028327 1.8138 0.069704 ## omega 0.011190 0.006266 1.7860 0.074099 ## alpha1 0.157664 0.047344 3.3302 0.000868 ## beta1 0.799852 0.065443 12.2221 0.000000 ## ## LogLikelihood : -1104.575 ## ## Information Criteria ## ------------------------------------ ## ## Akaike 1.1242 ## Bayes 1.1383 ## Shibata 1.1242 ## Hannan-Quinn 1.1294 ## ## Weighted Ljung-Box Test on Standardized Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 0.1703 0.6799 ## Lag[2*(p+q)+(p+q)-1][2] 0.3481 0.9900 ## Lag[4*(p+q)+(p+q)-1][5] 1.6404 0.8111 ## d.o.f=1 ## H0 : No serial correlation ## ## Weighted Ljung-Box Test on Standardized Squared Residuals ## ------------------------------------ ## statistic p-value ## Lag[1] 2.247 0.1339 ## Lag[2*(p+q)+(p+q)-1][5] 3.223 0.3679 ## Lag[4*(p+q)+(p+q)-1][9] 4.989 0.4310 ## d.o.f=2 ## ## Weighted ARCH LM Tests ## ------------------------------------ ## Statistic Shape Scale P-Value ## ARCH Lag[3] 1.477 0.500 2.000 0.2242 ## ARCH Lag[5] 1.482 1.440 1.667 0.5970 ## ARCH Lag[7] 3.291 2.315 1.543 0.4604 ## ## Nyblom stability test ## ------------------------------------ ## Joint Statistic: 0.765 ## Individual Statistics: ## mu 0.1584 ## ar1 0.0750 ## omega 0.3625 ## alpha1 0.2698 ## beta1 0.3521 ## ## 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 1.39276 0.1639 ## Negative Sign Bias 0.08532 0.9320 ## Positive Sign Bias 0.73575 0.4620 ## Joint Effect 2.76419 0.4294 ## ## ## Adjusted Pearson Goodness-of-Fit Test: ## ------------------------------------ ## group statistic p-value(g-1) ## 1 20 105.8 4.634e-14 ## 2 30 118.8 7.862e-13 ## 3 40 141.5 1.534e-13 ## 4 50 157.8 2.309e-13 ## ## ## Elapsed time : 0.3977649
################ # # # Exercise 10 # # # ################ plot(dmbp.garch11.fit,which="all")
## ## please wait...calculating quantiles...
Leave a Reply