library(rugarch)
## Loading required package: parallel
## 
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
## 
##     sigma
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(ggplot2)

data = read.csv("AUS.csv")
inflation = ts(data$INFLATION, start = c(2005, 1), frequency = 12)
infl = diff(inflation); infl
##        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
## 2005       -0.05  0.17 -1.66  0.31 -0.07 -0.33 -0.22  0.45  0.28  0.37 -0.33
## 2006  0.23  0.99  1.34  0.98 -0.57  1.74  2.49 -0.22 -1.20 -1.24 -2.05 -0.64
## 2007  0.33 -0.21 -0.13 -0.08  0.14 -0.60 -0.80  0.27  1.18  0.39  0.94  0.23
## 2008 -0.69 -0.60 -0.75 -0.13  0.78  0.41 -0.16  0.21 -0.77 -0.70 -0.08  0.49
## 2009  0.07  0.34  0.17  1.76 -0.69 -0.28 -0.09 -0.89 -0.14  0.59  0.35 -0.06
## 2010  0.21  0.40  0.53 -1.62 -0.64 -1.12 -0.86  0.09 -0.03  0.34 -0.78 -0.47
## 2011  0.05  0.89  1.18  0.77  1.65  2.31  2.17  0.84  2.55  1.08  1.62  0.62
## 2012  0.79 -0.81 -1.59 -0.65 -1.14 -1.05 -1.53 -0.90 -2.86 -2.65 -1.12 -0.91
## 2013 -0.67 -0.66  0.03  0.01  0.35 -0.08  0.39 -0.22  0.31  1.21  0.77 -0.63
## 2014 -0.32  1.62  0.12  0.62  1.08  0.16  1.01  2.81  2.18  0.09 -1.47  4.61
## 2015  1.71 -0.80 -0.01 -0.40 -1.21  0.75  0.74 -2.49 -4.22 -1.32 -1.18 -3.70
## 2016  0.38 -0.70  0.15 -0.23  0.18 -1.41
ts.plot(inflation, main = "monthly inflation rates(2005-2018)", ylab = "inflation rates", col = "blue" )

#define EGARCH (2,2) model specification
spec_garch = ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 2)),
                        mean.model = list(armaOrder = c(0, 0), include.mean = TRUE),
                        distribution.model = "norm")
summary(spec_garch)
##     Length      Class       Mode 
##          1 uGARCHspec         S4
spec_egarch = ugarchspec(variance.model = list(model = "eGARCH", garchOrder = c(2,2)), 
                         mean.model = list(armaOrder = c(0,0), Include.mean = F),
                         distribution.model = "norm"); spec_egarch
## Warning: unidentified option(s) in mean.model:
##  Include.mean
## 
## *---------------------------------*
## *       GARCH Model Spec          *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## ------------------------------------
## GARCH Model      : eGARCH(2,2)
## 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
summary(spec_egarch)
##     Length      Class       Mode 
##          1 uGARCHspec         S4
# fit the models 
spec_garchfit = ugarchfit(infl, spec = spec_garch); spec_garchfit
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : sGARCH(1,2)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.011241    0.081542 -0.13786 0.890353
## omega   0.330177    0.155076  2.12913 0.033244
## alpha1  0.703361    0.254981  2.75848 0.005807
## beta1   0.057643    0.182410  0.31601 0.751998
## beta2   0.143082    0.110543  1.29436 0.195540
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.011241    0.109043 -0.10309 0.917892
## omega   0.330177    0.187008  1.76558 0.077466
## alpha1  0.703361    0.293031  2.40029 0.016382
## beta1   0.057643    0.249570  0.23097 0.817339
## beta2   0.143082    0.083041  1.72303 0.084883
## 
## LogLikelihood : -200.8692 
## 
## Information Criteria
## ------------------------------------
##                    
## Akaike       3.0054
## Bayes        3.1120
## Shibata      3.0028
## Hannan-Quinn 3.0487
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic   p-value
## Lag[1]                      13.78 2.056e-04
## Lag[2*(p+q)+(p+q)-1][2]     15.62 6.287e-05
## Lag[4*(p+q)+(p+q)-1][5]     22.57 3.787e-06
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                      0.1846  0.6674
## Lag[2*(p+q)+(p+q)-1][8]     6.6827  0.1746
## Lag[4*(p+q)+(p+q)-1][14]   11.8023  0.1001
## d.o.f=3
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[4]     5.893 0.500 2.000 0.01520
## ARCH Lag[6]     7.359 1.461 1.711 0.03291
## ARCH Lag[8]     8.440 2.368 1.583 0.04999
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.2003
## Individual Statistics:              
## mu     0.07604
## omega  0.27726
## alpha1 0.34289
## beta1  0.08881
## beta2  0.28129
## 
## 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.4916 0.1382    
## Negative Sign Bias  0.6617 0.5093    
## Positive Sign Bias  1.2255 0.2226    
## Joint Effect        2.5521 0.4660    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     11.47       0.9071
## 2    30     17.38       0.9560
## 3    40     32.05       0.7771
## 4    50     40.74       0.7934
## 
## 
## Elapsed time : 0.07421398
plot(spec_garchfit, which = 9)

