#Sử dụng lệnh import file dữ liệu vào R
library(PerformanceAnalytics)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
library(xlsx)
data <- read.xlsx("C:/Users/Admin/Desktop/Book1.xlsx", sheetName = 4, header = T)
LGSP <- diff(log(data$SP), lag = 1)
LGVNI <- diff(log(data$VNI), lag = 1)
mhnn <- data.frame(VNI = LGVNI, SP = LGSP)
plot.ts(mhnn$VNI)
plot.ts(mhnn$SP)
library(Hmisc)
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
res2<-rcorr(as.matrix(mhnn[,1:2]))
res2
## VNI SP
## VNI 1.0 -0.1
## SP -0.1 1.0
##
## n= 1456
##
##
## P
## VNI SP
## VNI 2e-04
## SP 2e-04
# Hệ số tương quan Pearson
res <- cor(mhnn)
round(res, 2)
## VNI SP
## VNI 1.0 -0.1
## SP -0.1 1.0
Phần này cung cấp một hàm đơn giản để định dạng ma trận tương quan vào bảng với 4 cột chứa:
Cột 1 : tên hàng
Cột 2 : tên cột
Cột 3 : các hệ số tương quan
Cột 4 : các giá trị p của các tương quan
flattenCorrMatrix <- function(cormat, pmat) {
ut <- upper.tri(cormat)
data.frame(
row = rownames(cormat)[row(cormat)[ut]],
column = rownames(cormat)[col(cormat)[ut]],
cor =(cormat)[ut],
p = pmat[ut]
)
}
flattenCorrMatrix(res2$r, res2$P)
## row column cor p
## 1 VNI SP -0.0985932 0.0001645416
symnum(res, abbr.colnames = FALSE)
## VNI SP
## VNI 1
## SP 1
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
Hàm symnum() là một trong hàm hiển thị ma trận tương quan trong phần mềm R. Nó thay thế cho các hệ số tương quan bằng các ký hiệu theo mức độ tương quan và lấy ma trận tương qaun làm đối số.
Trong đó:
res là ma trận tương quan muốn trực hóa
abbr.colnames là các giá trị logic. Nếu giá trị đúng thì các tên cột sẽ được viết tắt
library(corrplot)
## corrplot 0.92 loaded
corrplot(res, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45)
chart.Correlation(mhnn, histogram=TRUE, pch=19)
## Warning in par(usr): argument 1 does not name a graphical parameter
#-Tương tự cho các cặp biến khác.
library(ggplot2)
library(ggcorrplot)
df <- dplyr::select_if(mhnn, is.numeric)
r <- cor(df, use="complete.obs")
ggcorrplot(r)
2. THỰC HIỆN CÁC KIỂM ĐỊNH
***2.1 KIỂM ĐỊNH PHÂN PHỐI CHUẨN JARQUE - BERA
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
# kiểm định cho chỉ số VNI
Var1 <- mhnn$VNI
# Kiểm định phân phối chuẩn cho VNI
result1 <- jarque.bera.test(Var1)
print(result1)
##
## Jarque Bera Test
##
## data: Var1
## X-squared = 1032.8, df = 2, p-value < 2.2e-16
Kết quả của kiểm định sẽ bao gồm giá trị chi-squared = 101.6 và p_value= 0.00000000000000022. Ta có p_value= 0.00000000000000022 < Với alpha = 0.05 thì bác bỏ giả thuyết H0. Kết luận rằng dữ liệu tuân theo phân phối chuẩn.
2.2 Kiểm định tính dừng: Augmented Dickey–Fuller
Dưới đây là cách thực hiện kiểm định ADF
adf.test(Var1)
## Warning in adf.test(Var1): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: Var1
## Dickey-Fuller = -11.358, Lag order = 11, p-value = 0.01
## alternative hypothesis: stationary
print(adf.test(Var1))
## Warning in adf.test(Var1): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: Var1
## Dickey-Fuller = -11.358, Lag order = 11, p-value = 0.01
## alternative hypothesis: stationary
Hàm “adf.test()” sẽ trả về kết quả của kiểm định ADF, bao gồm giá trị của thống kê kiểm định và giá trị p-value. Nếu p-value nhỏ hơn một mức ý nghĩa đã chọn (ví dụ: 0.05), bạn có thể bác bỏ giả thuyết rằng chuỗi thời gian không có tính dừng.
Kết quả chạy kiểm định của kiểm định ADF trên, bao gồm giá trị của thống kê kiểm định về tính dừng là Dickey-Fuller = -7.7697 và giá trị p-value = 0.01 . Ta có p-value = 0.01 < alpha = 0.05, bạn có thể bác bỏ giả thuyết H0 . Kết luận rằng chuỗi thời gian có tính dừng.
2.3 Kiểm định tương quan chuỗi: Ljung-Box
-Trong R, bạn có thể sử dụng hàm Box.test() trong gói “stats” để thực hiện kiểm định tương quan chuỗi Ljung-Box. Kiểm định Ljung-Box được sử dụng để kiểm tra tính tương quan tự do của một chuỗi thời gian và xác định xem chuỗi có phụ thuộc tương quan không gian hay không. Giả thiết H0 là không có tương quan chuỗi Ljung-Box.
# Kiểm định tương quan chuỗi cho BID
library(stats)
result2 <- Box.test(Var1, lag = 10, type = "Ljung-Box")
print(result2)
##
## Box-Ljung test
##
## data: Var1
## X-squared = 13.627, df = 10, p-value = 0.1907
Trong đó, ‘Var1’ là vector chuỗi thời gian mà bạn muốn kiểm tra, ‘lag’ là số lượng lag mà bạn muốn sử dụng trong kiểm định, và type = “Ljung-Box” để chỉ định sử dụng kiểm định Ljung-Box.
Kết quả của kiểm định Ljung-Box sẽ bao gồm giá trị của thống kê kiểm định (Q statistic) và giá trị p-value. Giá trị p-value thường được so sánh với một mức ý nghĩa nhất định (ví dụ: 0.05) để xác định xem có sự tồn tại của tương quan không gian trong chuỗi thời gian hay không. Nếu giá trị p-value nhỏ hơn mức ý nghĩa, ta có thể kết luận rằng có sự tồn tại của tương quan không gian trong chuỗi thời gian.
Kết quả chạy kiểm định của kiểm định Ljung-Box sẽ bao gồm giá trị của thống kê kiểm định (Q statistic) = 17.381 và giá trị p-value = 0.06635. Với giá trị p-value = 0.06635 > 0.05, Chấp nhận rằng không có tương quan không gian trong chuỗi thời gian
Kiểm định mô hình ARIMA chi biến VNI
library(tseries)
library(forecast)
modeld <- auto.arima(mhnn$VNI)
modeld
## Series: mhnn$VNI
## ARIMA(1,0,1) with zero mean
##
## Coefficients:
## ar1 ma1
## 0.7056 -0.6579
## s.e. 0.1803 0.1921
##
## sigma^2 = 0.0001692: log likelihood = 4257.4
## AIC=-8508.8 AICc=-8508.79 BIC=-8492.95
Kiểm định mô hình ARIMA chi biến SP
library(tseries)
library(forecast)
modeld1 <- auto.arima(mhnn$SP)
modeld1
## Series: mhnn$SP
## ARIMA(1,0,3) with zero mean
##
## Coefficients:
## ar1 ma1 ma2 ma3
## -0.8383 0.7830 0.0331 0.1262
## s.e. 0.0661 0.0694 0.0334 0.0275
##
## sigma^2 = 0.00097: log likelihood = 2987.01
## AIC=-5964.01 AICc=-5963.97 BIC=-5937.6
# Trích xuất phần dư
d <- residuals(modeld1)
Kiểm định Arch LM cho biến VNI
library(lmtest)
library(fGarch)
## 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")
##
## Attaching package: 'fGarch'
## The following objects are masked from 'package:PerformanceAnalytics':
##
## ES, VaR
library(rugarch)
## Loading required package: parallel
##
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
##
## sigma
# Kiểm định hiệu ứng ARCH - LM cho chỉ số chứng khoán
arch_spec <- ugarchspec(variance.model = list(model = "sGARCH"))
arch_VNI <- ugarchfit(spec = arch_spec, data = mhnn$VNI)
residuals <- residuals(arch_VNI)
n <- length(residuals)
x <- 1:n
# Tạo mô hình tuyến tính
arch_lm_model <- lm(residuals^2 ~ x)
# Kiểm định hiệu ứng ARCH-LM
aTSA::arch.test(arima(mhnn$VNI, order = c(1,0,1)))
## ARCH heteroscedasticity test for residuals
## alternative: heteroscedastic
##
## Portmanteau-Q test:
## order PQ p.value
## [1,] 4 183 0
## [2,] 8 291 0
## [3,] 12 381 0
## [4,] 16 403 0
## [5,] 20 415 0
## [6,] 24 417 0
## Lagrange-Multiplier test:
## order LM p.value
## [1,] 4 1039 0.00e+00
## [2,] 8 452 0.00e+00
## [3,] 12 279 0.00e+00
## [4,] 16 206 0.00e+00
## [5,] 20 161 0.00e+00
## [6,] 24 130 1.11e-16
Kiểm định Arch LM cho biến SP
library(lmtest)
library(fGarch)
library(rugarch)
# Kiểm định hiệu ứng ARCH - LM cho chỉ số chứng khoán
arch_spec1 <- ugarchspec(variance.model = list(model = "sGARCH"))
arch_SP <- ugarchfit(spec = arch_spec1, data = mhnn$SP)
residuals1 <- residuals(arch_SP)
n1 <- length(residuals1)
x1 <- 1:n
# Tạo mô hình tuyến tính
arch_lm_model1 <- lm(residuals1^2 ~ x)
# Kiểm định hiệu ứng ARCH-LM
aTSA::arch.test(arima(mhnn$VNI, order = c(1,0,3)))
## ARCH heteroscedasticity test for residuals
## alternative: heteroscedastic
##
## Portmanteau-Q test:
## order PQ p.value
## [1,] 4 182 0
## [2,] 8 290 0
## [3,] 12 380 0
## [4,] 16 402 0
## [5,] 20 413 0
## [6,] 24 416 0
## Lagrange-Multiplier test:
## order LM p.value
## [1,] 4 1041 0
## [2,] 8 454 0
## [3,] 12 281 0
## [4,] 16 208 0
## [5,] 20 162 0
## [6,] 24 131 0
Chạy mô hình Garch cho biến VNI
library(rugarch)
VNIts<- ts(mhnn$VNI)
head(VNIts)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] 0.009892958 0.013903513 -0.006986842 0.010071073 0.010367423
## [6] 0.004392599
library(lmtest)
VNIspec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,1), include.mean =TRUE), distribution.model = 'norm')
print(VNIspec)
##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : gjrGARCH(1,1)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(1,0,1)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE
VNIfit <- ugarchfit(spec = VNIspec, VNIts)
print(VNIfit)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000053 0.000347 0.15415 0.877490
## ar1 0.666920 0.181557 3.67333 0.000239
## ma1 -0.593593 0.192340 -3.08617 0.002028
## omega 0.000009 0.000000 69.91270 0.000000
## alpha1 0.019508 0.007324 2.66345 0.007734
## beta1 0.846753 0.010055 84.21380 0.000000
## gamma1 0.140931 0.025226 5.58663 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000053 0.000360 0.14831 0.882100
## ar1 0.666920 0.195582 3.40992 0.000650
## ma1 -0.593593 0.200210 -2.96486 0.003028
## omega 0.000009 0.000000 41.11297 0.000000
## alpha1 0.019508 0.010610 1.83868 0.065963
## beta1 0.846753 0.017513 48.35068 0.000000
## gamma1 0.140931 0.039926 3.52978 0.000416
##
## LogLikelihood : 4415.501
##
## Information Criteria
## ------------------------------------
##
## Akaike -6.0556
## Bayes -6.0302
## Shibata -6.0557
## Hannan-Quinn -6.0462
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2141 0.6435
## Lag[2*(p+q)+(p+q)-1][5] 0.2824 1.0000
## Lag[4*(p+q)+(p+q)-1][9] 0.7054 1.0000
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.02747 0.8684
## Lag[2*(p+q)+(p+q)-1][5] 0.36030 0.9770
## Lag[4*(p+q)+(p+q)-1][9] 1.16223 0.9785
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.4555 0.500 2.000 0.4998
## ARCH Lag[5] 0.5727 1.440 1.667 0.8620
## ARCH Lag[7] 0.8423 2.315 1.543 0.9378
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 29.4176
## Individual Statistics:
## mu 0.16797
## ar1 0.18939
## ma1 0.19019
## omega 5.40666
## alpha1 0.09388
## beta1 0.07860
## gamma1 0.05588
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 1.69 1.9 2.35
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.4668 0.6407
## Negative Sign Bias 0.2611 0.7941
## Positive Sign Bias 1.1917 0.2336
## Joint Effect 4.2800 0.2328
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 115.4 7.889e-16
## 2 30 140.1 1.627e-16
## 3 40 154.0 1.360e-15
## 4 50 164.2 2.377e-14
##
##
## Elapsed time : 0.713167
VNIst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 1), include.mean = TRUE), distribution.model = "std")
VNIst1<- ugarchfit(VNIst.spec,VNIts)
print(VNIst1)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001018 0.000274 3.7107 0.000207
## ar1 0.716028 0.182381 3.9260 0.000086
## ma1 -0.661249 0.195621 -3.3803 0.000724
## omega 0.000014 0.000001 19.3238 0.000000
## alpha1 0.023032 0.012869 1.7898 0.073484
## beta1 0.756720 0.023623 32.0334 0.000000
## gamma1 0.286861 0.055869 5.1346 0.000000
## shape 3.814336 0.337918 11.2878 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001018 0.000274 3.7185 0.000200
## ar1 0.716028 0.200058 3.5791 0.000345
## ma1 -0.661249 0.213343 -3.0995 0.001939
## omega 0.000014 0.000001 13.5750 0.000000
## alpha1 0.023032 0.018671 1.2336 0.217354
## beta1 0.756720 0.024043 31.4731 0.000000
## gamma1 0.286861 0.055321 5.1854 0.000000
## shape 3.814336 0.339233 11.2440 0.000000
##
## LogLikelihood : 4520.285
##
## Information Criteria
## ------------------------------------
##
## Akaike -6.1982
## Bayes -6.1692
## Shibata -6.1983
## Hannan-Quinn -6.1874
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.03662 0.8482
## Lag[2*(p+q)+(p+q)-1][5] 0.16244 1.0000
## Lag[4*(p+q)+(p+q)-1][9] 0.48722 1.0000
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.002 0.3168
## Lag[2*(p+q)+(p+q)-1][5] 2.062 0.6038
## Lag[4*(p+q)+(p+q)-1][9] 2.956 0.7663
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 1.107 0.500 2.000 0.2928
## ARCH Lag[5] 1.367 1.440 1.667 0.6279
## ARCH Lag[7] 1.455 2.315 1.543 0.8303
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 36.4615
## Individual Statistics:
## mu 0.2323
## ar1 0.2051
## ma1 0.1929
## omega 6.9880
## alpha1 0.2118
## beta1 0.2150
## gamma1 0.1728
## shape 0.2147
##
## 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 0.3249 0.74528
## Negative Sign Bias 0.8731 0.38274
## Positive Sign Bias 1.7950 0.07286 *
## Joint Effect 4.0856 0.25237
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 39.96 0.003311
## 2 30 55.46 0.002191
## 3 40 77.52 0.000237
## 4 50 83.97 0.001382
##
##
## Elapsed time : 1.358474
# Phân phối Student đối xứng (sstd)
VNIst1.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 1), include.mean = TRUE), distribution.model = "sstd")
VNIst2<- ugarchfit(VNIst1.spec,VNIts)
print(VNIst2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : sstd
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000221 0.000385 0.57288 0.566724
## ar1 0.930766 0.049400 18.84132 0.000000
## ma1 -0.900316 0.059873 -15.03698 0.000000
## omega 0.000011 0.000000 27.63756 0.000000
## alpha1 0.026313 0.013132 2.00374 0.045098
## beta1 0.793324 0.019551 40.57642 0.000000
## gamma1 0.237416 0.048809 4.86419 0.000001
## skew 0.826112 0.030854 26.77454 0.000000
## shape 4.225166 0.424683 9.94899 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000221 0.000391 0.56445 0.572449
## ar1 0.930766 0.059275 15.70261 0.000000
## ma1 -0.900316 0.069935 -12.87365 0.000000
## omega 0.000011 0.000001 20.39287 0.000000
## alpha1 0.026313 0.014328 1.83652 0.066281
## beta1 0.793324 0.018489 42.90850 0.000000
## gamma1 0.237416 0.049750 4.77215 0.000002
## skew 0.826112 0.032093 25.74097 0.000000
## shape 4.225166 0.406213 10.40137 0.000000
##
## LogLikelihood : 4533.692
##
## Information Criteria
## ------------------------------------
##
## Akaike -6.2152
## Bayes -6.1826
## Shibata -6.2153
## Hannan-Quinn -6.2031
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.326 0.2495
## Lag[2*(p+q)+(p+q)-1][5] 1.681 0.9925
## Lag[4*(p+q)+(p+q)-1][9] 2.221 0.9731
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.8132 0.3672
## Lag[2*(p+q)+(p+q)-1][5] 1.8767 0.6478
## Lag[4*(p+q)+(p+q)-1][9] 2.8789 0.7788
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 1.128 0.500 2.000 0.2882
## ARCH Lag[5] 1.430 1.440 1.667 0.6109
## ARCH Lag[7] 1.530 2.315 1.543 0.8154
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 45.8852
## Individual Statistics:
## mu 0.18304
## ar1 0.17696
## ma1 0.18710
## omega 10.07591
## alpha1 0.16604
## beta1 0.17542
## gamma1 0.11746
## skew 0.09913
## shape 0.15464
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.1 2.32 2.82
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.5696 0.5691
## Negative Sign Bias 1.0569 0.2908
## Positive Sign Bias 1.4288 0.1533
## Joint Effect 4.3787 0.2234
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 35.13 0.013485
## 2 30 48.99 0.011587
## 3 40 69.66 0.001827
## 4 50 88.23 0.000500
##
##
## Elapsed time : 1.519749
# Phân phối Generalized Error Distribution(ged)
VNIged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 1), include.mean = TRUE), distribution.model = "ged")
VNIged1 <- ugarchfit(VNIged.spec,VNIts)
print(VNIged1)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : ged
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001038 0.000201 5.1696 0.000000
## ar1 0.905263 0.014013 64.6008 0.000000
## ma1 -0.879578 0.015421 -57.0390 0.000000
## omega 0.000011 0.000000 34.7734 0.000000
## alpha1 0.023393 0.013101 1.7856 0.074167
## beta1 0.792164 0.018859 42.0048 0.000000
## gamma1 0.200743 0.043688 4.5949 0.000004
## shape 1.059431 0.046569 22.7495 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.001038 0.000147 7.0705 0.000000
## ar1 0.905263 0.006944 130.3748 0.000000
## ma1 -0.879578 0.006909 -127.3072 0.000000
## omega 0.000011 0.000000 28.2435 0.000000
## alpha1 0.023393 0.014657 1.5960 0.110488
## beta1 0.792164 0.020306 39.0119 0.000000
## gamma1 0.200743 0.044948 4.4662 0.000008
## shape 1.059431 0.051226 20.6816 0.000000
##
## LogLikelihood : 4514.375
##
## Information Criteria
## ------------------------------------
##
## Akaike -6.1901
## Bayes -6.1610
## Shibata -6.1901
## Hannan-Quinn -6.1792
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.193 0.2748
## Lag[2*(p+q)+(p+q)-1][5] 1.551 0.9970
## Lag[4*(p+q)+(p+q)-1][9] 2.046 0.9825
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.5575 0.4553
## Lag[2*(p+q)+(p+q)-1][5] 1.2911 0.7910
## Lag[4*(p+q)+(p+q)-1][9] 2.1408 0.8876
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.8606 0.500 2.000 0.3536
## ARCH Lag[5] 1.0323 1.440 1.667 0.7234
## ARCH Lag[7] 1.1390 2.315 1.543 0.8899
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 39.1533
## Individual Statistics:
## mu 0.2049
## ar1 0.1822
## ma1 0.2122
## omega 10.0284
## alpha1 0.1900
## beta1 0.1440
## gamma1 0.1369
## shape 0.1329
##
## 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 0.1599 0.8730
## Negative Sign Bias 0.4325 0.6655
## Positive Sign Bias 1.6441 0.1004
## Joint Effect 3.3740 0.3375
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 49.08 1.786e-04
## 2 30 63.82 2.020e-04
## 3 40 78.95 1.603e-04
## 4 50 115.36 2.838e-07
##
##
## Elapsed time : 1.496572
# Phân phối Generalized Error Distribution đối xứng ("sged")
VNIged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 1), include.mean = TRUE), distribution.model = "sged")
VNIged2 <- ugarchfit(VNIged.spec,VNIts)
print(VNIged2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,1)
## Distribution : sged
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000024 0.001160 -0.020762 0.983436
## ar1 0.934056 0.010956 85.253720 0.000000
## ma1 -0.910876 0.012910 -70.557952 0.000000
## omega 0.000010 0.000000 99.089419 0.000000
## alpha1 0.027659 0.019937 1.387285 0.165355
## beta1 0.802164 0.018447 43.485691 0.000000
## gamma1 0.189306 0.043910 4.311266 0.000016
## skew 0.865785 0.053303 16.242611 0.000000
## shape 1.119654 0.059852 18.706989 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000024 0.003666 -0.006568 0.994760
## ar1 0.934056 0.006166 151.496363 0.000000
## ma1 -0.910876 0.007857 -115.935447 0.000000
## omega 0.000010 0.000001 8.775982 0.000000
## alpha1 0.027659 0.054142 0.510857 0.609451
## beta1 0.802164 0.029234 27.439287 0.000000
## gamma1 0.189306 0.047965 3.946770 0.000079
## skew 0.865785 0.161506 5.360691 0.000000
## shape 1.119654 0.111324 10.057620 0.000000
##
## LogLikelihood : 4529.199
##
## Information Criteria
## ------------------------------------
##
## Akaike -6.2091
## Bayes -6.1764
## Shibata -6.2091
## Hannan-Quinn -6.1969
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.938 0.1639
## Lag[2*(p+q)+(p+q)-1][5] 2.609 0.7176
## Lag[4*(p+q)+(p+q)-1][9] 3.079 0.8783
## d.o.f=2
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.5409 0.4620
## Lag[2*(p+q)+(p+q)-1][5] 1.4033 0.7637
## Lag[4*(p+q)+(p+q)-1][9] 2.3674 0.8569
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.964 0.500 2.000 0.3262
## ARCH Lag[5] 1.197 1.440 1.667 0.6756
## ARCH Lag[7] 1.319 2.315 1.543 0.8567
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 42.585
## Individual Statistics:
## mu 0.11798
## ar1 0.16000
## ma1 0.19920
## omega 10.83707
## alpha1 0.16738
## beta1 0.14305
## gamma1 0.12220
## skew 0.04870
## shape 0.09903
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.1 2.32 2.82
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.9297 0.3527
## Negative Sign Bias 0.8570 0.3916
## Positive Sign Bias 1.1469 0.2516
## Joint Effect 4.4404 0.2177
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 35.95 0.010704
## 2 30 56.94 0.001461
## 3 40 61.03 0.013569
## 4 50 79.44 0.003847
##
##
## Elapsed time : 2.558296
#Tạo danh sách mô hình lựa chọn
VNI.model.list <- list(
garch11n = VNIfit,
garch11t = VNIst1,
garch11st = VNIst2,
garch11g = VNIged1,
garch11sg = VNIged2
)
#Tính toán lựa chọn mô hình
VNI.info.mat <- sapply(VNI.model.list, infocriteria)
rownames(VNI.info.mat) <- rownames(infocriteria(VNIfit))
VNI.info.mat
## garch11n garch11t garch11st garch11g garch11sg
## Akaike -6.055633 -6.198194 -6.215237 -6.190075 -6.209065
## Bayes -6.030232 -6.169164 -6.182578 -6.161045 -6.176406
## Shibata -6.055679 -6.198254 -6.215312 -6.190135 -6.209140
## Hannan-Quinn -6.046156 -6.187363 -6.203052 -6.179244 -6.196880
Dựa trên giá trị thông tin tiêu chuẩn, mô hình garch11sg có giá trị Akaike thấp nhất (-4.918553) và giá trị Hannan-Quinn thấp nhất (-4.885316). Điều này cho thấy mô hình GARCH(1,1) với phân phối ged này có khả năng phù hợp tốt với chuỗi dữ liệu VNI.
# Trích xuất chuỗi phần dư v của chuỗi lợi suất AGR
VNI.res <- residuals(VNIst2)/sigma(VNIst2)
fitdist(distribution = "sstd", VNI.res, control = list())
## $pars
## mu sigma skew shape
## -0.002561478 1.004907594 0.824890563 4.185212611
##
## $convergence
## [1] 0
##
## $values
## [1] 2123.460 1940.262 1940.262
##
## $lagrange
## [1] 0
##
## $hessian
## [,1] [,2] [,3] [,4]
## [1,] 2125.764996 344.3399 -733.5291 9.093034
## [2,] 344.339858 1931.7503 267.5525 126.560037
## [3,] -733.529104 267.5525 1312.4802 32.199100
## [4,] 9.093034 126.5600 32.1991 12.706451
##
## $ineqx0
## NULL
##
## $nfuneval
## [1] 95
##
## $outer.iter
## [1] 2
##
## $elapsed
## Time difference of 0.1111629 secs
##
## $vscale
## [1] 1 1 1 1 1
VNI.res
## m.c.seq.row..seq.n...seq.col..drop...FALSE.
## 0001-01-01 0.74300143
## 0002-01-01 1.10190861
## 0003-01-01 -0.68523195
## 0004-01-01 0.82212241
## 0005-01-01 0.87367952
## 0006-01-01 0.31684249
## 0007-01-01 0.86769430
## 0008-01-01 0.05301183
## 0009-01-01 1.20869096
## 0010-01-01 -3.22580170
## ...
## 1447-01-01 -0.70735170
## 1448-01-01 -0.91221196
## 1449-01-01 0.40810654
## 1450-01-01 0.41754288
## 1451-01-01 0.16137727
## 1452-01-01 0.06000926
## 1453-01-01 1.94068930
## 1454-01-01 -0.09064579
## 1455-01-01 0.65038104
## 1456-01-01 0.02398820
s = pdist("sstd",VNI.res, mu =-0.002561478
, sigma = 1.004907594, skew = 0.824890563, shape = 4.185212611 )
head(s,10)
## [1] 0.816380372 0.911509771 0.192272699 0.842873666 0.858348106 0.621976177
## [7] 0.856622444 0.484474324 0.929129150 0.007991471
Chạy mô hình Garch cho biến SP
library(rugarch)
SPts<- ts(mhnn$SP)
head(SPts,10)
## Time Series:
## Start = 1
## End = 10
## Frequency = 1
## [1] -0.015249562 0.004716990 -0.007083855 -0.004750603 0.000000000
## [6] -0.011976191 -0.007255171 0.001212856 0.026317308 -0.009489988
library(lmtest)
SPspec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,3), include.mean =TRUE), distribution.model = 'norm')
print(SPspec)
##
## *---------------------------------*
## * GARCH Model Spec *
## *---------------------------------*
##
## Conditional Variance Dynamics
## ------------------------------------
## GARCH Model : gjrGARCH(1,1)
## Variance Targeting : FALSE
##
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model : ARFIMA(1,0,3)
## Include Mean : TRUE
## GARCH-in-Mean : FALSE
##
## Conditional Distribution
## ------------------------------------
## Distribution : norm
## Includes Skew : FALSE
## Includes Shape : FALSE
## Includes Lambda : FALSE
SPfit <- ugarchfit(spec = SPspec, SPts)
print(SPfit)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,3)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000964 0.000568 -1.697332 0.089634
## ar1 -0.017458 0.683164 -0.025555 0.979612
## ma1 -0.020226 0.683345 -0.029598 0.976388
## ma2 0.047765 0.034936 1.367224 0.171555
## ma3 -0.058700 0.045895 -1.278996 0.200899
## omega 0.000076 0.000011 7.010697 0.000000
## alpha1 0.496245 0.059666 8.317027 0.000000
## beta1 0.627746 0.032231 19.476184 0.000000
## gamma1 -0.367285 0.062669 -5.860689 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000964 0.000615 -1.566491 0.117234
## ar1 -0.017458 1.201596 -0.014529 0.988408
## ma1 -0.020226 1.196659 -0.016902 0.986515
## ma2 0.047765 0.048602 0.982782 0.325715
## ma3 -0.058700 0.075233 -0.780240 0.435250
## omega 0.000076 0.000017 4.585999 0.000005
## alpha1 0.496245 0.135114 3.672787 0.000240
## beta1 0.627746 0.048519 12.938125 0.000000
## gamma1 -0.367285 0.127536 -2.879841 0.003979
##
## LogLikelihood : 3336.399
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.5706
## Bayes -4.5379
## Shibata -4.5707
## Hannan-Quinn -4.5584
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.208 0.2718
## Lag[2*(p+q)+(p+q)-1][11] 3.516 1.0000
## Lag[4*(p+q)+(p+q)-1][19] 5.547 0.9849
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.06248 0.8026
## Lag[2*(p+q)+(p+q)-1][5] 1.09912 0.8369
## Lag[4*(p+q)+(p+q)-1][9] 1.84159 0.9230
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.6871 0.500 2.000 0.4072
## ARCH Lag[5] 1.1119 1.440 1.667 0.7000
## ARCH Lag[7] 1.5363 2.315 1.543 0.8141
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.1983
## Individual Statistics:
## mu 0.07357
## ar1 0.08018
## ma1 0.08118
## ma2 0.15258
## ma3 0.04828
## omega 0.06277
## alpha1 0.12663
## beta1 0.05416
## gamma1 0.06861
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.1 2.32 2.82
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 1.392 0.1642
## Negative Sign Bias 1.273 0.2031
## Positive Sign Bias 1.270 0.2044
## Joint Effect 3.315 0.3456
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 126.6 6.293e-18
## 2 30 136.5 7.161e-16
## 3 40 150.4 5.294e-15
## 4 50 176.6 2.635e-16
##
##
## Elapsed time : 0.9334941
SPst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 3), include.mean = TRUE), distribution.model = "std")
SPst1<- ugarchfit(SPst.spec,SPts)
print(SPst1)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,3)
## Distribution : std
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.002147 0.000312 -6.8921 0.000000
## ar1 0.932056 0.009188 101.4447 0.000000
## ma1 -0.959299 0.000255 -3766.4101 0.000000
## ma2 0.036128 0.027082 1.3340 0.182196
## ma3 -0.036241 0.027388 -1.3232 0.185755
## omega 0.000066 0.000012 5.4684 0.000000
## alpha1 0.306359 0.051519 5.9465 0.000000
## beta1 0.703525 0.035218 19.9762 0.000000
## gamma1 -0.205266 0.062077 -3.3066 0.000944
## shape 4.635810 0.558049 8.3072 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.002147 0.000320 -6.7002 0.000000
## ar1 0.932056 0.008893 104.8086 0.000000
## ma1 -0.959299 0.000221 -4347.3849 0.000000
## ma2 0.036128 0.025265 1.4300 0.152731
## ma3 -0.036241 0.025565 -1.4176 0.156315
## omega 0.000066 0.000010 6.3913 0.000000
## alpha1 0.306359 0.051184 5.9854 0.000000
## beta1 0.703525 0.031596 22.2664 0.000000
## gamma1 -0.205266 0.064221 -3.1962 0.001392
## shape 4.635810 0.609487 7.6061 0.000000
##
## LogLikelihood : 3428.267
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.6954
## Bayes -4.6591
## Shibata -4.6955
## Hannan-Quinn -4.6819
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2858 0.5929
## Lag[2*(p+q)+(p+q)-1][11] 1.1982 1.0000
## Lag[4*(p+q)+(p+q)-1][19] 3.5589 0.9998
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.8016 0.3706
## Lag[2*(p+q)+(p+q)-1][5] 1.1134 0.8335
## Lag[4*(p+q)+(p+q)-1][9] 1.6140 0.9457
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.2575 0.500 2.000 0.6118
## ARCH Lag[5] 0.3875 1.440 1.667 0.9162
## ARCH Lag[7] 0.7854 2.315 1.543 0.9458
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.7084
## Individual Statistics:
## mu 0.55521
## ar1 0.06565
## ma1 0.02805
## ma2 0.03253
## ma3 0.02795
## omega 0.12319
## alpha1 0.04166
## beta1 0.05288
## gamma1 0.03196
## shape 0.18969
##
## 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 1.4429 0.1493
## Negative Sign Bias 1.5601 0.1190
## Positive Sign Bias 0.4563 0.6482
## Joint Effect 2.9917 0.3929
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 78.64 3.183e-09
## 2 30 92.34 1.583e-08
## 3 40 95.10 1.378e-06
## 4 50 106.64 3.694e-06
##
##
## Elapsed time : 3.337131
# Phân phối Student đối xứng (sstd)
SPst1.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 3), include.mean = TRUE), distribution.model = "sstd")
SPst2<- ugarchfit(SPst1.spec,SPts)
print(SPst2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,3)
## Distribution : sstd
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000276 0.000576 -0.47888 0.632022
## ar1 -0.934914 0.029832 -31.33942 0.000000
## ma1 0.936173 0.035914 26.06699 0.000000
## ma2 0.012901 0.029016 0.44463 0.656585
## ma3 0.023316 0.008344 2.79440 0.005200
## omega 0.000064 0.000011 5.69266 0.000000
## alpha1 0.347782 0.054265 6.40891 0.000000
## beta1 0.714437 0.030710 23.26406 0.000000
## gamma1 -0.255610 0.062337 -4.10046 0.000041
## skew 1.422404 0.054121 26.28169 0.000000
## shape 4.897659 0.626937 7.81205 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000276 0.000588 -0.46942 0.638771
## ar1 -0.934914 0.038341 -24.38392 0.000000
## ma1 0.936173 0.038075 24.58738 0.000000
## ma2 0.012901 0.024317 0.53056 0.595726
## ma3 0.023316 0.018712 1.24602 0.212759
## omega 0.000064 0.000011 6.08979 0.000000
## alpha1 0.347782 0.052813 6.58523 0.000000
## beta1 0.714437 0.030149 23.69697 0.000000
## gamma1 -0.255610 0.060938 -4.19462 0.000027
## skew 1.422404 0.059584 23.87220 0.000000
## shape 4.897659 0.688101 7.11765 0.000000
##
## LogLikelihood : 3466.724
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.7469
## Bayes -4.7070
## Shibata -4.7470
## Hannan-Quinn -4.7320
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.830e-07 0.9997
## Lag[2*(p+q)+(p+q)-1][11] 1.560e+00 1.0000
## Lag[4*(p+q)+(p+q)-1][19] 3.284e+00 0.9999
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.9534 0.3289
## Lag[2*(p+q)+(p+q)-1][5] 1.3372 0.7798
## Lag[4*(p+q)+(p+q)-1][9] 1.9367 0.9124
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.3620 0.500 2.000 0.5474
## ARCH Lag[5] 0.4958 1.440 1.667 0.8849
## ARCH Lag[7] 0.8968 2.315 1.543 0.9298
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.717
## Individual Statistics:
## mu 0.34937
## ar1 0.16740
## ma1 0.20074
## ma2 0.21635
## ma3 0.16811
## omega 0.23742
## alpha1 0.03138
## beta1 0.07397
## gamma1 0.03487
## skew 0.15104
## shape 0.09017
##
## 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 1.9697 0.04906 **
## Negative Sign Bias 1.7504 0.08026 *
## Positive Sign Bias 0.7439 0.45704
## Joint Effect 4.6802 0.19677
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 20.26 0.3789
## 2 30 22.28 0.8083
## 3 40 28.18 0.9005
## 4 50 43.86 0.6809
##
##
## Elapsed time : 2.131378
# Phân phối Generalized Error Distribution(ged)
SPged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 3), include.mean = TRUE), distribution.model = "ged")
SPged1 <- ugarchfit(SPged.spec,SPts)
print(SPged1)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,3)
## Distribution : ged
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.002312 0.000527 -4.38323 0.000012
## ar1 -0.931861 0.023616 -39.45913 0.000000
## ma1 0.898678 0.017552 51.20100 0.000000
## ma2 -0.015099 0.000645 -23.40881 0.000000
## ma3 0.026722 0.027857 0.95928 0.337415
## omega 0.000065 0.000012 5.36313 0.000000
## alpha1 0.358810 0.056251 6.37868 0.000000
## beta1 0.675678 0.038460 17.56847 0.000000
## gamma1 -0.233778 0.066121 -3.53563 0.000407
## shape 1.233300 0.054771 22.51741 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.002312 0.000547 -4.22553 0.000024
## ar1 -0.931861 0.035572 -26.19644 0.000000
## ma1 0.898678 0.007099 126.59162 0.000000
## ma2 -0.015099 0.044130 -0.34215 0.732240
## ma3 0.026722 0.028344 0.94280 0.345785
## omega 0.000065 0.000011 6.05804 0.000000
## alpha1 0.358810 0.064372 5.57397 0.000000
## beta1 0.675678 0.037570 17.98434 0.000000
## gamma1 -0.233778 0.077524 -3.01556 0.002565
## shape 1.233300 0.078781 15.65477 0.000000
##
## LogLikelihood : 3402.019
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.6594
## Bayes -4.6231
## Shibata -4.6595
## Hannan-Quinn -4.6458
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.6171 0.4321
## Lag[2*(p+q)+(p+q)-1][11] 2.3293 1.0000
## Lag[4*(p+q)+(p+q)-1][19] 4.1475 0.9991
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.3651 0.5457
## Lag[2*(p+q)+(p+q)-1][5] 0.9121 0.8792
## Lag[4*(p+q)+(p+q)-1][9] 1.6103 0.9461
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.5035 0.500 2.000 0.4780
## ARCH Lag[5] 0.6873 1.440 1.667 0.8273
## ARCH Lag[7] 1.2180 2.315 1.543 0.8757
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.4605
## Individual Statistics:
## mu 0.14775
## ar1 0.14751
## ma1 0.18778
## ma2 0.21650
## ma3 0.20296
## omega 0.04790
## alpha1 0.12052
## beta1 0.05121
## gamma1 0.06071
## shape 0.11794
##
## 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 1.5075 0.1319
## Negative Sign Bias 1.3139 0.1891
## Positive Sign Bias 0.8234 0.4104
## Joint Effect 2.8366 0.4175
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 113.3 1.925e-15
## 2 30 127.6 2.469e-14
## 3 40 134.7 1.844e-12
## 4 50 146.1 1.349e-11
##
##
## Elapsed time : 2.813984
# Phân phối Generalized Error Distribution đối xứng ("sged")
SPged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 3), include.mean = TRUE), distribution.model = "sged")
SPged2 <- ugarchfit(SPged.spec,SPts)
print(SPged2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(1,0,3)
## Distribution : sged
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000439 0.000458 -0.95836 0.337880
## ar1 -0.927909 0.014722 -63.02667 0.000000
## ma1 0.931165 0.013869 67.14018 0.000000
## ma2 0.027768 0.028087 0.98864 0.322841
## ma3 0.037760 0.007773 4.85812 0.000001
## omega 0.000063 0.000011 5.72535 0.000000
## alpha1 0.370042 0.038074 9.71892 0.000000
## beta1 0.698329 0.035504 19.66903 0.000000
## gamma1 -0.268442 0.025286 -10.61617 0.000000
## skew 1.418735 0.042935 33.04387 0.000000
## shape 1.222529 0.056626 21.58936 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000439 0.000540 -0.81261 0.416442
## ar1 -0.927909 0.018251 -50.84065 0.000000
## ma1 0.931165 0.013676 68.08990 0.000000
## ma2 0.027768 0.041190 0.67415 0.500213
## ma3 0.037760 0.026447 1.42778 0.153355
## omega 0.000063 0.000015 4.15096 0.000033
## alpha1 0.370042 0.046032 8.03880 0.000000
## beta1 0.698329 0.043789 15.94753 0.000000
## gamma1 -0.268442 0.043314 -6.19762 0.000000
## skew 1.418735 0.053539 26.49920 0.000000
## shape 1.222529 0.071044 17.20798 0.000000
##
## LogLikelihood : 3454.682
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.7303
## Bayes -4.6904
## Shibata -4.7304
## Hannan-Quinn -4.7154
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.001515 0.9689
## Lag[2*(p+q)+(p+q)-1][11] 1.490107 1.0000
## Lag[4*(p+q)+(p+q)-1][19] 3.213697 1.0000
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.6812 0.4092
## Lag[2*(p+q)+(p+q)-1][5] 1.1716 0.8198
## Lag[4*(p+q)+(p+q)-1][9] 1.8032 0.9272
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.4388 0.500 2.000 0.5077
## ARCH Lag[5] 0.5940 1.440 1.667 0.8556
## ARCH Lag[7] 0.9980 2.315 1.543 0.9139
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.779
## Individual Statistics:
## mu 0.41702
## ar1 0.12901
## ma1 0.16161
## ma2 0.17799
## ma3 0.12516
## omega 0.24520
## alpha1 0.03539
## beta1 0.09293
## gamma1 0.06358
## skew 0.09034
## shape 0.11509
##
## 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 1.8608 0.06297 *
## Negative Sign Bias 1.5805 0.11422
## Positive Sign Bias 0.9004 0.36807
## Joint Effect 4.1341 0.24734
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 19.44 0.4290
## 2 30 30.73 0.3782
## 3 40 37.46 0.5401
## 4 50 45.92 0.5986
##
##
## Elapsed time : 4.256432
#Tạo danh sách mô hình lựa chọn
SP.model.list <- list(
garchn = SPfit,
garcht = SPst1,
garchst = SPst2,
garchg = SPged1,
garchsg = SPged2
)
#Tính toán lựa chọn mô hình
SP.info.mat <- sapply(SP.model.list, infocriteria)
rownames(SP.info.mat) <- rownames(infocriteria(SPfit))
SP.info.mat
## garchn garcht garchst garchg garchsg
## Akaike -4.570604 -4.695422 -4.746873 -4.659367 -4.730333
## Bayes -4.537945 -4.659135 -4.706957 -4.623080 -4.690417
## Shibata -4.570679 -4.695516 -4.746986 -4.659461 -4.730446
## Hannan-Quinn -4.558419 -4.681884 -4.731981 -4.645829 -4.715441
Dựa trên giá trị thông tin tiêu chuẩn, mô hình garch11sg có giá trị Akaike thấp nhất (-4.746873) và giá trị Hannan-Quinn thấp nhất (-4.731981). Điều này cho thấy mô hình GARCH(1,1) với phân phối ged này có khả năng phù hợp tốt với chuỗi dữ liệu VNI.
# Trích xuất chuỗi phần dư v của chuỗi lợi suất AGR
SP.res <- residuals(SPst2)/sigma(SPst2)
fitdist(distribution = "sstd", SP.res, control = list())
## $pars
## mu sigma skew shape
## -0.006575876 0.989105807 1.415881015 5.013324705
##
## $convergence
## [1] 0
##
## $values
## [1] 1924.810 1917.143 1917.143
##
## $lagrange
## [1] 0
##
## $hessian
## [,1] [,2] [,3] [,4]
## [1,] 2363.45682 -1030.3193 -272.865075 -33.479312
## [2,] -1030.31928 2098.0988 -156.476396 82.546102
## [3,] -272.86507 -156.4764 407.030615 -6.937203
## [4,] -33.47931 82.5461 -6.937203 5.792583
##
## $ineqx0
## NULL
##
## $nfuneval
## [1] 95
##
## $outer.iter
## [1] 2
##
## $elapsed
## Time difference of 0.09908509 secs
##
## $vscale
## [1] 1 1 1 1 1
SP.res
## m.c.seq.row..seq.n...seq.col..drop...FALSE.
## 0001-01-01 -0.478279238
## 0002-01-01 0.160081952
## 0003-01-01 -0.212049444
## 0004-01-01 -0.156576909
## 0005-01-01 0.005014585
## 0006-01-01 -0.505904677
## 0007-01-01 -0.344827140
## 0008-01-01 0.094558967
## 0009-01-01 1.450937535
## 0010-01-01 -0.388843838
## ...
## 1447-01-01 1.651109206
## 1448-01-01 0.452600163
## 1449-01-01 1.172931949
## 1450-01-01 1.509933540
## 1451-01-01 -0.424221566
## 1452-01-01 -0.336425105
## 1453-01-01 -0.416797585
## 1454-01-01 -1.203686717
## 1455-01-01 -0.065401725
## 1456-01-01 0.095981416
s1 = pdist("sstd",SP.res, mu = -0.006575876, sigma = 0.989105807, skew = 1.415881015, shape = 5.013324705 )
head(s1,10)
## [1] 0.3294154 0.6351368 0.4653921 0.4926726 0.5685545 0.3151298 0.3982890
## [8] 0.6078268 0.9289698 0.3756583
library(VineCopula)
BiCopSelect(s,s1, familyset= c(1:10,13,16:20), selectioncrit="AIC",indeptest = FALSE, level = 0.05)
## Bivariate copula: Rotated Joe 90 degrees (par = -1.06, tau = -0.03)
Kiểm định cho biến VNI
# Kiểm định Anderson_Darling
library(nortest)
ad.test(s)
##
## Anderson-Darling normality test
##
## data: s
## A = 14.637, p-value < 2.2e-16
# Kiểm định Cramer-von Mises
cvm.test(s)
## Warning in cvm.test(s): p-value is smaller than 7.37e-10, cannot be computed
## more accurately
##
## Cramer-von Mises normality test
##
## data: s
## W = 1.8276, p-value = 7.37e-10
# Kiểm định Kolmogorov-Smirnov
ks.test(s, y = "punif")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: s
## D = 0.030519, p-value = 0.1327
## alternative hypothesis: two-sided
Kiểm định cho biến SP
# Kiểm định Anderson_Darling
library(nortest)
ad.test(s1)
##
## Anderson-Darling normality test
##
## data: s1
## A = 17.195, p-value < 2.2e-16
# Kiểm định Cramer-von Mises
cvm.test(s1)
## Warning in cvm.test(s1): p-value is smaller than 7.37e-10, cannot be computed
## more accurately
##
## Cramer-von Mises normality test
##
## data: s1
## W = 2.4042, p-value = 7.37e-10
# Kiểm định Kolmogorov-Smirnov
ks.test(s1, y = "punif")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: s1
## D = 0.013585, p-value = 0.951
## alternative hypothesis: two-sided
#Tạo copula
library("copula")
##
## Attaching package: 'copula'
## The following object is masked from 'package:VineCopula':
##
## pobs
library("scatterplot3d")
#Chuyển đôi dữ liệu phân phối đều
u <- pobs(s)
head(u,10)
## [1] 0.80576527 0.91214825 0.18462594 0.83459163 0.85586822 0.63898421
## [7] 0.85312286 0.49347975 0.92793411 0.01235415
k <- pobs(s1)
head(k,10)
## [1] 0.3321894 0.6382979 0.4632807 0.4873027 0.5655456 0.3157172 0.4049417
## [8] 0.6108442 0.9279341 0.3864104
# Tạo copula
copula_model <- normalCopula(dim = 2)
# Ước lượng copula từ dữ liệu chuẩn hóa
fit_copula <- fitCopula(copula_model, cbind(u,k), method = "ml")
# Xem kết quả ước lượng
summary(fit_copula)
## Call: fitCopula(copula_model, data = cbind(u, k), ... = pairlist(method = "ml"))
## Fit based on "maximum likelihood" and 1456 2-dimensional observations.
## Normal copula, dim. d = 2
## Estimate Std. Error
## rho.1 -0.06489 0.026
## The maximized loglikelihood is 3.019
## Optimization converged
## Number of loglikelihood evaluations:
## function gradient
## 7 7
#
mycop<-normalCopula(c(-0.03),dim=2,dispstr="ex")
mymvd<-mvdc(copula=mycop,margins =c("norm","norm"),paramMargins=list(list(mean=0,sd=1),list(mean=1,2)))
#
r<-rMvdc(1456,mymvd)
#
dens<-dMvdc(r,mymvd)
dist<-pMvdc(r,mymvd)
#
x<-r[,1]
y<-r[,2]
scatterplot3d(x,y,dens,highlight.3d = T)
scatterplot3d(x,y,dist,highlight.3d = T)
2.2 See the copula itself
The copula function can also be visualized,it will be this look.
u<-rCopula(1456,mycop)
a<-u[,1]
b<-u[,2]
copdens<-dCopula(u,mycop)
copdist<-pCopula(u,mycop)
scatterplot3d(a,b,copdens,highlight.3d = T)
scatterplot3d(a,b,copdist,highlight.3d = T)