“09:28:05, 10 - 08 - 2024”
***
library(xlsx)
h <- read.xlsx("F:/Các mô hình ngẫu nhiên/cmhnn3.xlsx", sheetIndex=1, header=T)
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.3.3
## corrplot 0.92 loaded
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.3.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(tseries)
## Warning: package 'tseries' was built under R version 4.3.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(forecast)
## Warning: package 'forecast' was built under R version 4.3.3
library(moments)
e <- h[c(2:3409),c(4,5)]
stargazer(e,type= "text",title = "thống kê mô tả")
##
## thống kê mô tả
## ==========================================
## Statistic N Mean St. Dev. Min Max
## ------------------------------------------
## MSFT2 3,408 1.001 0.016 0.853 1.142
## INTC2 3,408 1.000 0.020 0.820 1.195
## ------------------------------------------
corrplot.mixed(cor(e), lower ="number", upper="circle",tl.col='black' ) # biểu đồ hệ số tương quan
cor(e)
## MSFT2 INTC2
## MSFT2 1.0000000 0.5544902
## INTC2 0.5544902 1.0000000
library(stats)
MSFT2 <- e$MSFT2
INTC2 <- e$INTC2
plot.ts(MSFT2)
plot.ts(INTC2)
# Kiểm định ADF
adf.test(e$MSFT2)
## Warning in adf.test(e$MSFT2): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: e$MSFT2
## Dickey-Fuller = -15.455, Lag order = 15, p-value = 0.01
## alternative hypothesis: stationary
adf.test(e$INTC2)
## Warning in adf.test(e$INTC2): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: e$INTC2
## Dickey-Fuller = -15.633, Lag order = 15, p-value = 0.01
## alternative hypothesis: stationary
# kiểm định J-B
jarque.bera.test(e$MSFT2)
##
## Jarque Bera Test
##
## data: e$MSFT2
## X-squared = 8650.2, df = 2, p-value < 2.2e-16
jarque.bera.test(e$INTC2)
##
## Jarque Bera Test
##
## data: e$INTC2
## X-squared = 16084, df = 2, p-value < 2.2e-16
# kiểm định ljung-box cho chuỗi tương quan bậc 2
library(stats)
Box.test(e$MSFT2, lag=2,type="Ljung-Box")
##
## Box-Ljung test
##
## data: e$MSFT2
## X-squared = 45.522, df = 2, p-value = 1.303e-10
Box.test(e$INTC2,lag=2, type="Ljung-Box")
##
## Box-Ljung test
##
## data: e$INTC2
## X-squared = 44.574, df = 2, p-value = 2.093e-10
# Kiểm định arch-lm
library(fGarch)
## Warning: package 'fGarch' was built under R version 4.3.3
## NOTE: Packages 'fBasics', 'timeDate', and 'timeSeries' are no longer
## attached to the search() path when 'fGarch' is attached.
##
## If needed attach them yourself in your R script by e.g.,
## require("timeSeries")
library(rugarch)
## Warning: package 'rugarch' was built under R version 4.3.3
## Loading required package: parallel
##
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
##
## sigma
arch.spec <- ugarchspec(variance.model=list(model="sGARCH"))
arch.MSFT2 <- ugarchfit(spec=arch.spec,data=e$MSFT2)
residuals <- residuals(arch.MSFT2)
n <- length(residuals)
x <- 1:n
# Tạo mô hình tuyến tính
arch_lm_model <- lm(residuals^2 ~ x + lag(residuals^2, 1))
# Kiểm định hiệu ứng ARCH-LM
arch <- bptest(arch_lm_model)
# Hiển thị kết quả
arch
##
## studentized Breusch-Pagan test
##
## data: arch_lm_model
## BP = 444, df = 2, p-value < 2.2e-16
arch.spec <- ugarchspec(variance.model=list(model="sGARCH"))
arch.INTC2 <- ugarchfit(spec=arch.spec,data=e$INTC2)
residuals1 <- residuals(arch.INTC2)
n <- length(residuals1)
x <- 1:n
# Tạo mô hình tuyến tính
arch_lm_model1 <- lm(residuals1^2 ~ x + lag(residuals1^2, 1))
# Kiểm định hiệu ứng ARCH-LM
arch1 <- bptest(arch_lm_model1)
# Hiển thị kết quả
arch1
##
## studentized Breusch-Pagan test
##
## data: arch_lm_model1
## BP = 272.46, df = 2, p-value < 2.2e-16
f <- h[c(2:3409),]
m <- f[,c(4,5)]
g <- h[,c(2,3)]
library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.3.3
## Loading required package: xts
## Warning: package 'xts' was built under R version 4.3.3
##
## Attaching package: 'PerformanceAnalytics'
## The following objects are masked from 'package:fGarch':
##
## ES, VaR
## The following objects are masked from 'package:moments':
##
## kurtosis, skewness
## The following object is masked from 'package:graphics':
##
## legend
j <- chart.Correlation(g)
## Warning in par(usr): argument 1 does not name a graphical parameter
n <- chart.Correlation(m)
## Warning in par(usr): argument 1 does not name a graphical parameter
n
## NULL
MSFT2 <- diff(f$MSFT2)
INTC2 <- diff(f$INTC2)
library(rugarch)
library(lmtest)
library(stats)
library(tseries)
library(fGarch)
# Mô hình ARIMA
autoarfima(MSFT2, ar.max=2, ma.max=2, criterion="AIC", method= "full")$fit
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(2,0,2)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000000 0.000000 63.227 0
## ar1 -1.021338 0.006352 -160.784 0
## ar2 -0.136656 0.007439 -18.370 0
## ma1 -0.102299 0.000004 -24669.192 0
## ma2 -0.900337 0.000049 -18431.534 0
## sigma 0.016175 0.000185 87.302 0
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000000 0.000000 7.2658 0.000000
## ar1 -1.021338 0.050391 -20.2681 0.000000
## ar2 -0.136656 0.039574 -3.4532 0.000554
## ma1 -0.102299 0.000020 -5238.7949 0.000000
## ma2 -0.900337 0.000213 -4226.7476 0.000000
## sigma 0.016175 0.000975 16.5815 0.000000
##
## LogLikelihood : 9208.091
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.4019
## Bayes -5.3911
## Shibata -5.4019
## Hannan-Quinn -5.3980
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2049 6.508e-01
## Lag[2*(p+q)+(p+q)-1][11] 18.3085 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 32.3548 3.184e-10
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 355.6 0
## Lag[2*(p+q)+(p+q)-1][2] 444.0 0
## Lag[4*(p+q)+(p+q)-1][5] 578.4 0
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 413.3 2 0
## ARCH Lag[5] 447.3 5 0
## ARCH Lag[10] 486.2 10 0
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 4.3434
## Individual Statistics:
## mu 0.03637
## ar1 0.01998
## ar2 0.14457
## ma1 0.07407
## ma2 0.06284
## sigma 1.64729
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.49 1.68 2.12
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.20365
autoarfima(INTC2, ar.max=2, ma.max=2, criterion="AIC", method = "full")$fit
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(2,0,2)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## ar1 -0.845848 6.0e-06 -140672.76 0
## ar2 -0.088881 1.3e-05 -7040.65 0
## ma1 -0.264613 1.1e-05 -23157.28 0
## ma2 -0.740294 2.1e-05 -35607.42 0
## sigma 0.019386 4.2e-05 465.38 0
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## ar1 -0.845848 0.000020 -41977.51 0
## ar2 -0.088881 0.000013 -6776.51 0
## ma1 -0.264613 0.000022 -12075.92 0
## ma2 -0.740294 0.000023 -32423.81 0
## sigma 0.019386 0.000115 168.67 0
##
## LogLikelihood : 8596.117
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.0432
## Bayes -5.0342
## Shibata -5.0432
## Hannan-Quinn -5.0400
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.8369 0.3603
## Lag[2*(p+q)+(p+q)-1][11] 27.3571 0.0000
## Lag[4*(p+q)+(p+q)-1][19] 45.5977 0.0000
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 405.5 0
## Lag[2*(p+q)+(p+q)-1][2] 463.1 0
## Lag[4*(p+q)+(p+q)-1][5] 549.8 0
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 421.6 2 0
## ARCH Lag[5] 447.1 5 0
## ARCH Lag[10] 468.9 10 0
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 14.4453
## Individual Statistics:
## ar1 0.02253
## ar2 0.02252
## ma1 0.02229
## ma2 0.02480
## sigma 6.10544
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.28 1.47 1.88
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.2571669
# Mô hình GJR-GARCH cho MSFT2
MSFT.garch11n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "norm")
MSFT.garch11n.fit <- ugarchfit(spec = MSFT.garch11n.spec, data = MSFT2)
MSFT.garch11t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "std")
MSFT.garch11t.fit <- ugarchfit(spec = MSFT.garch11t.spec, data = MSFT2)
MSFT.garch11st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
MSFT.garch11st.fit <- ugarchfit(spec = MSFT.garch11st.spec, data = MSFT2)
MSFT.garch11g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "ged")
MSFT.garch11g.fit <- ugarchfit(spec = MSFT.garch11g.spec, data = MSFT2)
MSFT.garch11sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sged")
MSFT.garch11sg.fit <- ugarchfit(spec = MSFT.garch11sg.spec, data = MSFT2)
MSFT.garch12n.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(1,2)), mean.model=list(armaOrder=c(2,2),include.mean= TRUE), distribution.model="norm")
MSFT.garch12n.fit <- ugarchfit(spec=MSFT.garch12n.spec, data =MSFT2)
MSFT.garch12t.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(1,2)), mean.model= list(armaOrder=c(2,2), include.mean= TRUE), distribution.model= "std")
MSFT.garch12t.fit <- ugarchfit(spec=MSFT.garch12t.spec, data=MSFT2)
MSFT.garch12st.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(1,2)), mean.model=list(armaOrder=c(2,2), include.mean=TRUE), distribution.model= "sstd")
MSFT.garch12st.fit <- ugarchfit(spec=MSFT.garch12st.spec, data=MSFT2)
MSFT.garch12g.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(1,2)), mean.model= list(armaOrder=c(2,2), include.mean= TRUE), distribution.model="ged")
MSFT.garch12g.fit <- ugarchfit(spec=MSFT.garch12g.spec, data= MSFT2)
MSFT.garch12sg.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(1,2)), mean.model=list(armaOrder=c(2,2), include.mean=TRUE), distribution.model="sged")
MSFT.garch12sg.fit <- ugarchfit(spec=MSFT.garch12sg.spec, data=MSFT2)
MSFT.garch21n.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,1)), mean.model=list(armaOrder=c(2,2),include.mean= TRUE), distribution.model="norm")
MSFT.garch21n.fit <- ugarchfit(spec=MSFT.garch21n.spec, data =MSFT2)
MSFT.garch21t.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,1)), mean.model= list(armaOrder=c(2,2), include.mean= TRUE), distribution.model= "std")
MSFT.garch21t.fit <- ugarchfit(spec=MSFT.garch21t.spec, data=MSFT2)
MSFT.garch21st.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,1)), mean.model=list(armaOrder=c(2,2), include.mean=TRUE), distribution.model= "sstd")
MSFT.garch21st.fit <- ugarchfit(spec=MSFT.garch21st.spec, data=MSFT2)
MSFT.garch21g.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,1)), mean.model= list(armaOrder=c(2,2), include.mean= TRUE), distribution.model="ged")
MSFT.garch21g.fit <- ugarchfit(spec=MSFT.garch21g.spec, data= MSFT2)
MSFT.garch21sg.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,1)), mean.model=list(armaOrder=c(2,2), include.mean=TRUE), distribution.model="sged")
MSFT.garch21sg.fit <- ugarchfit(spec=MSFT.garch21sg.spec, data=MSFT2)
MSFT.garch22n.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,2)), mean.model=list(armaOrder=c(2,2),include.mean= TRUE), distribution.model="norm")
MSFT.garch22n.fit <- ugarchfit(spec=MSFT.garch22n.spec, data =MSFT2)
MSFT.garch22t.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,2)), mean.model= list(armaOrder=c(2,2), include.mean= TRUE), distribution.model= "std")
MSFT.garch22t.fit <- ugarchfit(spec=MSFT.garch22t.spec, data=MSFT2)
MSFT.garch22st.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,2)), mean.model=list(armaOrder=c(2,2), include.mean=TRUE), distribution.model= "sstd")
MSFT.garch22st.fit <- ugarchfit(spec=MSFT.garch22st.spec, data=MSFT2)
MSFT.garch22g.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,2)), mean.model= list(armaOrder=c(2,2), include.mean= TRUE), distribution.model="ged")
MSFT.garch22g.fit <- ugarchfit(spec=MSFT.garch22g.spec, data= MSFT2)
MSFT.garch22sg.spec <- ugarchspec(variance.model=list(model="gjrGARCH", garchOrder=c(2,2)), mean.model=list(armaOrder=c(2,2), include.mean=TRUE), distribution.model="sged")
MSFT.garch22sg.fit <- ugarchfit(spec=MSFT.garch22sg.spec, data=MSFT2)
INTC.garch11n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "norm")
INTC.garch11n.fit <- ugarchfit(spec = INTC.garch11n.spec, data = INTC2)
INTC.garch11t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "std")
INTC.garch11t.fit <- ugarchfit(spec =INTC.garch11t.spec, data = INTC2)
INTC.garch11st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
INTC.garch11st.fit <- ugarchfit(spec = INTC.garch11st.spec, data = INTC2)
INTC.garch11g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "ged")
INTC.garch11g.fit <- ugarchfit(spec = INTC.garch11g.spec, data = INTC2)
INTC.garch11sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sged")
INTC.garch11sg.fit <- ugarchfit(spec = INTC.garch11sg.spec, data = INTC2)
INTC.garch12n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "norm")
INTC.garch12n.fit <- ugarchfit(spec = INTC.garch12n.spec, data = INTC2)
INTC.garch12t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "std")
INTC.garch12t.fit <- ugarchfit(spec =INTC.garch12t.spec, data = INTC2)
INTC.garch12st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
INTC.garch12st.fit <- ugarchfit(spec = INTC.garch12st.spec, data = INTC2)
INTC.garch12g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "ged")
INTC.garch12g.fit <- ugarchfit(spec = INTC.garch12g.spec, data = INTC2)
INTC.garch12sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sged")
INTC.garch12sg.fit <- ugarchfit(spec = INTC.garch12sg.spec, data = INTC2)
INTC.garch21n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "norm")
INTC.garch21n.fit <- ugarchfit(spec = INTC.garch21n.spec, data = INTC2)
INTC.garch21t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "std")
INTC.garch21t.fit <- ugarchfit(spec =INTC.garch21t.spec, data = INTC2)
INTC.garch21st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
INTC.garch21st.fit <- ugarchfit(spec = INTC.garch21st.spec, data = INTC2)
INTC.garch21g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "ged")
INTC.garch21g.fit <- ugarchfit(spec = INTC.garch21g.spec, data = INTC2)
INTC.garch21sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sged")
INTC.garch21sg.fit <- ugarchfit(spec = INTC.garch21sg.spec, data = INTC2)
INTC.garch22n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "norm")
INTC.garch22n.fit <- ugarchfit(spec = INTC.garch22n.spec, data = INTC2)
INTC.garch22t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2,2)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "std")
INTC.garch22t.fit <- ugarchfit(spec =INTC.garch22t.spec, data = INTC2)
INTC.garch22st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2,2)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
INTC.garch22st.fit <- ugarchfit(spec = INTC.garch22st.spec, data = INTC2)
INTC.garch22g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2,2)), mean.model
= list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "ged")
INTC.garch22g.fit <- ugarchfit(spec = INTC.garch22g.spec, data = INTC2)
INTC.garch22sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2,2)),
mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sged")
INTC.garch22sg.fit <- ugarchfit(spec = INTC.garch22sg.spec, data = INTC2)
safe_infocriteria <- function(model) {tryCatch(infocriteria(model),error = function(e) return(rep(NA, 4)))}
# Lựa chọn mô hình cho MSFT
MSFT.model.list <- list(garch11n = MSFT.garch11n.fit, garch11t = MSFT.garch11t.fit, garch11st = MSFT.garch11st.fit,
garch11g = MSFT.garch11g.fit, garch11sg = MSFT.garch11sg.fit, garch12n=MSFT.garch12n.fit, garch12t = MSFT.garch12t.fit, garch12st= MSFT.garch12st.fit, garch12g=MSFT.garch12g.fit, garch12sg= MSFT.garch12sg.fit, garch21n = MSFT.garch21n.fit, garch21t=MSFT.garch21t.fit, garch21st=MSFT.garch21st.fit, garch21g=MSFT.garch21g.fit, garch21sg=MSFT.garch21sg.fit, garch22n=MSFT.garch22n.fit, garch22t= MSFT.garch22t.fit, garch22st=MSFT.garch22st.fit, garch22g=MSFT.garch22g.fit, garch22sg=MSFT.garch22sg.fit)
MSFT.info.mat <- sapply(MSFT.model.list, safe_infocriteria)
## Warning in log(log(nObs)): NaNs produced
## Warning in log(log(nObs)): NaNs produced
## Warning in log(log(nObs)): NaNs produced
rownames(MSFT.info.mat) <- rownames(infocriteria(MSFT.garch11n.fit))
MSFT.info.mat
## garch11n garch11t garch11st garch11g garch11sg garch12n
## Akaike -5.563748 -5.686385 NA -5.669903 -5.669175 -5.563828
## Bayes -5.547546 -5.668382 NA -5.651900 -5.649372 -5.545825
## Shibata -5.563762 -5.686402 NA -5.669920 -5.669196 -5.563845
## Hannan-Quinn -5.557958 -5.679951 NA -5.663469 -5.662098 -5.557394
## garch12t garch12st garch12g garch12sg garch21n garch21t
## Akaike NA -5.685469 NA -5.669404 -5.566571 -5.685680
## Bayes NA -5.663865 NA -5.647800 -5.546768 -5.664077
## Shibata NA -5.685494 NA -5.669428 -5.566592 -5.685705
## Hannan-Quinn NA -5.677748 NA -5.661683 -5.559494 -5.677959
## garch21st garch21g garch21sg garch22n garch22t garch22st
## Akaike -5.685097 -5.668388 -5.669196 -5.566033 -5.685085 -5.684474
## Bayes -5.661693 -5.646785 -5.645792 -5.544430 -5.661681 -5.659270
## Shibata -5.685126 -5.668413 -5.669225 -5.566058 -5.685114 -5.684508
## Hannan-Quinn -5.676733 -5.660668 -5.660832 -5.558312 -5.676721 -5.675467
## garch22g garch22sg
## Akaike -5.668920 -5.668659
## Bayes -5.645516 -5.643455
## Shibata -5.668949 -5.668693
## Hannan-Quinn -5.660556 -5.659652
MSFT.garch11t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000001 0.000000 9.8870 0.000000
## ar1 -0.818893 0.017327 -47.2599 0.000000
## ar2 -0.050848 0.014898 -3.4130 0.000642
## ma1 -0.231509 0.000043 -5421.4160 0.000000
## ma2 -0.768805 0.000022 -34614.8879 0.000000
## omega 0.000008 0.000003 3.0123 0.002593
## alpha1 0.024102 0.001758 13.7101 0.000000
## beta1 0.885537 0.005176 171.0992 0.000000
## gamma1 0.132893 0.019150 6.9396 0.000000
## shape 4.789510 0.122497 39.0991 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000001 0.000000 2.2545e+00 0.024163
## ar1 -0.818893 0.017865 -4.5838e+01 0.000000
## ar2 -0.050848 0.018078 -2.8126e+00 0.004914
## ma1 -0.231509 0.000032 -7.3100e+03 0.000000
## ma2 -0.768805 0.000045 -1.7137e+04 0.000000
## omega 0.000008 0.000009 8.8204e-01 0.377753
## alpha1 0.024102 0.008020 3.0054e+00 0.002652
## beta1 0.885537 0.031510 2.8103e+01 0.000000
## gamma1 0.132893 0.076509 1.7370e+00 0.082393
## shape 4.789510 1.302904 3.6760e+00 0.000237
##
## LogLikelihood : 9696.757
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.6864
## Bayes -5.6684
## Shibata -5.6864
## Hannan-Quinn -5.6800
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2971 0.5856788
## Lag[2*(p+q)+(p+q)-1][11] 8.1186 0.0006846
## Lag[4*(p+q)+(p+q)-1][19] 12.2845 0.1655722
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.03131 0.8596
## Lag[2*(p+q)+(p+q)-1][5] 0.90685 0.8804
## Lag[4*(p+q)+(p+q)-1][9] 2.16413 0.8845
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.8366 0.500 2.000 0.3604
## ARCH Lag[5] 1.8868 1.440 1.667 0.4968
## ARCH Lag[7] 2.3865 2.315 1.543 0.6359
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 183.4231
## Individual Statistics:
## mu 67.29780
## ar1 0.13555
## ar2 0.08513
## ma1 0.10667
## ma2 0.11560
## omega 3.06186
## alpha1 0.47558
## beta1 0.52699
## gamma1 0.66604
## shape 1.13453
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.29 2.54 3.05
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.3296 0.7418
## Negative Sign Bias 0.2154 0.8294
## Positive Sign Bias 0.4766 0.6337
## Joint Effect 0.3437 0.9516
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 30.95 0.040873
## 2 30 49.67 0.009789
## 3 40 55.01 0.046018
## 4 50 70.80 0.022454
##
##
## Elapsed time : 1.367071
INTC.model.list <- list(garch11n = INTC.garch11n.fit, garch11t = INTC.garch11t.fit, garch11st = INTC.garch11st.fit, garch11g = INTC.garch11g.fit, garch11sg = INTC.garch11sg.fit,garch12n = INTC.garch12n.fit, garch12t = INTC.garch12t.fit, garch12st = INTC.garch12st.fit, garch12g = INTC.garch12g.fit, garch12sg = INTC.garch12sg.fit, garch21n = INTC.garch21n.fit, garch21t = INTC.garch21t.fit, garch21st = INTC.garch21st.fit, garch21g = INTC.garch21g.fit, garch21sg = INTC.garch21sg.fit, garch22n = INTC.garch22n.fit, garch22t = INTC.garch22t.fit, garch22st = INTC.garch22st.fit, garch22g = INTC.garch22g.fit, garch22sg = INTC.garch22sg.fit )
INTC.info.mat <- sapply(INTC.model.list, safe_infocriteria)
## Warning in log(log(nObs)): NaNs produced
## Warning in log(log(nObs)): NaNs produced
rownames(INTC.info.mat) <-rownames(infocriteria(INTC.garch11n.fit))
INTC.info.mat
## garch11n garch11t garch11st garch11g garch11sg garch12n
## Akaike -5.195382 NA NA -5.343292 -5.340263 -5.197554
## Bayes -5.179179 NA NA -5.325289 -5.320459 -5.179551
## Shibata -5.195396 NA NA -5.343309 -5.340283 -5.197571
## Hannan-Quinn -5.189591 NA NA -5.336859 -5.333185 -5.191120
## garch12t garch12st garch12g garch12sg garch21n garch21t
## Akaike -5.369988 -5.369173 -5.342374 -5.342555 -5.201582 -5.369752
## Bayes -5.350185 -5.347570 -5.322571 -5.320952 -5.181779 -5.348148
## Shibata -5.370009 -5.369198 -5.342395 -5.342580 -5.201603 -5.369776
## Hannan-Quinn -5.362911 -5.361453 -5.335297 -5.334835 -5.194505 -5.362031
## garch21st garch21g garch21sg garch22n garch22t garch22st
## Akaike -5.369368 -5.342739 -5.342541 -5.199918 -5.368063 -5.367605
## Bayes -5.345964 -5.321135 -5.319137 -5.178315 -5.344660 -5.342400
## Shibata -5.369397 -5.342763 -5.342570 -5.199943 -5.368092 -5.367638
## Hannan-Quinn -5.361004 -5.335018 -5.334177 -5.192198 -5.359700 -5.358597
## garch22g garch22sg
## Akaike -5.341548 -5.341463
## Bayes -5.318144 -5.316259
## Shibata -5.341576 -5.341497
## Hannan-Quinn -5.333184 -5.332456
MSFT.garch11t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000001 0.000000 9.8870 0.000000
## ar1 -0.818893 0.017327 -47.2599 0.000000
## ar2 -0.050848 0.014898 -3.4130 0.000642
## ma1 -0.231509 0.000043 -5421.4160 0.000000
## ma2 -0.768805 0.000022 -34614.8879 0.000000
## omega 0.000008 0.000003 3.0123 0.002593
## alpha1 0.024102 0.001758 13.7101 0.000000
## beta1 0.885537 0.005176 171.0992 0.000000
## gamma1 0.132893 0.019150 6.9396 0.000000
## shape 4.789510 0.122497 39.0991 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000001 0.000000 2.2545e+00 0.024163
## ar1 -0.818893 0.017865 -4.5838e+01 0.000000
## ar2 -0.050848 0.018078 -2.8126e+00 0.004914
## ma1 -0.231509 0.000032 -7.3100e+03 0.000000
## ma2 -0.768805 0.000045 -1.7137e+04 0.000000
## omega 0.000008 0.000009 8.8204e-01 0.377753
## alpha1 0.024102 0.008020 3.0054e+00 0.002652
## beta1 0.885537 0.031510 2.8103e+01 0.000000
## gamma1 0.132893 0.076509 1.7370e+00 0.082393
## shape 4.789510 1.302904 3.6760e+00 0.000237
##
## LogLikelihood : 9696.757
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.6864
## Bayes -5.6684
## Shibata -5.6864
## Hannan-Quinn -5.6800
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2971 0.5856788
## Lag[2*(p+q)+(p+q)-1][11] 8.1186 0.0006846
## Lag[4*(p+q)+(p+q)-1][19] 12.2845 0.1655722
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.03131 0.8596
## Lag[2*(p+q)+(p+q)-1][5] 0.90685 0.8804
## Lag[4*(p+q)+(p+q)-1][9] 2.16413 0.8845
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.8366 0.500 2.000 0.3604
## ARCH Lag[5] 1.8868 1.440 1.667 0.4968
## ARCH Lag[7] 2.3865 2.315 1.543 0.6359
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 183.4231
## Individual Statistics:
## mu 67.29780
## ar1 0.13555
## ar2 0.08513
## ma1 0.10667
## ma2 0.11560
## omega 3.06186
## alpha1 0.47558
## beta1 0.52699
## gamma1 0.66604
## shape 1.13453
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.29 2.54 3.05
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.3296 0.7418
## Negative Sign Bias 0.2154 0.8294
## Positive Sign Bias 0.4766 0.6337
## Joint Effect 0.3437 0.9516
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 30.95 0.040873
## 2 30 49.67 0.009789
## 3 40 55.01 0.046018
## 4 50 70.80 0.022454
##
##
## Elapsed time : 1.367071
INTC.garch12t.fit
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,2)
## Mean Model : ARFIMA(2,0,2)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000000 0.000000 -3.3097e+00 0.000934
## ar1 -0.812940 0.014539 -5.5913e+01 0.000000
## ar2 -0.003265 0.012843 -2.5420e-01 0.799341
## ma1 -0.200464 0.000025 -8.0014e+03 0.000000
## ma2 -0.801609 0.000025 -3.2454e+04 0.000000
## omega 0.000005 0.000001 3.6603e+00 0.000252
## alpha1 0.063283 0.014551 4.3490e+00 0.000014
## beta1 0.581051 0.013767 4.2205e+01 0.000000
## beta2 0.344721 0.012772 2.6989e+01 0.000000
## gamma1 0.005552 0.021024 2.6409e-01 0.791709
## shape 3.924135 0.247646 1.5846e+01 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000000 0.000001 -5.1105e-01 0.60931
## ar1 -0.812940 0.027381 -2.9690e+01 0.00000
## ar2 -0.003265 0.017564 -1.8588e-01 0.85254
## ma1 -0.200464 0.000059 -3.4099e+03 0.00000
## ma2 -0.801609 0.000121 -6.6131e+03 0.00000
## omega 0.000005 0.000003 1.4877e+00 0.13684
## alpha1 0.063283 0.108512 5.8319e-01 0.55977
## beta1 0.581051 0.011185 5.1950e+01 0.00000
## beta2 0.344721 0.010282 3.3526e+01 0.00000
## gamma1 0.005552 0.162007 3.4271e-02 0.97266
## shape 3.924135 0.361396 1.0858e+01 0.00000
##
## LogLikelihood : 9158.775
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.3700
## Bayes -5.3502
## Shibata -5.3700
## Hannan-Quinn -5.3629
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2149 0.64299
## Lag[2*(p+q)+(p+q)-1][11] 7.2209 0.02652
## Lag[4*(p+q)+(p+q)-1][19] 16.0375 0.01299
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.02078 0.8854
## Lag[2*(p+q)+(p+q)-1][8] 1.18841 0.9593
## Lag[4*(p+q)+(p+q)-1][14] 2.57887 0.9750
## d.o.f=3
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[4] 0.4877 0.500 2.000 0.4850
## ARCH Lag[6] 0.7336 1.461 1.711 0.8250
## ARCH Lag[8] 2.1742 2.368 1.583 0.7063
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 13.063
## Individual Statistics:
## mu 0.14723
## ar1 0.03030
## ar2 0.03589
## ma1 0.03996
## ma2 0.03876
## omega 1.66128
## alpha1 0.26644
## beta1 0.33400
## beta2 0.33509
## gamma1 0.16202
## shape 0.25961
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.49 2.75 3.27
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.3525 0.7245
## Negative Sign Bias 1.0564 0.2909
## Positive Sign Bias 0.8756 0.3813
## Joint Effect 2.0423 0.5637
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 24.56 0.1754
## 2 30 27.96 0.5200
## 3 40 43.34 0.2913
## 4 50 50.66 0.4078
##
##
## Elapsed time : 1.093254
MSFT.res <- residuals(MSFT.garch11t.fit)/sigma(MSFT.garch11t.fit)
fitdist(distribution="std",MSFT.res, control=list())$pars
## mu sigma shape
## 0.0008340824 1.0003331582 4.7853035512
u <- pdist(distribution="std",q=MSFT.res,mu=0.0008340824, sigma=1.0003331582, shape=4.7853035512)
INTC.res <- residuals(INTC.garch12t.fit)/sigma(INTC.garch12t.fit)
fitdist(distribution="sstd",INTC.res, control=list())$pars
## mu sigma skew shape
## -0.0189951 0.9905165 0.9715729 4.0837104
v <- pdist(distribution="sstd", INTC.res, mu=-0.0189951, sigma= 0.9905165, skew= 0.9715729, shape= 4.0837104 )
# Kiểm định Anderson-Darling
library(goftest)
ad.test(u,"punif")
##
## Anderson-Darling test of goodness-of-fit
## Null hypothesis: uniform distribution
## Parameters assumed to be fixed
##
## data: u
## An = 0.68315, p-value = 0.5731
ad.test(v,"punif")
##
## Anderson-Darling test of goodness-of-fit
## Null hypothesis: uniform distribution
## Parameters assumed to be fixed
##
## data: v
## An = 0.25327, p-value = 0.9686
# Kiểm định Cramer-von Mises
cvm.test(u,"punif")
##
## Cramer-von Mises test of goodness-of-fit
## Null hypothesis: uniform distribution
## Parameters assumed to be fixed
##
## data: u
## omega2 = 0.10406, p-value = 0.5654
cvm.test(v, "punif")
##
## Cramer-von Mises test of goodness-of-fit
## Null hypothesis: uniform distribution
## Parameters assumed to be fixed
##
## data: v
## omega2 = 0.030317, p-value = 0.9751
# Kiểm định ks-test
ks.test(u,"punif")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: u
## D = 0.015542, p-value = 0.3829
## alternative hypothesis: two-sided
ks.test(v, "punif")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: v
## D = 0.008252, p-value = 0.9745
## alternative hypothesis: two-sided
library(VineCopula)
## Warning: package 'VineCopula' was built under R version 4.3.3
cop <-BiCopSelect(u,v,familyset=1:9, selectioncrit="AIC", indeptest=FALSE,level=0.05)
summary(cop)
## Family
## ------
## No: 2
## Name: t
##
## Parameter(s)
## ------------
## par: 0.54
## par2: 5.66
## Dependence measures
## -------------------
## Kendall's tau: 0.36 (empirical = 0.37, p value < 0.01)
## Upper TD: 0.2
## Lower TD: 0.2
##
## Fit statistics
## --------------
## logLik: 593.71
## AIC: -1183.42
## BIC: -1171.15
Stu <- BiCopEst(u,v,family=9, method="mle", se=T, max.df=10)
summary(Stu)
## Family
## ------
## No: 9
## Name: BB7
##
## Parameter(s)
## ------------
## par: 1.38 (SE = 0.03)
## par2: 0.6 (SE = 0.04)
## Dependence measures
## -------------------
## Kendall's tau: 0.34 (empirical = 0.37, p value < 0.01)
## Upper TD: 0.35
## Lower TD: 0.32
##
## Fit statistics
## --------------
## logLik: 551.07
## AIC: -1098.14
## BIC: -1085.88