Important: You only need to type the quoted commands in R console

Content

  1. Student-t and skew Student-t
  2. ARCH effect test
  3. ARCH(1) model with normal innovations
  4. ARCH(1) model with Student-t innovations
  5. ARCH(1) model with skewed Student-t innovations
  6. Use ARMA(p,q)+ARCH(1) model with normal innovations

1. Student-t and skew Student-t

  • Compare skew-Student-t and Student-t distributions in fGarch package, the commands are sstd and std, respectively.
require(fGarch)
## Loading required package: fGarch
## Loading required package: timeDate
## Loading required package: timeSeries
## Loading required package: fBasics
x1 = rstd(5000,0,1,5) #(nobs, mean, sd, nu), where nu is the degrees of freedom
x2 = rsstd(5000,0,1,5,0.8)   # skew to the left (nobs, mean,sd,nu,xi) where xi is the skew parameter.
x3 = rsstd(5000,0,1,5,1.5)  # skew to the right
par(mfcol=c(1,2))
hist(x1,nclass=50)
hist(x2,nclass=50)

hist(x1,nclass=50)
hist(x3,nclass=50)

dev.off()
## null device 
##           1

2. ARCH effect test

  • Get INTC data
require(quantmod)
## Loading required package: quantmod
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following object is masked from 'package:timeSeries':
## 
##     time<-
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## 
## Attaching package: 'TTR'
## The following object is masked from 'package:fBasics':
## 
##     volatility
## Version 0.4-0 included new data defaults. See ?getSymbols.
require(aTSA)
## Loading required package: aTSA
## 
## Attaching package: 'aTSA'
## The following object is masked from 'package:graphics':
## 
##     identify
getSymbols("INTC")
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## [1] "INTC"
ret = diff(log(INTC$INTC.Adjusted))[-1]
  • Conduct test
acf(ret)  # No strong serial correlations

Box.test(ret,lag=12,type='Ljung') ## confirm no serrial correlations
## 
##  Box-Ljung test
## 
## data:  ret
## X-squared = 71.907, df = 12, p-value = 1.406e-10
t.test(ret$INTC.Adjusted)  ## Confirm mean is not zero
## 
##  One Sample t-test
## 
## data:  ret$INTC.Adjusted
## t = 1.3677, df = 3089, p-value = 0.1715
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.000195095  0.001094933
## sample estimates:
##    mean of x 
## 0.0004499191
at=ret-mean(ret)
Box.test(at^2,lag=12,type="Ljung")  # Confirm the existence of ARCH effect
## 
##  Box-Ljung test
## 
## data:  at^2
## X-squared = 1224.3, df = 12, p-value < 2.2e-16
arch.test(arima(at,order = c(1,0,0)), output = T)
## ARCH heteroscedasticity test for residuals 
## alternative: heteroscedastic 
## 
## Portmanteau-Q test: 
##      order   PQ p.value
## [1,]     4  279       0
## [2,]     8  628       0
## [3,]    12 1086       0
## [4,]    16 1326       0
## [5,]    20 1555       0
## [6,]    24 1824       0
## Lagrange-Multiplier test: 
##      order   LM p.value
## [1,]     4 3125       0
## [2,]     8 1249       0
## [3,]    12  658       0
## [4,]    16  475       0
## [5,]    20  375       0
## [6,]    24  304       0

3. ARCH(1) model with normal innovations

