#a
setwd("C:/Users/Administrator/Desktop/R code/Homework(3)/Homework/HW2")
require(quantmod)
## Loading required package: quantmod
## Warning: package 'quantmod' was built under R version 3.6.1
## Loading required package: xts
## Warning: package 'xts' was built under R version 3.6.1
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.6.1
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 3.6.1
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
require(data.table)
## Loading required package: data.table
## Warning: package 'data.table' was built under R version 3.6.1
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:xts':
##
## first, last
gdp = getSymbols('GDPC96', src = 'FRED',auto.assign = F)
## '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.
gdp.df = data.frame(date = time(gdp), coredata(gdp))
x <- gdp.df[,2]
gdpGrowthRate <- diff(x)/x[-1]
m1=ar(gdpGrowthRate,method="mle")
m1
##
## Call:
## ar(x = gdpGrowthRate, method = "mle")
##
## Coefficients:
## 1 2 3
## 0.3461 0.1219 -0.0889
##
## Order selected 3 sigma^2 estimated as 7.413e-05
names(m1)
## [1] "order" "ar" "var.pred" "x.mean"
## [5] "aic" "n.used" "n.obs" "order.max"
## [9] "partialacf" "resid" "method" "series"
## [13] "frequency" "call" "asy.var.coef"
m1$aic
## 0 1 2 3 4 5
## 40.5452753 0.6242637 0.2723640 0.0000000 0.3361502 0.8715167
## 6 7 8 9 10 11
## 2.0548508 4.0485943 5.9787206 5.3812683 7.1366785 8.6820394
## 12
## 2.9745324
m1$order
## [1] 3
require(ggfortify)
## Loading required package: ggfortify
## Warning: package 'ggfortify' was built under R version 3.6.1
## Loading required package: ggplot2
autoplot(ts(m1$resid),ts.colour = "blue", ts.geom = 'ribbon', main="AR(3) fit for GDP")
Box.test(m1$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m1$resid
## X-squared = 6.4612, df = 10, p-value = 0.7751
(pv1=1-pchisq(6.4612,10-3))
## [1] 0.4870428
(m2 <- arima(gdpGrowthRate,order=c(3,0,0)))
##
## Call:
## arima(x = gdpGrowthRate, order = c(3, 0, 0))
##
## Coefficients:
## ar1 ar2 ar3 intercept
## 0.3467 0.1230 -0.0913 0.0076
## s.e. 0.0593 0.0624 0.0594 0.0008
##
## sigma^2 estimated as 7.41e-05: log likelihood = 937.35, aic = -1864.71
(mean(gdpGrowthRate))
## [1] 0.00766698
phi = 1
for (i in 1:length(m2$coef)) {
if (i == length(m2$coef)) {
(phi = phi * m2$coef[i])
} else {
phi = phi-m2$coef[i]
}
}
phi
## ar1
## 0.004750274
names(m2)
## [1] "coef" "sigma2" "var.coef" "mask" "loglik"
## [6] "aic" "arma" "residuals" "call" "series"
## [11] "code" "n.cond" "nobs" "model"
sqrt(m2$sigma2)
## [1] 0.008608056
tsdiag(m2,gof=20)
Box.test(m2$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m2$resid
## X-squared = 7.8448, df = 10, p-value = 0.644
(pv3=1-pchisq(7.8448,10-3))
## [1] 0.3464782
(m3 <- arima(gdpGrowthRate,order=c(3,0,0),fixed=c(NA,NA,0,NA)))
## Warning in arima(gdpGrowthRate, order = c(3, 0, 0), fixed = c(NA, NA, 0, :
## some AR parameters were fixed: setting transform.pars = FALSE
##
## Call:
## arima(x = gdpGrowthRate, order = c(3, 0, 0), fixed = c(NA, NA, 0, NA))
##
## Coefficients:
## ar1 ar2 ar3 intercept
## 0.3380 0.0920 0 0.0076
## s.e. 0.0593 0.0594 0 0.0009
##
## sigma^2 estimated as 7.473e-05: log likelihood = 936.18, aic = -1864.36
sprintf("The fitted model is: r[t] - 0.0076 = 0.3380*r[t-1] + 0.0920*r[t-2].")
## [1] "The fitted model is: r[t] - 0.0076 = 0.3380*r[t-1] + 0.0920*r[t-2]."
#b
(p1 <- c(1,-m2$coef[1:3]))
## ar1 ar2 ar3
## 1.00000000 -0.34671999 -0.12300655 0.09125774
(roots=polyroot(p1))
## [1] 1.834766+1.163435i -2.321630+0.000000i 1.834766-1.163435i
Mod(roots)
## [1] 2.172544 2.321630 2.172544
(k=2*pi/acos(1.834766/2.172544))
## [1] 11.11832
sprintf("The business cycle is 11 quarters.")
## [1] "The business cycle is 11 quarters."
#c
require(forecast)
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.6.1
## Registered S3 methods overwritten by 'forecast':
## method from
## autoplot.Arima ggfortify
## autoplot.acf ggfortify
## autoplot.ar ggfortify
## autoplot.bats ggfortify
## autoplot.decomposed.ts ggfortify
## autoplot.ets ggfortify
## autoplot.forecast ggfortify
## autoplot.stl ggfortify
## autoplot.ts ggfortify
## fitted.ar ggfortify
## fitted.fracdiff fracdiff
## fortify.ts ggfortify
## residuals.ar ggfortify
## residuals.fracdiff fracdiff
pre <- forecast::forecast(m2,level = c(95), h = 8)
autoplot(pre)
#d
gdplgGrowthRate <- diff(log10(x))
(m4 <- auto.arima(gdpGrowthRate, trace = TRUE))
##
## Fitting models using approximations to speed things up...
##
## ARIMA(2,1,2) with drift : Inf
## ARIMA(0,1,0) with drift : -1744.405
## ARIMA(1,1,0) with drift : -1784.41
## ARIMA(0,1,1) with drift : -1803.378
## ARIMA(0,1,0) : -1746.432
## ARIMA(1,1,1) with drift : -1832.306
## ARIMA(2,1,1) with drift : -1828.318
## ARIMA(1,1,2) with drift : -1832.232
## ARIMA(0,1,2) with drift : -1822.863
## ARIMA(2,1,0) with drift : -1789.233
## ARIMA(1,1,1) : -1834.362
## ARIMA(0,1,1) : -1805.418
## ARIMA(1,1,0) : -1786.45
## ARIMA(2,1,1) : -1829.405
## ARIMA(1,1,2) : -1834.302
## ARIMA(0,1,2) : -1824.916
## ARIMA(2,1,0) : -1791.291
## ARIMA(2,1,2) : -1841.231
## ARIMA(3,1,2) : Inf
## ARIMA(2,1,3) : -1840.713
## ARIMA(1,1,3) : -1835.161
## ARIMA(3,1,1) : -1843.294
## ARIMA(3,1,0) : -1793.939
## ARIMA(4,1,1) : -1843.505
## ARIMA(4,1,0) : -1795.686
## ARIMA(5,1,1) : -1833.796
## ARIMA(4,1,2) : -1843.529
## ARIMA(5,1,2) : -1838.415
## ARIMA(4,1,3) : -1841.818
## ARIMA(3,1,3) : Inf
## ARIMA(5,1,3) : Inf
## ARIMA(4,1,2) with drift : Inf
##
## Now re-fitting the best model(s) without approximations...
##
## ARIMA(4,1,2) : -1851.215
##
## Best model: ARIMA(4,1,2)
## Series: gdpGrowthRate
## ARIMA(4,1,2)
##
## Coefficients:
## ar1 ar2 ar3 ar4 ma1 ma2
## 0.7018 0.0027 -0.1102 -0.0555 -1.3592 0.3689
## s.e. 0.3703 0.1460 0.0870 0.0772 0.3679 0.3634
##
## sigma^2 estimated as 7.559e-05: log likelihood=932.81
## AIC=-1851.63 AICc=-1851.21 BIC=-1826.18
tsdiag(m4,gof=20)
Box.test(m4$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m4$resid
## X-squared = 5.2588, df = 10, p-value = 0.8732
(pv4=1-pchisq(5.2588,10-7))
## [1] 0.1537982
sprintf("The fitted model is ARIMA(4,1,2)")
## [1] "The fitted model is ARIMA(4,1,2)"
#e
pre1 <- forecast::forecast(m4,level = c(95), h = 8)
autoplot(pre1)
#2 #a
require(stringr)
## Loading required package: stringr
crsp <- fread("m-dec125910-5112.txt")
crspmod <- crsp[crsp$prtnam == 10]
lgcrspmod <- log10(1+crspmod$totret)
acf(lgcrspmod)
pacf(lgcrspmod)
(m5 <- arima(lgcrspmod, order = c(6,0,1)))
##
## Call:
## arima(x = lgcrspmod, order = c(6, 0, 1))
##
## Coefficients:
## Warning in sqrt(diag(x$var.coef)): 产生了NaNs
## ar1 ar2 ar3 ar4 ar5 ar6 ma1
## -0.0193 0.0088 -0.0077 -0.0041 -0.0083 -0.0231 0.2378
## s.e. NaN NaN NaN 0.0363 0.0353 0.0362 NaN
## intercept
## 0.0042
## s.e. 0.0012
##
## sigma^2 estimated as 0.0007146: log likelihood = 1638.95, aic = -3259.91
tsdiag(m5,gof=24)
Box.test(m5$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m5$resid
## X-squared = 2.3775, df = 10, p-value = 0.9925
(pv5=1-pchisq(2.3775,10-7))
## [1] 0.4978367
sprintf("The fitted model is ARMA(6,1)")
## [1] "The fitted model is ARMA(6,1)"
#b
Jan = rep(c(1,rep(0,11)),62)
(m13 <- arima(lgcrspmod,order=c(6,0,1), xreg=Jan))
##
## Call:
## arima(x = lgcrspmod, order = c(6, 0, 1), xreg = Jan)
##
## Coefficients:
## ar1 ar2 ar3 ar4 ar5 ar6 ma1 intercept
## -0.6614 0.1389 -0.0209 0.0246 0.0117 -0.0195 0.8961 0.0018
## s.e. 0.1015 0.0488 0.0447 0.0444 0.0440 0.0388 0.0948 0.0012
## Jan
## 0.0286
## s.e. 0.0033
##
## sigma^2 estimated as 0.0006508: log likelihood = 1673.74, aic = -3327.48
tsdiag(m13,gof=24)
Box.test(m13$resid,lag=24,type="Ljung")
##
## Box-Ljung test
##
## data: m13$resid
## X-squared = 17.107, df = 24, p-value = 0.844
(pv13=1-pchisq(17.107,24-7))
## [1] 0.4471399
sprintf("The fitted model is ARMA(6,1)")
## [1] "The fitted model is ARMA(6,1)"
#c
sprintf("AIC of part a model is: %s, of part b with dummy variable is %s", m5$aic , m13$aic)
## [1] "AIC of part a model is: -3259.90949269888, of part b with dummy variable is -3327.47515806744"
sprintf("Model with dummy variable has smaller AIC.")
## [1] "Model with dummy variable has smaller AIC."
sprintf("So there is seasonality in part a.")
## [1] "So there is seasonality in part a."
#3 #a
at = rnorm(1000)
rt1 = rep(0,1000)
for (t in 3:1000)
{
rt1[t] = 0.5*rt1[t-1]+1+at[t]+2*at[t-2]
}
sprintf("The model is ARMA(1,2)")
## [1] "The model is ARMA(1,2)"
rt1[1]
## [1] 0
rt1[2]
## [1] 0
#b
(m6 <- arima(rt1, order = c(1,0,2)))
##
## Call:
## arima(x = rt1, order = c(1, 0, 2))
##
## Coefficients:
## ar1 ma1 ma2 intercept
## 0.5038 0.0043 0.5430 1.7835
## s.e. 0.0395 0.0370 0.0287 0.2008
##
## sigma^2 estimated as 4.163: log likelihood = -2132.68, aic = 4275.35
Box.test(m6$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m6$resid
## X-squared = 6.5715, df = 10, p-value = 0.7652
(pv6=1-pchisq(6.7592,10-3))
## [1] 0.4543752
#c
at2 = rnorm(100)
rt3 = rep(0,100)
for (t in 3:100)
{
rt3[t] = 0.5*rt3[t-1]+1+at2[t]+2*at2[t-2]
}
(m7 <- arima(rt3, order = c(1,0,2)))
##
## Call:
## arima(x = rt3, order = c(1, 0, 2))
##
## Coefficients:
## ar1 ma1 ma2 intercept
## 0.5306 -0.1614 0.7614 2.7836
## s.e. 0.0966 0.0744 0.1774 0.7216
##
## sigma^2 estimated as 4.649: log likelihood = -219.89, aic = 449.77
Box.test(m7$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m7$resid
## X-squared = 12.812, df = 10, p-value = 0.2344
(pv7=1-pchisq(2.1461,10-3))
## [1] 0.9513132
at3 = rnorm(10000)
rt4 = rep(0,10000)
for (t in 3:10000)
{
rt4[t] = 0.5*rt4[t-1]+1+at3[t]+2*at3[t-2]
}
(m8 <- arima(rt4, order = c(1,0,2)))
##
## Call:
## arima(x = rt4, order = c(1, 0, 2))
##
## Coefficients:
## ar1 ma1 ma2 intercept
## 0.4967 0.0048 0.5021 2.1250
## s.e. 0.0130 0.0122 0.0096 0.0597
##
## sigma^2 estimated as 3.982: log likelihood = -21099.15, aic = 42208.3
Box.test(m8$resid,lag=10,type="Ljung")
##
## Box-Ljung test
##
## data: m8$resid
## X-squared = 1.1589, df = 10, p-value = 0.9997
(pv8=1-pchisq(11.844,10-3))
## [1] 0.1058071
#d
rt2 = rep(0,1000)
rt2[1] = 20
rt2[2] = 10
for (t in 3:1000)
{
rt2[t] = 0.5*rt2[t-1]+1+at[t]+2*at[t-2]
}
(diff <- rt1[1000]-rt2[1000])
## [1] 0
sprintf("Two series converges to the same value.")
## [1] "Two series converges to the same value."
#4 #a
require(aTSA)
## Loading required package: aTSA
##
## Attaching package: 'aTSA'
## The following object is masked from 'package:forecast':
##
## forecast
## The following object is masked from 'package:graphics':
##
## identify
sp <- fread("d-gmsp9908.txt")
lgrsp <- log10(1+sp$sp)
adf.test(lgrsp)
## Augmented Dickey-Fuller Test
## alternative: stationary
##
## Type 1: no drift no trend
## lag ADF p.value
## [1,] 0 -54.1 0.01
## [2,] 1 -40.4 0.01
## [3,] 2 -30.6 0.01
## [4,] 3 -27.1 0.01
## [5,] 4 -24.9 0.01
## [6,] 5 -22.2 0.01
## [7,] 6 -21.3 0.01
## [8,] 7 -19.0 0.01
## [9,] 8 -17.8 0.01
## Type 2: with drift no trend
## lag ADF p.value
## [1,] 0 -54.1 0.01
## [2,] 1 -40.4 0.01
## [3,] 2 -30.6 0.01
## [4,] 3 -27.1 0.01
## [5,] 4 -24.9 0.01
## [6,] 5 -22.3 0.01
## [7,] 6 -21.3 0.01
## [8,] 7 -19.0 0.01
## [9,] 8 -17.8 0.01
## Type 3: with drift and trend
## lag ADF p.value
## [1,] 0 -54.1 0.01
## [2,] 1 -40.4 0.01
## [3,] 2 -30.6 0.01
## [4,] 3 -27.1 0.01
## [5,] 4 -24.9 0.01
## [6,] 5 -22.3 0.01
## [7,] 6 -21.3 0.01
## [8,] 7 -19.1 0.01
## [9,] 8 -17.9 0.01
## ----
## Note: in fact, p.value = 0.01 means p.value <= 0.01
acf(lgrsp)
(m9 <- auto.arima(lgrsp))
## Series: lgrsp
## ARIMA(1,0,5) with zero mean
##
## Coefficients:
## ar1 ma1 ma2 ma3 ma4 ma5
## -0.9435 0.8693 -0.1694 -0.0505 -0.0038 -0.0736
## s.e. 0.0232 0.0303 0.0264 0.0273 0.0264 0.0200
##
## sigma^2 estimated as 3.304e-05: log likelihood=9408.89
## AIC=-18803.77 AICc=-18803.73 BIC=-18762.96
summary(m9)
## Series: lgrsp
## ARIMA(1,0,5) with zero mean
##
## Coefficients:
## ar1 ma1 ma2 ma3 ma4 ma5
## -0.9435 0.8693 -0.1694 -0.0505 -0.0038 -0.0736
## s.e. 0.0232 0.0303 0.0264 0.0273 0.0264 0.0200
##
## sigma^2 estimated as 3.304e-05: log likelihood=9408.89
## AIC=-18803.77 AICc=-18803.73 BIC=-18762.96
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -6.737119e-05 0.005741273 0.003934782 -Inf Inf 0.6666903
## ACF1
## Training set 0.0005477942
(m9 <- arima(lgrsp,order = c(1,0,5),fixed = c(NA,NA,NA,0,0,NA,NA)))
##
## Call:
## arima(x = lgrsp, order = c(1, 0, 5), fixed = c(NA, NA, NA, 0, 0, NA, NA))
##
## Coefficients:
## ar1 ma1 ma2 ma3 ma4 ma5 intercept
## -0.9376 0.8586 -0.1434 0 0 -0.0898 -1e-04
## s.e. 0.0264 0.0330 0.0238 0 0 0.0129 1e-04
##
## sigma^2 estimated as 3.301e-05: log likelihood = 9407, aic = -18802
Box.test(m9$resid , lag= 10 ,type="Ljung")
##
## Box-Ljung test
##
## data: m9$resid
## X-squared = 8.4685, df = 10, p-value = 0.5832
(pv9=1-pchisq(8.4685,10-6))
## [1] 0.07584781
arch.test(arima(m9$residuals,order = c(1,0,5),fixed = c(NA,NA,NA,0,0,NA,NA)), output = T)
## ARCH heteroscedasticity test for residuals
## alternative: heteroscedastic
##
## Portmanteau-Q test:
## order PQ p.value
## [1,] 4 981 0
## [2,] 8 2008 0
## [3,] 12 2989 0
## [4,] 16 3488 0
## [5,] 20 4052 0
## [6,] 24 4503 0
## Lagrange-Multiplier test:
## order LM p.value
## [1,] 4 1286 0.00e+00
## [2,] 8 426 0.00e+00
## [3,] 12 257 0.00e+00
## [4,] 16 179 0.00e+00
## [5,] 20 138 0.00e+00
## [6,] 24 109 4.13e-13
sprintf("The residuals of model has ARCH effect.")
## [1] "The residuals of model has ARCH effect."
#b
require(fGarch)
## Loading required package: fGarch
## Warning: package 'fGarch' was built under R version 3.6.1
## Loading required package: timeDate
## Loading required package: timeSeries
##
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo':
##
## time<-
## Loading required package: fBasics
##
## Attaching package: 'fBasics'
## The following object is masked from 'package:TTR':
##
## volatility
m10 <- garchFit(~arma(1,5)+garch(1,0), data=lgrsp,trace=F)
summary(m10)
##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~arma(1, 5) + garch(1, 0), data = lgrsp, trace = F)
##
## Mean and Variance Equation:
## data ~ arma(1, 5) + garch(1, 0)
## <environment: 0x000000002b944178>
## [data = lgrsp]
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu ar1 ma1 ma2 ma3
## 1.0193e-04 -9.2792e-01 9.2240e-01 -6.9466e-02 -1.5402e-01
## ma4 ma5 omega alpha1
## -1.8108e-01 -1.2667e-01 2.1719e-05 3.6691e-01
##
## Std. Errors:
## based on Hessian
##
## Error Analysis:
## Estimate Std. Error t value Pr(>|t|)
## mu 1.019e-04 1.367e-04 0.746 0.4558
## ar1 -9.279e-01 2.349e-02 -39.507 < 2e-16 ***
## ma1 9.224e-01 3.053e-02 30.212 < 2e-16 ***
## ma2 -6.947e-02 2.989e-02 -2.324 0.0201 *
## ma3 -1.540e-01 2.383e-02 -6.463 1.03e-10 ***
## ma4 -1.811e-01 2.623e-02 -6.903 5.09e-12 ***
## ma5 -1.267e-01 2.082e-02 -6.084 1.17e-09 ***
## omega 2.172e-05 8.444e-07 25.722 < 2e-16 ***
## alpha1 3.669e-01 3.901e-02 9.406 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log Likelihood:
## 9559.858 normalized: 3.801137
##
## Description:
## Thu Jul 25 17:36:06 2019 by user: Administrator
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 2076.958 0
## Shapiro-Wilk Test R W 0.9555867 0
## Ljung-Box Test R Q(10) 36.72935 6.302951e-05
## Ljung-Box Test R Q(15) 52.43674 4.782298e-06
## Ljung-Box Test R Q(20) 74.84259 2.893961e-08
## Ljung-Box Test R^2 Q(10) 651.2938 0
## Ljung-Box Test R^2 Q(15) 893.9215 0
## Ljung-Box Test R^2 Q(20) 1113.086 0
## LM Arch Test R TR^2 445.0252 0
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## -7.595116 -7.574253 -7.595142 -7.587544
m11 <- garchFit(~arma(1,5)+garch(1,1), data=lgrsp,trace=F)
summary(m11)
##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~arma(1, 5) + garch(1, 1), data = lgrsp, trace = F)
##
## Mean and Variance Equation:
## data ~ arma(1, 5) + garch(1, 1)
## <environment: 0x000000002b4be2e0>
## [data = lgrsp]
##
## Conditional Distribution:
## norm
##
## Coefficient(s):
## mu ar1 ma1 ma2 ma3
## 8.1638e-05 3.2976e-01 -3.9135e-01 -1.9103e-02 1.1043e-03
## ma4 ma5 omega alpha1 beta1
## -1.1260e-02 -4.8845e-02 1.9003e-07 7.1139e-02 9.2362e-01
##
## Std. Errors:
## based on Hessian
##
## Error Analysis:
## Estimate Std. Error t value Pr(>|t|)
## mu 8.164e-05 5.632e-05 1.450 0.147163
## ar1 3.298e-01 3.226e-01 1.022 0.306750
## ma1 -3.913e-01 3.225e-01 -1.214 0.224929
## ma2 -1.910e-02 3.042e-02 -0.628 0.530049
## ma3 1.104e-03 2.590e-02 0.043 0.965991
## ma4 -1.126e-02 2.270e-02 -0.496 0.619841
## ma5 -4.884e-02 2.335e-02 -2.092 0.036438 *
## omega 1.900e-07 5.540e-08 3.430 0.000604 ***
## alpha1 7.114e-02 9.069e-03 7.845 4.44e-15 ***
## beta1 9.236e-01 9.670e-03 95.513 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log Likelihood:
## 9964.893 normalized: 3.962184
##
## Description:
## Thu Jul 25 17:36:08 2019 by user: Administrator
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 250.0163 0
## Shapiro-Wilk Test R W 0.9882654 1.583518e-13
## Ljung-Box Test R Q(10) 2.693394 0.987748
## Ljung-Box Test R Q(15) 11.97102 0.6812215
## Ljung-Box Test R Q(20) 17.75231 0.6037208
## Ljung-Box Test R^2 Q(10) 14.36857 0.1568339
## Ljung-Box Test R^2 Q(15) 17.83628 0.2713705
## Ljung-Box Test R^2 Q(20) 19.51467 0.4886331
## LM Arch Test R TR^2 15.10126 0.2359456
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## -7.916416 -7.893235 -7.916447 -7.908002
m12 <- garchFit(~arma(1,5)+garch(1,1), cond.dist = c("sstd"), data=lgrsp,trace=F)
summary(m12)
##
## Title:
## GARCH Modelling
##
## Call:
## garchFit(formula = ~arma(1, 5) + garch(1, 1), data = lgrsp, cond.dist = c("sstd"),
## trace = F)
##
## Mean and Variance Equation:
## data ~ arma(1, 5) + garch(1, 1)
## <environment: 0x000000000d88f9d8>
## [data = lgrsp]
##
## Conditional Distribution:
## sstd
##
## Coefficient(s):
## mu ar1 ma1 ma2 ma3
## 8.0651e-05 2.9790e-01 -3.7251e-01 -4.2573e-02 2.4295e-03
## ma4 ma5 omega alpha1 beta1
## -1.5038e-02 -4.8351e-02 1.2200e-07 7.2390e-02 9.2556e-01
## skew shape
## 8.8944e-01 1.0000e+01
##
## Std. Errors:
## based on Hessian
##
## Error Analysis:
## Estimate Std. Error t value Pr(>|t|)
## mu 8.065e-05 5.265e-05 1.532 0.1256
## ar1 2.979e-01 3.043e-01 0.979 0.3277
## ma1 -3.725e-01 3.045e-01 -1.223 0.2212
## ma2 -4.257e-02 3.235e-02 -1.316 0.1882
## ma3 2.430e-03 2.966e-02 0.082 0.9347
## ma4 -1.504e-02 2.267e-02 -0.663 0.5071
## ma5 -4.835e-02 2.332e-02 -2.073 0.0382 *
## omega 1.220e-07 5.405e-08 2.257 0.0240 *
## alpha1 7.239e-02 1.007e-02 7.186 6.67e-13 ***
## beta1 9.256e-01 1.015e-02 91.190 < 2e-16 ***
## skew 8.894e-01 2.492e-02 35.696 < 2e-16 ***
## shape 1.000e+01 1.861e+00 5.372 7.77e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Log Likelihood:
## 10003.34 normalized: 3.97747
##
## Description:
## Thu Jul 25 17:36:12 2019 by user: Administrator
##
##
## Standardised Residuals Tests:
## Statistic p-Value
## Jarque-Bera Test R Chi^2 337.991 0
## Shapiro-Wilk Test R W 0.9864829 1.006571e-14
## Ljung-Box Test R Q(10) 5.989736 0.8161248
## Ljung-Box Test R Q(15) 15.06453 0.4467788
## Ljung-Box Test R Q(20) 20.56419 0.4231705
## Ljung-Box Test R^2 Q(10) 12.36941 0.2610935
## Ljung-Box Test R^2 Q(15) 15.94954 0.3854135
## Ljung-Box Test R^2 Q(20) 17.52376 0.6187482
## LM Arch Test R TR^2 13.03771 0.3663055
##
## Information Criterion Statistics:
## AIC BIC SIC HQIC
## -7.945397 -7.917580 -7.945443 -7.935302
sprintf("By QQplot we can see the fitted model is ARMA(1,5)+GARCH(1,1) with skewed Student-t distribution.")
## [1] "By QQplot we can see the fitted model is ARMA(1,5)+GARCH(1,1) with skewed Student-t distribution."
##b
predict(m12,4)
## meanForecast meanError standardDeviation
## 1 -0.0009553152 0.01201988 0.01201988
## 2 -0.0004903080 0.01204606 0.01201263
## 3 -0.0001035272 0.01206397 0.01200539
## 4 -0.0005164143 0.01205842 0.01199816