plot(spec_garchfit, which = 1)

spec_egarchfit = ugarchfit(infl, spec = spec_egarch); spec_egarchfit
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : eGARCH(2,2)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu      0.005685    0.082650  0.068787 0.945159
## omega  -0.005251    0.025098 -0.209205 0.834288
## alpha1  0.051240    0.225519  0.227210 0.820260
## alpha2  0.183285    0.163887  1.118357 0.263414
## beta1   0.788775    0.317339  2.485593 0.012934
## beta2   0.182140    0.327029  0.556953 0.577560
## gamma1  0.585607    0.261028  2.243466 0.024867
## gamma2 -0.407287    0.269173 -1.513102 0.130254
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu      0.005685     0.10178  0.055856 0.955456
## omega  -0.005251     0.03204 -0.163873 0.869831
## alpha1  0.051240     0.30340  0.168888 0.865885
## alpha2  0.183285     0.15934  1.150307 0.250018
## beta1   0.788775     0.29778  2.648834 0.008077
## beta2   0.182140     0.34257  0.531681 0.594947
## gamma1  0.585607     0.31498  1.859168 0.063003
## gamma2 -0.407287     0.31133 -1.308207 0.190803
## 
## LogLikelihood : -196.8653 
## 
## Information Criteria
## ------------------------------------
##                    
## Akaike       2.9907
## Bayes        3.1612
## Shibata      2.9844
## Hannan-Quinn 3.0600
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic   p-value
## Lag[1]                      19.66 9.253e-06
## Lag[2*(p+q)+(p+q)-1][2]     23.30 6.068e-07
## Lag[4*(p+q)+(p+q)-1][5]     33.10 4.218e-09
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                     0.01087  0.9170
## Lag[2*(p+q)+(p+q)-1][11]   6.25757  0.4018
## Lag[4*(p+q)+(p+q)-1][19]  11.83415  0.2775
## d.o.f=4
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[5]     3.301 0.500 2.000 0.06924
## ARCH Lag[7]     4.234 1.473 1.746 0.17724
## ARCH Lag[9]     5.594 2.402 1.619 0.20895
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  1.3976
## Individual Statistics:              
## mu     0.32248
## omega  0.30582
## alpha1 0.06601
## alpha2 0.06150
## beta1  0.17169
## beta2  0.19065
## gamma1 0.14688
## gamma2 0.28097
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.89 2.11 2.59
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias           1.6892 0.09354   *
## Negative Sign Bias  1.4513 0.14907    
## Positive Sign Bias  0.9934 0.32234    
## Joint Effect        3.5047 0.32016    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     16.43       0.6284
## 2    30     28.77       0.4773
## 3    40     37.89       0.5204
## 4    50     34.90       0.9359
## 
## 
## Elapsed time : 0.2112951
plot(spec_egarchfit, which = 9)

plot(spec_egarchfit, which = 1)

f = ugarchforecast(spec_garchfit, n.ahead = 60, confint = 0.95)
plot(f, which = 1)

g = ugarchforecast(spec_egarchfit, n.ahead = 60, confint = 0.95)
plot(g, which = 1) # choose EGarch because it is the best

infocriteria(spec_garchfit)
##                      
## Akaike       3.005389
## Bayes        3.111958
## Shibata      3.002848
## Hannan-Quinn 3.048696
infocriteria(spec_egarchfit)
##                      
## Akaike       2.990735
## Bayes        3.161245
## Shibata      2.984404
## Hannan-Quinn 3.060026