m2=garchFit(~garch(1,0),data=ret)  #lots of output
## 
## Series Initialization:
##  ARMA Model:                arma
##  Formula Mean:              ~ arma(0, 0)
##  GARCH Model:               garch
##  Formula Variance:          ~ garch(1, 0)
##  ARMA Order:                0 0
##  Max ARMA Order:            0
##  GARCH Order:               1 0
##  Max GARCH Order:           1
##  Maximum Order:             1
##  Conditional Dist:          norm
##  h.start:                   2
##  llh.start:                 1
##  Length of Series:          3090
##  Recursion Init:            mci
##  Series Scale:              0.01828648
## 
## Parameter Initialization:
##  Initial Parameters:          $params
##  Limits of Transformations:   $U, $V
##  Which Parameters are Fixed?  $includes
##  Parameter Matrix:
##                      U           V     params includes
##     mu     -0.24603918   0.2460392 0.02460392     TRUE
##     omega   0.00000100 100.0000000 0.10000000     TRUE
##     alpha1  0.00000001   1.0000000 0.10000000     TRUE
##     gamma1 -0.99999999   1.0000000 0.10000000    FALSE
##     delta   0.00000000   2.0000000 2.00000000    FALSE
##     skew    0.10000000  10.0000000 1.00000000    FALSE
##     shape   1.00000000  10.0000000 4.00000000    FALSE
##  Index List of Parameters to be Optimized:
##     mu  omega alpha1 
##      1      2      3 
##  Persistence:                  0.1 
## 
## 
## --- START OF TRACE ---
## Selected Algorithm: nlminb 
## 
## R coded nlminb Solver: 
## 
##   0:     9445.8928: 0.0246039 0.100000 0.100000
##   1:     4367.1446: 0.0246075  1.05789 0.387131
##   2:     4358.1482: 0.0246428  1.08236 0.283933
##   3:     4322.4163: 0.0246482 0.985590 0.240506
##   4:     4292.3436: 0.0246611 0.807974 0.179104
##   5:     4290.5874: 0.0246980 0.771357 0.363427
##   6:     4288.3954: 0.0286613 0.687104 0.315759
##   7:     4285.8916: 0.0331251 0.736061 0.313325
##   8:     4285.6799: 0.0377293 0.739665 0.296437
##   9:     4285.6748: 0.0375816 0.741976 0.291580
##  10:     4285.6741: 0.0385805 0.741679 0.292657
##  11:     4285.6737: 0.0381538 0.741650 0.292724
##  12:     4285.6737: 0.0381647 0.741677 0.292657
##  13:     4285.6737: 0.0381651 0.741675 0.292664
## 
## Final Estimate of the Negative LLH:
##  LLH:  -8079.249    norm LLH:  -2.614644 
##           mu        omega       alpha1 
## 0.0006979046 0.0002480127 0.2926641420 
## 
## R-optimhess Difference Approximated Hessian Matrix:
##                   mu        omega       alpha1
## mu     -11420017.966     -4744845     3767.851
## omega   -4744845.114 -18055327011 -2361027.444
## alpha1      3767.851     -2361027    -1070.351
## attr(,"time")
## Time difference of 0.02696395 secs
## 
## --- END OF TRACE ---
## 
## 
## Time to Estimate Parameters:
##  Time difference of 0.136991 secs
m2=garchFit(~garch(1,0),data=ret,trace=F) # no output printed.
summary(m2) # Obtain results and model checking statististics
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(1, 0), data = ret, trace = F) 
## 
## Mean and Variance Equation:
##  data ~ garch(1, 0)
## <environment: 0x000000001de7fba0>
##  [data = ret]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##         mu       omega      alpha1  
## 0.00069790  0.00024801  0.29266414  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##         Estimate  Std. Error  t value Pr(>|t|)    
## mu     6.979e-04   2.963e-04    2.356   0.0185 *  
## omega  2.480e-04   8.828e-06   28.095  < 2e-16 ***
## alpha1 2.927e-01   3.628e-02    8.068 6.66e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  8079.249    normalized:  2.614644 
## 
## Description:
##  Mon Apr 15 14:15:16 2019 by user: Sirius 
## 
## 
## Standardised Residuals Tests:
##                                 Statistic p-Value     
##  Jarque-Bera Test   R    Chi^2  3106.155  0           
##  Shapiro-Wilk Test  R    W      0.9493431 0           
##  Ljung-Box Test     R    Q(10)  37.41036  4.804912e-05
##  Ljung-Box Test     R    Q(15)  52.01586  5.614487e-06
##  Ljung-Box Test     R    Q(20)  56.76874  2.225106e-05
##  Ljung-Box Test     R^2  Q(10)  202.3313  0           
##  Ljung-Box Test     R^2  Q(15)  336.1846  0           
##  Ljung-Box Test     R^2  Q(20)  416.3516  0           
##  LM Arch Test       R    TR^2   207.4148  0           
## 
## Information Criterion Statistics:
##       AIC       BIC       SIC      HQIC 
## -5.227346 -5.221486 -5.227348 -5.225241
sresi=residuals(m2,standardize=T) # Obtain standardized residuals
#plot(m2)  # Many choices are available, choice 3 or 13 is useful.
predict(m2,6) # prediction
##   meanForecast  meanError standardDeviation
## 1 0.0006979046 0.01671452        0.01671452
## 2 0.0006979046 0.01815973        0.01815973
## 3 0.0006979046 0.01856142        0.01856142
## 4 0.0006979046 0.01867734        0.01867734
## 5 0.0006979046 0.01871114        0.01871114
## 6 0.0006979046 0.01872101        0.01872101

