library(rugarch)
## Warning: package 'rugarch' was built under R version 4.3.1
## Loading required package: parallel
##
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
##
## sigma
library(readxl)
data <- read_excel("C:/Users/Thanh Lan/Documents/datap.xlsx")
VNts <- ts(data$VNI)
# Ước lượng mô hình GARCH(1,1) theo phân phối chuẩn
VNspec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(2,2), include.mean =TRUE), distribution.model = 'norm')
• Đoạn mã này tạo ra một đối tượng spec (VNspec) để đặc tả mô hình GARCH.
• Mô hình GARCH được sử dụng là GJR-GARCH (generalized autoregressive conditional heteroskedasticity) với garchOrder = c(1, 1).
• Mô hình trung bình được sử dụng là ARMA (autoregressive moving average) với armaOrder = c(2, 2) và include.mean = TRUE (bao gồm thành phần trung bình).
• Phân phối được sử dụng là phân phối chuẩn (“norm”).
VNfit <- ugarchfit(spec = VNspec, VNts)
print(VNfit)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 1029.546779 44.328428 23.22543 0.000000
## ar1 0.481410 0.070715 6.80771 0.000000
## ar2 0.519965 0.070790 7.34521 0.000000
## ma1 -0.266687 0.062357 -4.27682 0.000019
## ma2 -0.622420 0.057397 -10.84415 0.000000
## omega 153.591373 49.480423 3.10408 0.001909
## alpha1 0.090763 0.019974 4.54415 0.000006
## beta1 0.916572 0.014030 65.32909 0.000000
## gamma1 -0.018849 0.028840 -0.65358 0.513380
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1029.546779 25.708647 40.04671 0.000000
## ar1 0.481410 0.044770 10.75292 0.000000
## ar2 0.519965 0.045658 11.38834 0.000000
## ma1 -0.266687 0.040328 -6.61303 0.000000
## ma2 -0.622420 0.039547 -15.73860 0.000000
## omega 153.591373 115.324285 1.33182 0.182919
## alpha1 0.090763 0.032295 2.81041 0.004948
## beta1 0.916572 0.019662 46.61527 0.000000
## gamma1 -0.018849 0.035876 -0.52539 0.599308
##
## LogLikelihood : -6524.318
##
## Information Criteria
## ------------------------------------
##
## Akaike 13.028
## Bayes 13.072
## Shibata 13.027
## Hannan-Quinn 13.044
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.578 2.091e-01
## Lag[2*(p+q)+(p+q)-1][11] 20.543 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 30.975 1.782e-09
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 2.083 0.14897
## Lag[2*(p+q)+(p+q)-1][5] 5.687 0.10646
## Lag[4*(p+q)+(p+q)-1][9] 11.220 0.02717
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.7615 0.500 2.000 0.38285
## ARCH Lag[5] 2.5508 1.440 1.667 0.36190
## ARCH Lag[7] 8.2836 2.315 1.543 0.04536
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 5.9993
## Individual Statistics:
## mu 0.01607
## ar1 0.29922
## ar2 0.18805
## ma1 3.52120
## ma2 1.75838
## omega 0.05157
## alpha1 0.16532
## beta1 0.53401
## gamma1 0.40693
##
## 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.2037 0.8386
## Negative Sign Bias 0.7426 0.4579
## Positive Sign Bias 1.2433 0.2141
## Joint Effect 2.1143 0.5490
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 108.9 1.258e-14
## 2 30 115.5 2.823e-12
## 3 40 126.6 3.443e-11
## 4 50 136.7 3.205e-10
##
##
## Elapsed time : 0.729316
• Đoạn mã này sử dụng hàm ugarchfit để ước lượng mô hình GARCH cho dữ liệu VNts.
• Tham số spec là đối tượng spec đã được đặc tả trong bước trước.
• Dữ liệu được truyền vào là VNts, tức là cột dữ liệu thứ 2 của vni.data.
Tương tự, các câu lệnh tiếp theo có cùng mục đích nhưng sử dụng các phân phối khác nhau:
# Phân phối Student (std)
vnst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "std")
vnst<- ugarchfit(vnst.spec,VNts)
print(vnst)
##
## *---------------------------------*
## * 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 1008.584236 40.923972 24.64532 0.000000
## ar1 0.473812 0.339855 1.39416 0.163269
## ar2 0.521571 0.339007 1.53852 0.123921
## ma1 -0.262014 0.279604 -0.93709 0.348711
## ma2 -0.614297 0.254162 -2.41695 0.015651
## omega 42.757431 42.247974 1.01206 0.311510
## alpha1 0.086994 0.019450 4.47270 0.000008
## beta1 0.925328 0.013354 69.29195 0.000000
## gamma1 -0.026644 0.028594 -0.93179 0.351445
## shape 12.356594 3.810561 3.24272 0.001184
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1008.584236 34.958369 28.85101 0.000000
## ar1 0.473812 1.047408 0.45237 0.651005
## ar2 0.521571 1.046687 0.49831 0.618268
## ma1 -0.262014 0.852573 -0.30732 0.758598
## ma2 -0.614297 0.784171 -0.78337 0.433409
## omega 42.757431 65.307551 0.65471 0.512655
## alpha1 0.086994 0.033487 2.59783 0.009381
## beta1 0.925328 0.016808 55.05205 0.000000
## gamma1 -0.026644 0.049539 -0.53783 0.590696
## shape 12.356594 6.379458 1.93694 0.052753
##
## LogLikelihood : -6516.035
##
## Information Criteria
## ------------------------------------
##
## Akaike 13.013
## Bayes 13.062
## Shibata 13.013
## Hannan-Quinn 13.032
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.6471 4.212e-01
## Lag[2*(p+q)+(p+q)-1][11] 20.2034 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 30.0425 5.603e-09
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.070 0.3009
## Lag[2*(p+q)+(p+q)-1][5] 2.047 0.6074
## Lag[4*(p+q)+(p+q)-1][9] 7.481 0.1622
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.4888 0.500 2.000 0.48446
## ARCH Lag[5] 0.8167 1.440 1.667 0.78799
## ARCH Lag[7] 7.3750 2.315 1.543 0.07203
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 8.7664
## Individual Statistics:
## mu 0.04099
## ar1 0.46417
## ar2 0.30878
## ma1 3.37250
## ma2 1.87039
## omega 0.09129
## alpha1 0.37431
## beta1 0.45320
## gamma1 0.41241
## shape 0.91445
##
## 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.2328 0.8160
## Negative Sign Bias 1.0907 0.2757
## Positive Sign Bias 1.5291 0.1265
## Joint Effect 3.5280 0.3171
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 115.6 7.256e-16
## 2 30 130.6 7.445e-15
## 3 40 140.9 1.898e-13
## 4 50 154.8 6.731e-13
##
##
## Elapsed time : 1.604363
# Phân phối Student đối xứng (sstd)
vnsst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
vnsst<- ugarchfit(vnsst.spec,VNts)
print(vnsst)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : sstd
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 1062.868563 30.481643 34.86914 0.000000
## ar1 0.450142 0.019544 23.03180 0.000000
## ar2 0.539138 0.019492 27.65968 0.000000
## ma1 -0.274112 0.017321 -15.82533 0.000000
## ma2 -0.594157 0.016194 -36.69001 0.000000
## omega 89.174028 70.024670 1.27347 0.202853
## alpha1 0.093174 0.023890 3.90011 0.000096
## beta1 0.922718 0.015842 58.24471 0.000000
## gamma1 -0.030258 0.030986 -0.97648 0.328829
## skew 1.459007 0.063475 22.98537 0.000000
## shape 7.223753 1.713434 4.21595 0.000025
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1062.868563 21.829481 48.68959 0.000000
## ar1 0.450142 0.005619 80.10447 0.000000
## ar2 0.539138 0.003595 149.97949 0.000000
## ma1 -0.274112 0.029215 -9.38258 0.000000
## ma2 -0.594157 0.018886 -31.45973 0.000000
## omega 89.174028 105.794737 0.84290 0.399286
## alpha1 0.093174 0.029577 3.15019 0.001632
## beta1 0.922718 0.017059 54.09037 0.000000
## gamma1 -0.030258 0.034839 -0.86851 0.385117
## skew 1.459007 0.081454 17.91206 0.000000
## shape 7.223753 2.907841 2.48423 0.012983
##
## LogLikelihood : -6480.562
##
## Information Criteria
## ------------------------------------
##
## Akaike 12.944
## Bayes 12.998
## Shibata 12.944
## Hannan-Quinn 12.965
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.00188 9.654e-01
## Lag[2*(p+q)+(p+q)-1][11] 23.51647 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 33.70204 5.768e-11
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.8608 0.3535
## Lag[2*(p+q)+(p+q)-1][5] 2.9150 0.4228
## Lag[4*(p+q)+(p+q)-1][9] 8.3719 0.1089
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.9242 0.500 2.000 0.33638
## ARCH Lag[5] 1.5794 1.440 1.667 0.57168
## ARCH Lag[7] 7.7980 2.315 1.543 0.05817
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 8.6037
## Individual Statistics:
## mu 0.04452
## ar1 0.30059
## ar2 0.21649
## ma1 2.34399
## ma2 1.51178
## omega 0.06834
## alpha1 0.17009
## beta1 0.16484
## gamma1 0.18271
## skew 2.26651
## shape 0.54064
##
## 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.184 0.23669
## Negative Sign Bias 0.721 0.47111
## Positive Sign Bias 2.229 0.02601 **
## Joint Effect 5.640 0.13048
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 58.00 7.991e-06
## 2 30 80.14 1.105e-06
## 3 40 83.70 4.207e-05
## 4 50 111.11 1.008e-06
##
##
## Elapsed time : 5.833001
# Phân phối Generalized Error Distribution(ged)
vnged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "ged")
vnged <- ugarchfit(vnged.spec,VNts)
print(vnged)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : ged
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 1002.362161 43.309298 23.14427 0.000000
## ar1 0.490972 0.064239 7.64289 0.000000
## ar2 0.504628 0.064019 7.88245 0.000000
## ma1 -0.267181 0.056852 -4.69959 0.000003
## ma2 -0.612536 0.051631 -11.86365 0.000000
## omega 111.484659 48.973254 2.27644 0.022820
## alpha1 0.087752 0.020167 4.35119 0.000014
## beta1 0.920590 0.014133 65.13873 0.000000
## gamma1 -0.018685 0.030280 -0.61709 0.537176
## shape 1.712774 0.130598 13.11481 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1002.362161 47.163628 21.25286 0.000000
## ar1 0.490972 0.039226 12.51666 0.000000
## ar2 0.504628 0.041750 12.08685 0.000000
## ma1 -0.267181 0.035137 -7.60392 0.000000
## ma2 -0.612536 0.034239 -17.88986 0.000000
## omega 111.484659 90.411776 1.23308 0.217547
## alpha1 0.087752 0.028110 3.12172 0.001798
## beta1 0.920590 0.017720 51.95323 0.000000
## gamma1 -0.018685 0.032825 -0.56924 0.569191
## shape 1.712774 0.253740 6.75010 0.000000
##
## LogLikelihood : -6522.049
##
## Information Criteria
## ------------------------------------
##
## Akaike 13.025
## Bayes 13.074
## Shibata 13.025
## Hannan-Quinn 13.044
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.927 1.651e-01
## Lag[2*(p+q)+(p+q)-1][11] 20.117 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 30.243 4.385e-09
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.501 0.22053
## Lag[2*(p+q)+(p+q)-1][5] 4.500 0.19795
## Lag[4*(p+q)+(p+q)-1][9] 10.096 0.04786
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.7635 0.500 2.000 0.38224
## ARCH Lag[5] 2.0302 1.440 1.667 0.46460
## ARCH Lag[7] 8.1122 2.315 1.543 0.04954
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 8.7731
## Individual Statistics:
## mu 0.04881
## ar1 0.47744
## ar2 0.31291
## ma1 3.63411
## ma2 1.94256
## omega 0.04802
## alpha1 0.15727
## beta1 0.49126
## gamma1 0.32387
## shape 1.27830
##
## 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.3672 0.7135
## Negative Sign Bias 0.7591 0.4480
## Positive Sign Bias 1.3917 0.1643
## Joint Effect 2.5131 0.4729
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 108.8 1.323e-14
## 2 30 115.3 3.025e-12
## 3 40 130.0 1.035e-11
## 4 50 148.8 5.396e-12
##
##
## Elapsed time : 1.083259
# Phân phối Generalized Error Distribution đối xứng ("sged")
vnsged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sged")
vnsged <- ugarchfit(vnsged.spec,VNts)
print(vnsged)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(1,1)
## Mean Model : ARFIMA(2,0,2)
## Distribution : sged
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 1056.618112 28.346113 37.2756 0.000000
## ar1 0.483453 0.006557 73.7353 0.000000
## ar2 0.494958 0.006391 77.4428 0.000000
## ma1 -0.327051 0.019355 -16.8975 0.000000
## ma2 -0.537719 0.016398 -32.7921 0.000000
## omega 187.559395 77.345887 2.4249 0.015311
## alpha1 0.099859 0.013429 7.4362 0.000000
## beta1 0.918762 0.010053 91.3899 0.000000
## gamma1 -0.033359 0.019245 -1.7334 0.083018
## skew 1.509278 0.054210 27.8412 0.000000
## shape 1.165975 0.090351 12.9049 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1056.618112 47.737836 22.1338 0.000000
## ar1 0.483453 0.004539 106.5169 0.000000
## ar2 0.494958 0.004143 119.4810 0.000000
## ma1 -0.327051 0.025636 -12.7574 0.000000
## ma2 -0.537719 0.011916 -45.1262 0.000000
## omega 187.559395 145.396434 1.2900 0.197055
## alpha1 0.099859 0.010265 9.7277 0.000000
## beta1 0.918762 0.007234 127.0147 0.000000
## gamma1 -0.033359 0.012068 -2.7644 0.005704
## skew 1.509278 0.080204 18.8180 0.000000
## shape 1.165975 0.180441 6.4618 0.000000
##
## LogLikelihood : -6476.347
##
## Information Criteria
## ------------------------------------
##
## Akaike 12.936
## Bayes 12.990
## Shibata 12.936
## Hannan-Quinn 12.956
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1979 6.564e-01
## Lag[2*(p+q)+(p+q)-1][11] 25.4648 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 36.8230 1.003e-12
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.144 0.70434
## Lag[2*(p+q)+(p+q)-1][5] 4.502 0.19778
## Lag[4*(p+q)+(p+q)-1][9] 10.073 0.04839
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 1.671 0.500 2.000 0.19608
## ARCH Lag[5] 3.166 1.440 1.667 0.26661
## ARCH Lag[7] 8.770 2.315 1.543 0.03526
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 9.7862
## Individual Statistics:
## mu 0.07939
## ar1 0.44657
## ar2 0.31978
## ma1 2.24638
## ma2 1.51758
## omega 0.06789
## alpha1 0.08952
## beta1 0.25788
## gamma1 0.11160
## skew 1.81608
## shape 0.33855
##
## 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 2.049 0.040706 **
## Negative Sign Bias 0.214 0.830614
## Positive Sign Bias 2.860 0.004322 ***
## Joint Effect 8.720 0.033262 **
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 48.55 2.139e-04
## 2 30 81.88 6.137e-07
## 3 40 105.47 4.945e-08
## 4 50 119.68 7.587e-08
##
##
## Elapsed time : 3.928089
# Tạo danh sách bao gồm các phân phối và ước lượng
VNI_list <- list(VNfit,vnst,vnsst,vnged,vnsged)
• Đoạn mã này tạo ra một danh sách (VN_list) chứa các đối tượng mô hình GARCH đã được ước lượng.
• Mỗi đối tượng mô hình GARCH tương ứng với một loại mô hình và đã được ước lượng trước đó bằng cách sử dụng hàm ugarchfit().
• Tên của từng đối tượng trong danh sách được đặt theo quy ước nhất định để chỉ loại mô hình và phân phối tương ứng.
Cụ thể, danh sách vni.model.list bao gồm các đối tượng mô hình GARCH sau:
• VNfit : Đối tượng mô hình GARCH(1,1) với phân phối chuẩn.
• vnst : Đối tượng mô hình GARCH(1,1) với phân phối Student’s t.
• vnsst : Đối tượng mô hình GARCH(1,1) với phân phối Student’s t đối xứng.
• vnged : Đối tượng mô hình GARCH(1,1) với phân phối Generalized Error Distribution (GED).
• vnsged : Đối tượng mô hình GARCH(1,1) với phân phối Generalized Error Distribution đối xứng.
# Tính toán các thông tin
vni_info_mat <- sapply(VNI_list, infocriteria)
print(vni_info_mat)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 13.02755 13.01303 12.94429 13.02502 12.93589
## [2,] 13.07162 13.06199 12.99815 13.07398 12.98974
## [3,] 13.02739 13.01283 12.94405 13.02483 12.93565
## [4,] 13.04430 13.03164 12.96476 13.04363 12.95635
• Đoạn mã này sử dụng hàm sapply() để áp dụng hàm infocriteria lên từng đối tượng trong danh sách VNI_list.
• Hàm infocriteria được sử dụng để tính toán các tiêu chí thông tin cho mô hình GARCH, bao gồm AIC, BIC và HQC.
• Kết quả của hàm sapply() là một ma trận, trong đó mỗi cột tương ứng với một đối tượng mô hình và mỗi hàng tương ứng với một tiêu chí thông tin.
rownames(vni_info_mat)<-rownames(infocriteria(VNfit))
• Đoạn mã này gán tên hàng cho ma trận vni_info_mat bằng cách sử dụng tên hàng từ kết quả của hàm infocriteria cho mô hình GARCH(1,1) với phân phối chuẩn.
• Điều này đảm bảo rằng tên hàng của ma trận vni_info_mat tương ứng với các tiêu chí thông tin (ví dụ: AIC, BIC, HQC).
print(rownames(vni_info_mat))
## [1] "Akaike" "Bayes" "Shibata" "Hannan-Quinn"
• Cuối cùng, đoạn mã này hiển thị ma trận vni_info_mat, chứa các tiêu chí thông tin cho tất cả các mô hình GARCH đã được ước lượng.
• Ma trận này cung cấp một cái nhìn tổng quan về các tiêu chí thông tin để so sánh và đánh giá hiệu suất của các mô hình GARCH khác nhau.
# Ước lượng mô hình GARCH(2,2) theo phân phối Student đối xứng (sstd)
vnsst.spec2 <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2,2)), mean.model = list(armaOrder = c(2, 2), include.mean = TRUE), distribution.model = "sstd")
vnsst2 <- ugarchfit(vnsst.spec2,VNts)
print(vnsst2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(2,2)
## Mean Model : ARFIMA(2,0,2)
## Distribution : sstd
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 1051.78400 27.056657 38.873391 0.000000
## ar1 0.49364 0.081163 6.082126 0.000000
## ar2 0.49371 0.080905 6.102377 0.000000
## ma1 -0.28273 0.066942 -4.223586 0.000024
## ma2 -0.58369 0.061078 -9.556440 0.000000
## omega 103.24372 95.712701 1.078684 0.280729
## alpha1 0.14166 0.038072 3.720936 0.000198
## alpha2 0.00000 0.003607 0.000016 0.999987
## beta1 0.30009 0.101810 2.947586 0.003203
## beta2 0.58298 0.090327 6.454063 0.000000
## gamma1 -0.20281 0.041655 -4.868896 0.000001
## gamma2 0.15665 0.028201 5.554653 0.000000
## skew 1.44341 0.060911 23.697139 0.000000
## shape 7.12907 1.538064 4.635097 0.000004
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 1051.78400 19.791033 53.144473 0.000000
## ar1 0.49364 0.068547 7.201518 0.000000
## ar2 0.49371 0.065037 7.591274 0.000000
## ma1 -0.28273 0.074488 -3.795666 0.000147
## ma2 -0.58369 0.056920 -10.254679 0.000000
## omega 103.24372 123.555898 0.835603 0.403378
## alpha1 0.14166 0.041738 3.394126 0.000688
## alpha2 0.00000 0.060211 0.000001 0.999999
## beta1 0.30009 0.093846 3.197736 0.001385
## beta2 0.58298 0.076624 7.608310 0.000000
## gamma1 -0.20281 0.044153 -4.593461 0.000004
## gamma2 0.15665 0.061709 2.538480 0.011134
## skew 1.44341 0.075615 19.088997 0.000000
## shape 7.12907 2.408175 2.960364 0.003073
##
## LogLikelihood : -6478.189
##
## Information Criteria
## ------------------------------------
##
## Akaike 12.946
## Bayes 13.014
## Shibata 12.945
## Hannan-Quinn 12.972
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.2989 5.846e-01
## Lag[2*(p+q)+(p+q)-1][11] 21.7870 0.000e+00
## Lag[4*(p+q)+(p+q)-1][19] 31.9347 5.396e-10
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1658 0.6838
## Lag[2*(p+q)+(p+q)-1][11] 8.1202 0.2066
## Lag[4*(p+q)+(p+q)-1][19] 10.8940 0.3603
## d.o.f=4
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[5] 0.1572 0.500 2.000 0.69172
## ARCH Lag[7] 7.8874 1.473 1.746 0.02754
## ARCH Lag[9] 8.5246 2.402 1.619 0.05481
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 11.0804
## Individual Statistics:
## mu 0.04427
## ar1 0.29543
## ar2 0.18538
## ma1 2.41227
## ma2 1.18688
## omega 0.07012
## alpha1 0.23709
## alpha2 0.14596
## beta1 0.20246
## beta2 0.21224
## gamma1 0.23289
## gamma2 0.22999
## skew 2.63813
## shape 0.41925
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 3.08 3.34 3.9
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 1.1653 0.2442
## Negative Sign Bias 0.3754 0.7075
## Positive Sign Bias 2.2221 0.0265 **
## Joint Effect 5.4309 0.1428
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 69.04 1.325e-07
## 2 30 81.34 7.370e-07
## 3 40 101.57 1.769e-07
## 4 50 116.39 2.077e-07
##
##
## Elapsed time : 33.57122
# Trích xuất chuỗi phần dư v của chuỗi lợi suất VNI
vni.res <- residuals(vnsst2)/sigma(vnsst2)
• Đoạn mã này trích xuất chuỗi phần dư của mô hình GARCH(2,2) với phân phối Student’s t đối xứng (vnsst2).
• Hàm residuals() được sử dụng để lấy phần dư từ mô hình, và sigma() được sử dụng để lấy độ lệch chuẩn (sigma) từ mô hình.
fitdist(distribution = "sstd", vni.res, control = list())
## $pars
## mu sigma skew shape
## 0.02997726 1.01935491 1.46323654 6.90476926
##
## $convergence
## [1] 0
##
## $values
## [1] 1391.273 1376.650 1376.650
##
## $lagrange
## [1] 0
##
## $hessian
## [,1] [,2] [,3] [,4]
## [1,] 1640.79900 -789.57068 -240.546812 -11.2655907
## [2,] -789.57068 1775.61296 -44.020333 25.4762330
## [3,] -240.54681 -44.02033 313.778764 1.8100216
## [4,] -11.26559 25.47623 1.810022 0.8354334
##
## $ineqx0
## NULL
##
## $nfuneval
## [1] 114
##
## $outer.iter
## [1] 2
##
## $elapsed
## Time difference of 0.073807 secs
##
## $vscale
## [1] 1 1 1 1 1
• Đoạn mã này sử dụng hàm fitdist() từ gói fitdistrplus để ước lượng tham số phân phối dựa trên dữ liệu chuỗi phần dư (vni.res).
• Đối số distribution chỉ định loại phân phối cần ước lượng, trong trường hợp này là “sstd” (phân phối Student’s t đối xứng).
• control = list() được sử dụng để chỉ định các tham số điều khiển mặc định cho quá trình ước lượng.
v = pdist("sstd",vni.res, mu = 0.02997726, sigma = 1.01935491, skew = 1.46323654, shape = 6.90476926)
• Đoạn mã này sử dụng hàm pdist() từ gói gld để tạo một đối tượng phân phối v dựa trên các tham số ước lượng từ fitdist.
• pdist() nhận các đối số như distribution (loại phân phối), data (dữ liệu chuỗi phần dư), và các tham số phân phối cụ thể (mu, sigma, skew, shape).
# Kiểm định Anderson_Darling
library(nortest)
ad.test(v)
##
## Anderson-Darling normality test
##
## data: v
## A = 14.858, p-value < 2.2e-16
# Kiểm định Cramer-von Mises
cvm.test(v)
## Warning in cvm.test(v): p-value is smaller than 7.37e-10, cannot be computed
## more accurately
##
## Cramer-von Mises normality test
##
## data: v
## W = 2.1412, p-value = 7.37e-10
# Kiểm định Kolmogorov-Smirnov
ks.test(v, y = "punif")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: v
## D = 0.045792, p-value = 0.0298
## alternative hypothesis: two-sided