5. ARCH(1) model with skewed Student-t innovations

m3=garchFit(~garch(1,0),data=ret,trace=F,cond.dist=c("sstd"))
summary(m3)
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(1, 0), data = ret, cond.dist = c("sstd"), 
##     trace = F) 
## 
## Mean and Variance Equation:
##  data ~ garch(1, 0)
## <environment: 0x0000000023136370>
##  [data = ret]
## 
## Conditional Distribution:
##  sstd 
## 
## Coefficient(s):
##         mu       omega      alpha1        skew       shape  
## 0.00057427  0.00026062  0.32897650  0.96403891  3.65860874  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##         Estimate  Std. Error  t value Pr(>|t|)    
## mu     0.0005743   0.0002950    1.947   0.0516 .  
## omega  0.0002606   0.0000188   13.861  < 2e-16 ***
## alpha1 0.3289765   0.0532744    6.175 6.61e-10 ***
## skew   0.9640389   0.0226336   42.593  < 2e-16 ***
## shape  3.6586087   0.2614363   13.994  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  8316.656    normalized:  2.691475 
## 
## Description:
##  Mon Apr 15 14:15:17 2019 by user: Sirius 
## 
## 
## Standardised Residuals Tests:
##                                 Statistic p-Value     
##  Jarque-Bera Test   R    Chi^2  3127.257  0           
##  Shapiro-Wilk Test  R    W      0.9492523 0           
##  Ljung-Box Test     R    Q(10)  36.75206  6.246293e-05
##  Ljung-Box Test     R    Q(15)  51.25141  7.506414e-06
##  Ljung-Box Test     R    Q(20)  55.95154  2.95613e-05 
##  Ljung-Box Test     R^2  Q(10)  192.9461  0           
##  Ljung-Box Test     R^2  Q(15)  322.4933  0           
##  Ljung-Box Test     R^2  Q(20)  400.5649  0           
##  LM Arch Test       R    TR^2   202.4937  0           
## 
## Information Criterion Statistics:
##       AIC       BIC       SIC      HQIC 
## -5.379713 -5.369946 -5.379718 -5.376205

6. Use ARMA(p,q)+ARCH(1) model with normal innovations

  • In case needs an ARMA model for mean equation
m4=garchFit(~arma(1,1)+garch(1,0),data=ret,trace=F) #change p,q to two positive numbers, or use auto.arima to determine p, q
summary(m4)
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~arma(1, 1) + garch(1, 0), data = ret, trace = F) 
## 
## Mean and Variance Equation:
##  data ~ arma(1, 1) + garch(1, 0)
## <environment: 0x00000000230ee6b0>
##  [data = ret]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##          mu          ar1          ma1        omega       alpha1  
##  0.00068036  -0.00189955  -0.01083340   0.00024887   0.28553827  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu      6.804e-04   3.753e-04    1.813   0.0698 .  
## ar1    -1.900e-03   3.255e-01   -0.006   0.9953    
## ma1    -1.083e-02   3.386e-01   -0.032   0.9745    
## omega   2.489e-04   9.216e-06   27.003  < 2e-16 ***
## alpha1  2.855e-01   3.874e-02    7.371 1.69e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  8082.052    normalized:  2.615551 
## 
## Description:
##  Mon Apr 15 14:15:18 2019 by user: Sirius 
## 
## 
## Standardised Residuals Tests:
##                                 Statistic p-Value     
##  Jarque-Bera Test   R    Chi^2  3166.402  0           
##  Shapiro-Wilk Test  R    W      0.9490046 0           
##  Ljung-Box Test     R    Q(10)  34.85376  0.0001322463
##  Ljung-Box Test     R    Q(15)  49.62068  1.388575e-05
##  Ljung-Box Test     R    Q(20)  54.41973  5.011316e-05
##  Ljung-Box Test     R^2  Q(10)  202.323   0           
##  Ljung-Box Test     R^2  Q(15)  337.7983  0           
##  Ljung-Box Test     R^2  Q(20)  418.2603  0           
##  LM Arch Test       R    TR^2   207.2196  0           
## 
## Information Criterion Statistics:
##       AIC       BIC       SIC      HQIC 
## -5.227865 -5.218098 -5.227870 -5.224357