library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.4.1
## 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(readxl)
## Warning: package 'readxl' was built under R version 4.4.1
library(PerformanceAnalytics)
library(readxl)
data <- read_xlsx("D:/CMHNN/VNI_SET.xlsx")
lgvni<- diff(log(data$VNI), lag = 1)
lgset<- diff(log(data$SET), lag = 1)

mhnn <- data.frame(VNI= lgvni, SET= lgset)
tn <- data[,c(2:3)]
head(data,10)
## # A tibble: 10 × 3
##    Date                  VNI   SET
##    <dttm>              <dbl> <dbl>
##  1 2018-01-03 00:00:00 1006. 1779.
##  2 2018-01-04 00:00:00 1020. 1791.
##  3 2018-01-05 00:00:00 1013. 1795.
##  4 2018-01-08 00:00:00 1023. 1793.
##  5 2018-01-09 00:00:00 1034. 1795.
##  6 2018-01-10 00:00:00 1038. 1795.
##  7 2018-01-11 00:00:00 1048. 1803.
##  8 2018-01-12 00:00:00 1050. 1810.
##  9 2018-01-15 00:00:00 1063. 1823.
## 10 2018-01-16 00:00:00 1063. 1822.
summary(mhnn)
##       VNI                 SET            
##  Min.   :-0.069076   Min.   :-1.143e-01  
##  1st Qu.:-0.004635   1st Qu.:-4.671e-03  
##  Median : 0.001110   Median : 9.755e-05  
##  Mean   : 0.000167   Mean   :-1.744e-04  
##  3rd Qu.: 0.006744   3rd Qu.: 4.570e-03  
##  Max.   : 0.062002   Max.   : 7.653e-02
library(psych)
## Warning: package 'psych' was built under R version 4.4.1
detailed <- describe(mhnn)
print(detailed)
##     vars    n mean   sd median trimmed  mad   min  max range  skew kurtosis se
## VNI    1 1463    0 0.01      0       0 0.01 -0.07 0.06  0.13 -0.87     3.74  0
## SET    2 1463    0 0.01      0       0 0.01 -0.11 0.08  0.19 -1.82    24.77  0
plot.ts(tn$VNI)

plot.ts(tn$SET)

# Vẽ đồ thị chuỗi thời gian cho VN-Index
plot.ts(mhnn$VNI, main="VN-Index Time Series", ylab="VN-Index", xlab="Time", col="blue")

# Vẽ đồ thị chuỗi thời gian cho SET Index
plot.ts(mhnn$SET, main="SET Index Time Series", ylab="SET Index", xlab="Time", col="red")

Kiểm định phân phối chuẩn bằng QQ_lot

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.1
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
ggplot(data.frame(price = mhnn$VNI), aes(sample = price)) +
  geom_qq() +
  geom_qq_line()

library(ggplot2)
ggplot(data.frame(price = mhnn$SET), aes(sample = price)) +
  geom_qq() +
  geom_qq_line()

TƯƠNG QUAN

###TƯƠNG QUAN
  res <- cor(mhnn)
round(res, 2)
##      VNI  SET
## VNI 1.00 0.31
## SET 0.31 1.00
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.4.1
## corrplot 0.92 loaded
res <- cor(mhnn)
rounded_res <- round(res, 2)
round(res, 2)
##      VNI  SET
## VNI 1.00 0.31
## SET 0.31 1.00
corrplot(rounded_res, method = "color")

library(corrplot)
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

library(ggplot2)
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.4.1
df <- dplyr::select_if(mhnn, is.numeric)
r <- cor(df, use="complete.obs")
ggcorrplot(r)

Thực hành các kiểm định

library(tseries)
## Warning: package 'tseries' was built under R version 4.4.1
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
mhnn <- data.frame(VNI= lgvni, SET= lgset)

Kiểm định phân phối chuẩn: Jarque-Bera

# Kiểm định 
Var1 <- mhnn$VNI
Var2 <- mhnn$SET
# Kiểm định phân phối chuẩn cho ORS
result1 <-  jarque.bera.test(Var1)
print(result1)
## 
##  Jarque Bera Test
## 
## data:  Var1
## X-squared = 1042, df = 2, p-value < 2.2e-16
result2 <- jarque.bera.test(Var2)
print(result2)
## 
##  Jarque Bera Test
## 
## data:  Var2
## X-squared = 38337, df = 2, p-value < 2.2e-16

Kiểm định tính dừng: Augmented Dickey–Fuller

adf.test(Var1)
## Warning in adf.test(Var1): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Var1
## Dickey-Fuller = -11.716, Lag order = 11, p-value = 0.01
## alternative hypothesis: stationary
adf.test(Var2)
## Warning in adf.test(Var2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Var2
## Dickey-Fuller = -9.2563, Lag order = 11, p-value = 0.01
## alternative hypothesis: stationary

Kiểm định tương quan chuỗi: Ljung-Box

library(stats)
result11 <-  Box.test(Var1, lag = 10, type = "Ljung-Box")
print(result11)
## 
##  Box-Ljung test
## 
## data:  Var1
## X-squared = 20.897, df = 10, p-value = 0.02182
result22 <-  Box.test(Var2, lag = 10, type = "Ljung-Box")
print(result22)
## 
##  Box-Ljung test
## 
## data:  Var2
## X-squared = 82.36, df = 10, p-value = 1.729e-13

2.4 Tính dừng

library(forecast)
## Warning: package 'forecast' was built under R version 4.4.1
modeld <- auto.arima(mhnn$VNI)
modeld
## Series: mhnn$VNI 
## ARIMA(1,0,0) with zero mean 
## 
## Coefficients:
##          ar1
##       0.0615
## s.e.  0.0261
## 
## sigma^2 = 0.0001687:  log likelihood = 4279.57
## AIC=-8555.15   AICc=-8555.14   BIC=-8544.57
modeld1 <- auto.arima(mhnn$SET)
modeld1
## Series: mhnn$SET 
## ARIMA(3,0,1) with zero mean 
## 
## Coefficients:
##           ar1     ar2     ar3     ma1
##       -0.7289  0.0103  0.1295  0.6976
## s.e.   0.0739  0.0323  0.0270  0.0711
## 
## sigma^2 = 0.000102:  log likelihood = 4648.98
## AIC=-9287.96   AICc=-9287.92   BIC=-9261.52
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.4.1
library(fGarch)
## Warning: package 'fGarch' was built under R version 4.4.1
## 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)
## Warning: package 'rugarch' was built under R version 4.4.1
## Loading required package: parallel
## 
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
## 
##     sigma
library(readxl)

Kiểm định ARCH - LM

# 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,0)))
## ARCH heteroscedasticity test for residuals 
## alternative: heteroscedastic 
## 
## Portmanteau-Q test: 
##      order  PQ p.value
## [1,]     4 166       0
## [2,]     8 283       0
## [3,]    12 389       0
## [4,]    16 410       0
## [5,]    20 432       0
## [6,]    24 434       0
## Lagrange-Multiplier test: 
##      order   LM p.value
## [1,]     4 1103       0
## [2,]     8  466       0
## [3,]    12  285       0
## [4,]    16  208       0
## [5,]    20  162       0
## [6,]    24  132       0

# Kiểm định hiệu ứng ARCH - LM  cho chỉ số chứng khoán 
arch_spec <- ugarchspec(variance.model = list(model = "sGARCH"))
arch_SET <- ugarchfit(spec = arch_spec, data = mhnn$SET)

residuals <- residuals(arch_SET)
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$SET,order = c(3,0,1)))
## ARCH heteroscedasticity test for residuals 
## alternative: heteroscedastic 
## 
## Portmanteau-Q test: 
##      order   PQ p.value
## [1,]     4  236       0
## [2,]     8  550       0
## [3,]    12  841       0
## [4,]    16  953       0
## [5,]    20 1005       0
## [6,]    24 1011       0
## Lagrange-Multiplier test: 
##      order   LM  p.value
## [1,]     4 1810 0.00e+00
## [2,]     8  488 0.00e+00
## [3,]    12  263 0.00e+00
## [4,]    16  156 0.00e+00
## [5,]    20  123 0.00e+00
## [6,]    24  100 1.34e-11

MÔ HÌNH GARCH

library(rugarch)
VNIts<- ts(mhnn$VNI)
head(VNIts)
## Time Series:
## Start = 1 
## End = 6 
## Frequency = 1 
## [1]  0.013903513 -0.006986842  0.010071073  0.010367423  0.004392599
## [6]  0.009644034
library(rugarch)
SETts<- ts(mhnn$SET)
head(SETts)
## Time Series:
## Start = 1 
## End = 6 
## Frequency = 1 
## [1]  0.006998110  0.002470397 -0.001471466  0.001337785 -0.000161554
## [6]  0.004380559
library(lmtest)
VNIspec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,0), 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,0)
## Include Mean     : TRUE 
## GARCH-in-Mean        : FALSE 
## 
## Conditional Distribution
## ------------------------------------
## Distribution :  norm 
## Includes Skew    :  FALSE 
## Includes Shape   :  FALSE 
## Includes Lambda  :  FALSE
library(lmtest)
SETspec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(3,1), include.mean =TRUE), distribution.model = 'norm')
print(SETspec)
## 
## *---------------------------------*
## *       GARCH Model Spec          *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## ------------------------------------
## GARCH Model      : gjrGARCH(1,1)
## Variance Targeting   : FALSE 
## 
## Conditional Mean Dynamics
## ------------------------------------
## Mean Model       : ARFIMA(3,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,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu      0.000252    0.000303   0.83019 0.406430
## ar1     0.086104    0.029697   2.89943 0.003738
## omega   0.000007    0.000000  48.96693 0.000000
## alpha1  0.018647    0.005305   3.51485 0.000440
## beta1   0.870058    0.008651 100.57113 0.000000
## gamma1  0.116479    0.019269   6.04506 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000252    0.000328  0.76895 0.441926
## ar1     0.086104    0.026966  3.19300 0.001408
## omega   0.000007    0.000000 35.95992 0.000000
## alpha1  0.018647    0.006331  2.94520 0.003228
## beta1   0.870058    0.012251 71.02161 0.000000
## gamma1  0.116479    0.026882  4.33295 0.000015
## 
## LogLikelihood : 4440.556 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.0623
## Bayes        -6.0406
## Shibata      -6.0623
## Hannan-Quinn -6.0542
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2085  0.6479
## Lag[2*(p+q)+(p+q)-1][2]    0.9098  0.7926
## Lag[4*(p+q)+(p+q)-1][5]    2.5128  0.5627
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                    0.02992  0.8627
## Lag[2*(p+q)+(p+q)-1][5]   0.30420  0.9833
## Lag[4*(p+q)+(p+q)-1][9]   0.79687  0.9932
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.4371 0.500 2.000  0.5085
## ARCH Lag[5]    0.4632 1.440 1.667  0.8944
## ARCH Lag[7]    0.7994 2.315 1.543  0.9438
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  18.1224
## Individual Statistics:              
## mu     0.30267
## ar1    0.07353
## omega  4.12741
## alpha1 0.06405
## beta1  0.07956
## gamma1 0.05009
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          1.49 1.68 2.12
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value    prob sig
## Sign Bias          1.47638 0.14006    
## Negative Sign Bias 0.01921 0.98468    
## Positive Sign Bias 1.08656 0.27741    
## Joint Effect       8.99863 0.02931  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     126.7    6.181e-18
## 2    30     148.4    5.674e-18
## 3    40     154.7    1.045e-15
## 4    50     173.0    9.778e-16
## 
## 
## Elapsed time : 0.422405
SETfit <- ugarchfit(spec = SETspec, SETts)
print(SETfit)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(3,0,1)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000405    0.000225 -1.80315 0.071365
## ar1     0.336868    0.507070  0.66434 0.506471
## ar2    -0.044120    0.041027 -1.07538 0.282205
## ar3     0.056252    0.028652  1.96326 0.049616
## ma1    -0.279802    0.506412 -0.55252 0.580593
## omega   0.000002    0.000002  1.42861 0.153116
## alpha1  0.033046    0.011458  2.88408 0.003926
## beta1   0.886825    0.015331 57.84589 0.000000
## gamma1  0.105600    0.022895  4.61241 0.000004
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000405    0.000347 -1.16666 0.243348
## ar1     0.336868    0.484206  0.69571 0.486609
## ar2    -0.044120    0.043981 -1.00316 0.315785
## ar3     0.056252    0.030389  1.85108 0.064159
## ma1    -0.279802    0.483556 -0.57864 0.562835
## omega   0.000002    0.000009  0.24023 0.810151
## alpha1  0.033046    0.019678  1.67940 0.093075
## beta1   0.886825    0.062999 14.07685 0.000000
## gamma1  0.105600    0.059648  1.77038 0.076663
## 
## LogLikelihood : 4962.008 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.7710
## Bayes        -6.7385
## Shibata      -6.7711
## Hannan-Quinn -6.7589
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                     0.01214  0.9123
## Lag[2*(p+q)+(p+q)-1][11]   2.47550  1.0000
## Lag[4*(p+q)+(p+q)-1][19]   6.39433  0.9519
## d.o.f=4
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2694  0.6037
## Lag[2*(p+q)+(p+q)-1][5]    3.5700  0.3128
## Lag[4*(p+q)+(p+q)-1][9]    5.0851  0.4170
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     3.238 0.500 2.000 0.07193
## ARCH Lag[5]     4.590 1.440 1.667 0.12769
## ARCH Lag[7]     5.059 2.315 1.543 0.21862
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  5.2762
## Individual Statistics:              
## mu     0.05887
## ar1    0.02582
## ar2    0.12448
## ar3    0.12543
## ma1    0.02926
## omega  1.01517
## alpha1 0.25936
## beta1  0.17479
## gamma1 0.13743
## 
## 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.415340 0.1572    
## Negative Sign Bias 0.923612 0.3558    
## Positive Sign Bias 0.006387 0.9949    
## Joint Effect       2.717958 0.4372    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     46.41    0.0004342
## 2    30     55.19    0.0023550
## 3    40     58.18    0.0247185
## 4    50     71.07    0.0213044
## 
## 
## Elapsed time : 0.7732229
VNIst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(1, 0), 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,0)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001140    0.000238   4.7835 0.000002
## ar1     0.046067    0.026757   1.7217 0.085125
## omega   0.000012    0.000000  25.7491 0.000000
## alpha1  0.032933    0.012698   2.5935 0.009500
## beta1   0.787379    0.021618  36.4229 0.000000
## gamma1  0.229134    0.046661   4.9106 0.000001
## shape   3.626860    0.300767  12.0587 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001140    0.000253   4.4993 0.000007
## ar1     0.046067    0.026457   1.7412 0.081649
## omega   0.000012    0.000001  22.2505 0.000000
## alpha1  0.032933    0.013286   2.4787 0.013185
## beta1   0.787379    0.019570  40.2334 0.000000
## gamma1  0.229134    0.047193   4.8553 0.000001
## shape   3.626860    0.282615  12.8332 0.000000
## 
## LogLikelihood : 4544.987 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.2037
## Bayes        -6.1784
## Shibata      -6.2037
## Hannan-Quinn -6.1942
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.6946  0.4046
## Lag[2*(p+q)+(p+q)-1][2]    1.0433  0.7137
## Lag[4*(p+q)+(p+q)-1][5]    2.1192  0.6768
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.8956  0.3440
## Lag[2*(p+q)+(p+q)-1][5]    2.2542  0.5597
## Lag[4*(p+q)+(p+q)-1][9]    2.8306  0.7866
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     1.494 0.500 2.000  0.2216
## ARCH Lag[5]     1.702 1.440 1.667  0.5409
## ARCH Lag[7]     1.772 2.315 1.543  0.7654
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  41.6054
## Individual Statistics:              
## mu     0.33652
## ar1    0.09476
## omega  9.34867
## alpha1 0.10291
## beta1  0.13361
## gamma1 0.14912
## shape  0.15740
## 
## 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            1.806 0.07107   *
## Negative Sign Bias   1.455 0.14590    
## Positive Sign Bias   1.068 0.28591    
## Joint Effect         8.979 0.02957  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     46.43    0.0004303
## 2    30     62.49    0.0002998
## 3    40     79.45    0.0001396
## 4    50     74.01    0.0120097
## 
## 
## Elapsed time : 0.522985
SETst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "std")

SETst1<- ugarchfit(SETst.spec,SETts) 
print(SETst1)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(3,0,1)
## Distribution : std 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000175    0.000198 -0.88491 0.376207
## ar1     0.685259    0.499775  1.37114 0.170333
## ar2    -0.031393    0.035460 -0.88533 0.375979
## ar3     0.026914    0.027023  0.99599 0.319256
## ma1    -0.656143    0.500050 -1.31216 0.189468
## omega   0.000003    0.000002  1.74803 0.080458
## alpha1  0.016974    0.002695  6.29866 0.000000
## beta1   0.879854    0.013564 64.86481 0.000000
## gamma1  0.120370    0.027196  4.42598 0.000010
## shape   6.060553    0.920224  6.58595 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000175    0.000250 -0.69856 0.484824
## ar1     0.685259    0.473157  1.44827 0.147541
## ar2    -0.031393    0.036953 -0.84955 0.395572
## ar3     0.026914    0.029229  0.92082 0.357143
## ma1    -0.656143    0.470650 -1.39412 0.163281
## omega   0.000003    0.000006  0.52348 0.600637
## alpha1  0.016974    0.040391  0.42024 0.674309
## beta1   0.879854    0.024743 35.55953 0.000000
## gamma1  0.120370    0.031239  3.85322 0.000117
## shape   6.060553    1.134862  5.34034 0.000000
## 
## LogLikelihood : 5004.842 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.8282
## Bayes        -6.7921
## Shibata      -6.8283
## Hannan-Quinn -6.8147
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                      0.8101  0.3681
## Lag[2*(p+q)+(p+q)-1][11]    3.1753  1.0000
## Lag[4*(p+q)+(p+q)-1][19]    7.6590  0.8389
## d.o.f=4
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1153  0.7341
## Lag[2*(p+q)+(p+q)-1][5]    4.0068  0.2532
## Lag[4*(p+q)+(p+q)-1][9]    5.4779  0.3627
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     4.890 0.500 2.000 0.02702
## ARCH Lag[5]     5.582 1.440 1.667 0.07528
## ARCH Lag[7]     5.818 2.315 1.543 0.15392
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  3.699
## Individual Statistics:              
## mu     0.13103
## ar1    0.01392
## ar2    0.06351
## ar3    0.05764
## ma1    0.01245
## omega  0.34273
## alpha1 0.28199
## beta1  0.13556
## gamma1 0.07166
## shape  0.11804
## 
## 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.9229 0.05468   *
## Negative Sign Bias  1.1452 0.25233    
## Positive Sign Bias  0.7663 0.44364    
## Joint Effect        3.8728 0.27553    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     11.96       0.8875
## 2    30     24.96       0.6802
## 3    40     39.15       0.4633
## 4    50     43.73       0.6859
## 
## 
## Elapsed time : 0.926527
# 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, 0), 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,0)
## Distribution : sstd 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000415    0.000274   1.5120 0.130533
## ar1     0.037114    0.026856   1.3820 0.166983
## omega   0.000011    0.000000  27.1406 0.000000
## alpha1  0.035126    0.010451   3.3609 0.000777
## beta1   0.803315    0.018895  42.5151 0.000000
## gamma1  0.198526    0.039760   4.9930 0.000001
## skew    0.827937    0.031138  26.5892 0.000000
## shape   3.988498    0.365313  10.9180 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000415    0.000296   1.4001 0.161491
## ar1     0.037114    0.027624   1.3435 0.179103
## omega   0.000011    0.000000  22.9989 0.000000
## alpha1  0.035126    0.011134   3.1549 0.001605
## beta1   0.803315    0.016473  48.7644 0.000000
## gamma1  0.198526    0.039086   5.0792 0.000000
## skew    0.827937    0.032375  25.5731 0.000000
## shape   3.988498    0.333050  11.9757 0.000000
## 
## LogLikelihood : 4558.381 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.2206
## Bayes        -6.1917
## Shibata      -6.2207
## Hannan-Quinn -6.2098
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      1.733  0.1881
## Lag[2*(p+q)+(p+q)-1][2]     2.306  0.1282
## Lag[4*(p+q)+(p+q)-1][5]     3.797  0.2595
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      0.924  0.3364
## Lag[2*(p+q)+(p+q)-1][5]     2.181  0.5763
## Lag[4*(p+q)+(p+q)-1][9]     2.747  0.7999
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     1.358 0.500 2.000  0.2439
## ARCH Lag[5]     1.563 1.440 1.667  0.5760
## ARCH Lag[7]     1.640 2.315 1.543  0.7929
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  44.9897
## Individual Statistics:              
## mu     0.30100
## ar1    0.10822
## omega  8.95396
## alpha1 0.08742
## beta1  0.13009
## gamma1 0.11666
## skew   0.10455
## shape  0.12495
## 
## 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            2.118 0.03431  **
## Negative Sign Bias   1.507 0.13211    
## Positive Sign Bias   1.099 0.27190    
## Joint Effect        10.896 0.01230  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     25.63      0.14095
## 2    30     33.29      0.26626
## 3    40     54.29      0.05267
## 4    50     68.82      0.03235
## 
## 
## Elapsed time : 0.700639
# Phân phối Student đối xứng (sstd)
SETst1.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "sstd")

SETst2<- ugarchfit(SETst1.spec,SETts) 
print(SETst2)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(3,0,1)
## Distribution : sstd 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000367    0.000199 -1.843790 0.065214
## ar1    -0.671124    6.103944 -0.109949 0.912450
## ar2     0.001369    0.176363  0.007765 0.993805
## ar3    -0.003866    0.123622 -0.031272 0.975053
## ma1     0.694709    6.113176  0.113641 0.909522
## omega   0.000003    0.000003  0.868946 0.384877
## alpha1  0.019700    0.006767  2.911124 0.003601
## beta1   0.885346    0.019234 46.030202 0.000000
## gamma1  0.115252    0.016854  6.838177 0.000000
## skew    0.887947    0.029821 29.776104 0.000000
## shape   6.160223    0.844457  7.294890 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000367    0.000726 -0.505393 0.613283
## ar1    -0.671124  105.096698 -0.006386 0.994905
## ar2     0.001369    2.759656  0.000496 0.999604
## ar3    -0.003866    2.063729 -0.001873 0.998505
## ma1     0.694709  104.981792  0.006617 0.994720
## omega   0.000003    0.000040  0.070824 0.943538
## alpha1  0.019700    0.211336  0.093218 0.925730
## beta1   0.885346    0.219591  4.031799 0.000055
## gamma1  0.115252    0.217437  0.530050 0.596077
## skew    0.887947    0.133987  6.627126 0.000000
## shape   6.160223    7.034863  0.875671 0.381209
## 
## LogLikelihood : 5009.701 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.8335
## Bayes        -6.7937
## Shibata      -6.8336
## Hannan-Quinn -6.8187
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                       1.217  0.2699
## Lag[2*(p+q)+(p+q)-1][11]     4.923  0.9693
## Lag[4*(p+q)+(p+q)-1][19]     9.287  0.5895
## d.o.f=4
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1112  0.7388
## Lag[2*(p+q)+(p+q)-1][5]    4.1067  0.2410
## Lag[4*(p+q)+(p+q)-1][9]    5.6219  0.3440
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     4.859 0.500 2.000 0.02750
## ARCH Lag[5]     5.753 1.440 1.667 0.06864
## ARCH Lag[7]     5.982 2.315 1.543 0.14244
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  8.306
## Individual Statistics:              
## mu     0.11242
## ar1    0.13356
## ar2    0.20844
## ar3    0.18670
## ma1    0.13653
## omega  0.95232
## alpha1 0.27469
## beta1  0.12895
## gamma1 0.05733
## skew   0.20088
## shape  0.11776
## 
## 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.4311 0.1526    
## Negative Sign Bias  0.9525 0.3410    
## Positive Sign Bias  0.4005 0.6888    
## Joint Effect        2.2922 0.5140    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     8.018       0.9865
## 2    30    22.830       0.7842
## 3    40    37.834       0.5230
## 4    50    38.880       0.8494
## 
## 
## Elapsed time : 0.9870639
# 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, 0), 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,0)
## Distribution : ged 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001051    0.000151   6.9514 0.000000
## ar1     0.018679    0.006934   2.6937 0.007065
## omega   0.000010    0.000000  29.0025 0.000000
## alpha1  0.024589    0.010087   2.4378 0.014778
## beta1   0.819167    0.016797  48.7683 0.000000
## gamma1  0.161187    0.034503   4.6716 0.000003
## shape   1.057066    0.046426  22.7690 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.001051    0.000116   9.0888 0.000000
## ar1     0.018679    0.001965   9.5069 0.000000
## omega   0.000010    0.000000  28.8227 0.000000
## alpha1  0.024589    0.009896   2.4846 0.012968
## beta1   0.819167    0.016212  50.5293 0.000000
## gamma1  0.161187    0.032306   4.9894 0.000001
## shape   1.057066    0.048672  21.7180 0.000000
## 
## LogLikelihood : 4539.418 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.1961
## Bayes        -6.1708
## Shibata      -6.1961
## Hannan-Quinn -6.1866
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      2.871 0.09016
## Lag[2*(p+q)+(p+q)-1][2]     3.372 0.01652
## Lag[4*(p+q)+(p+q)-1][5]     4.623 0.14259
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.4747  0.4908
## Lag[2*(p+q)+(p+q)-1][5]    1.2729  0.7954
## Lag[4*(p+q)+(p+q)-1][9]    1.7238  0.9353
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.9987 0.500 2.000  0.3176
## ARCH Lag[5]    1.0692 1.440 1.667  0.7125
## ARCH Lag[7]    1.1605 2.315 1.543  0.8861
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  31.7617
## Individual Statistics:              
## mu     0.28257
## ar1    0.07815
## omega  8.00581
## alpha1 0.09393
## beta1  0.10647
## gamma1 0.10902
## shape  0.14927
## 
## 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           2.0324 0.04230  **
## Negative Sign Bias  1.0389 0.29903    
## Positive Sign Bias  0.8566 0.39182    
## Joint Effect        9.6021 0.02227  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     52.15    6.289e-05
## 2    30     69.62    3.412e-05
## 3    40     76.17    3.410e-04
## 4    50     90.14    3.116e-04
## 
## 
## Elapsed time : 0.877182
# Phân phối Generalized Error Distribution(ged)
SETged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "ged")

SETged1 <- ugarchfit(SETged.spec,SETts) 
print(SETged1)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(3,0,1)
## Distribution : ged 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000161    0.000238  -0.67458 0.499941
## ar1     0.632954    0.046720  13.54789 0.000000
## ar2    -0.035128    0.028415  -1.23625 0.216367
## ar3     0.041614    0.026958   1.54367 0.122669
## ma1    -0.601097    0.046907 -12.81476 0.000000
## omega   0.000003    0.000004   0.73474 0.462499
## alpha1  0.022981    0.016704   1.37580 0.168883
## beta1   0.885013    0.025537  34.65578 0.000000
## gamma1  0.110244    0.029128   3.78478 0.000154
## shape   1.336464    0.065976  20.25693 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000161    0.000636  -0.25269  0.80051
## ar1     0.632954    0.020803  30.42603  0.00000
## ar2    -0.035128    0.036860  -0.95300  0.34059
## ar3     0.041614    0.032842   1.26708  0.20513
## ma1    -0.601097    0.019533 -30.77355  0.00000
## omega   0.000003    0.000025   0.10330  0.91772
## alpha1  0.022981    0.077743   0.29561  0.76753
## beta1   0.885013    0.150563   5.87803  0.00000
## gamma1  0.110244    0.100213   1.10009  0.27129
## shape   1.336464    0.115417  11.57941  0.00000
## 
## LogLikelihood : 4997.957 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.8188
## Bayes        -6.7827
## Shibata      -6.8189
## Hannan-Quinn -6.8053
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                      0.5816  0.4457
## Lag[2*(p+q)+(p+q)-1][11]    2.6839  1.0000
## Lag[4*(p+q)+(p+q)-1][19]    6.9771  0.9103
## d.o.f=4
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.2207  0.6385
## Lag[2*(p+q)+(p+q)-1][5]    3.6614  0.2994
## Lag[4*(p+q)+(p+q)-1][9]    5.0403  0.4235
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     3.985 0.500 2.000  0.0459
## ARCH Lag[5]     4.868 1.440 1.667  0.1102
## ARCH Lag[7]     5.173 2.315 1.543  0.2076
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  6.6556
## Individual Statistics:              
## mu     0.10617
## ar1    0.01361
## ar2    0.06078
## ar3    0.08375
## ma1    0.01608
## omega  1.03989
## alpha1 0.28096
## beta1  0.16457
## gamma1 0.10405
## shape  0.27251
## 
## 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.8627 0.06271   *
## Negative Sign Bias  1.1234 0.26144    
## Positive Sign Bias  0.4944 0.62113    
## Joint Effect        3.8018 0.28367    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     17.75       0.5391
## 2    30     28.00       0.5180
## 3    40     40.95       0.3849
## 4    50     52.76       0.3310
## 
## 
## Elapsed time : 1.211175
# 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, 0), 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,0)
## Distribution : sged 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000267    0.000153   1.7434 0.081271
## ar1     0.030277    0.014082   2.1500 0.031554
## omega   0.000009    0.000000  29.1984 0.000000
## alpha1  0.026147    0.007947   3.2900 0.001002
## beta1   0.835662    0.014246  58.6588 0.000000
## gamma1  0.141116    0.027927   5.0530 0.000000
## skew    0.861255    0.018085  47.6219 0.000000
## shape   1.128199    0.051426  21.9381 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## mu      0.000267    0.000106   2.5252 0.011562
## ar1     0.030277    0.008258   3.6665 0.000246
## omega   0.000009    0.000000  28.6082 0.000000
## alpha1  0.026147    0.007780   3.3609 0.000777
## beta1   0.835662    0.013202  63.2990 0.000000
## gamma1  0.141116    0.024650   5.7248 0.000000
## skew    0.861255    0.014480  59.4771 0.000000
## shape   1.128199    0.053745  20.9918 0.000000
## 
## LogLikelihood : 4552.441 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.2125
## Bayes        -6.1836
## Shibata      -6.2126
## Hannan-Quinn -6.2017
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                      2.293 0.12994
## Lag[2*(p+q)+(p+q)-1][2]     3.021 0.03372
## Lag[4*(p+q)+(p+q)-1][5]     4.706 0.13374
## d.o.f=1
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.4637  0.4959
## Lag[2*(p+q)+(p+q)-1][5]    1.1589  0.8228
## Lag[4*(p+q)+(p+q)-1][9]    1.6429  0.9431
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]    0.8753 0.500 2.000  0.3495
## ARCH Lag[5]    0.9507 1.440 1.667  0.7476
## ARCH Lag[7]    1.1036 2.315 1.543  0.8961
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  31.4178
## Individual Statistics:              
## mu     0.43513
## ar1    0.16953
## omega  7.35901
## alpha1 0.09656
## beta1  0.13479
## gamma1 0.10740
## skew   0.18930
## shape  0.09610
## 
## 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           1.8720 0.06141   *
## Negative Sign Bias  0.8735 0.38252    
## Positive Sign Bias  1.1173 0.26405    
## Joint Effect        9.8380 0.01999  **
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     33.01      0.02399
## 2    30     41.61      0.06080
## 3    40     52.22      0.07663
## 4    50     59.80      0.13882
## 
## 
## Elapsed time : 1.358645
# Phân phối Generalized Error Distribution đối xứng ("sged")
SETged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "sged")

SETged2 <- ugarchfit(SETged.spec,SETts) 
print(SETged2)
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : gjrGARCH(1,1)
## Mean Model   : ARFIMA(3,0,1)
## Distribution : sged 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## mu     -0.000442    0.000219  -2.0200 0.043387
## ar1     0.730901    0.083556   8.7474 0.000000
## ar2    -0.036319    0.038940  -0.9327 0.350975
## ar3     0.031610    0.025469   1.2411 0.214563
## ma1    -0.706433    0.084591  -8.3511 0.000000
## omega   0.000002    0.000002   1.1393 0.254594
## alpha1  0.023779    0.012901   1.8431 0.065308
## beta1   0.891736    0.020190  44.1678 0.000000
## gamma1  0.107800    0.028110   3.8350 0.000126
## skew    0.885676    0.030756  28.7972 0.000000
## shape   1.341635    0.067806  19.7863 0.000000
## 
## Robust Standard Errors:
##         Estimate  Std. Error   t value Pr(>|t|)
## mu     -0.000442    0.000269  -1.64165 0.100663
## ar1     0.730901    0.025139  29.07416 0.000000
## ar2    -0.036319    0.051445  -0.70598 0.480200
## ar3     0.031610    0.027645   1.14342 0.252863
## ma1    -0.706433    0.029538 -23.91579 0.000000
## omega   0.000002    0.000009   0.25692 0.797244
## alpha1  0.023779    0.019141   1.24229 0.214131
## beta1   0.891736    0.067430  13.22468 0.000000
## gamma1  0.107800    0.059813   1.80230 0.071498
## skew    0.885676    0.054138  16.35967 0.000000
## shape   1.341635    0.115644  11.60141 0.000000
## 
## LogLikelihood : 5005.038 
## 
## Information Criteria
## ------------------------------------
##                     
## Akaike       -6.8271
## Bayes        -6.7874
## Shibata      -6.8272
## Hannan-Quinn -6.8123
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                          statistic p-value
## Lag[1]                       1.031  0.3098
## Lag[2*(p+q)+(p+q)-1][11]     3.746  1.0000
## Lag[4*(p+q)+(p+q)-1][19]     7.865  0.8126
## d.o.f=4
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.1818  0.6698
## Lag[2*(p+q)+(p+q)-1][5]    3.8077  0.2791
## Lag[4*(p+q)+(p+q)-1][9]    5.2684  0.3911
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]     4.093 0.500 2.000 0.04305
## ARCH Lag[5]     5.218 1.440 1.667 0.09147
## ARCH Lag[7]     5.508 2.315 1.543 0.17796
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  13.518
## Individual Statistics:              
## mu     0.07961
## ar1    0.01948
## ar2    0.08448
## ar3    0.08279
## ma1    0.01687
## omega  2.34711
## alpha1 0.26567
## beta1  0.14846
## gamma1 0.07456
## skew   0.11620
## shape  0.30944
## 
## 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.5480 0.1218    
## Negative Sign Bias  0.9976 0.3186    
## Positive Sign Bias  0.2315 0.8170    
## Joint Effect        2.8686 0.4123    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     12.42       0.8669
## 2    30     23.73       0.7420
## 3    40     37.78       0.5255
## 4    50     54.40       0.2766
## 
## 
## Elapsed time : 2.221092
# Tạo danh sách bao gồm các phân phối và ước lượng của VNI
VNI_list <- list(
  garchn= VNIfit,
  garcht= VNIst1,
  garchst = VNIst2,
  garchg = VNIged1,
  garchsg = VNIged2
)
# Tính toán các thông tin
VNI_info_mat <- sapply(VNI_list, infocriteria) 
rownames(VNI_info_mat) <- rownames(infocriteria(VNIfit))
print(VNI_info_mat)
##                 garchn    garcht   garchst    garchg   garchsg
## Akaike       -6.062277 -6.203674 -6.220616 -6.196060 -6.212496
## Bayes        -6.040589 -6.178371 -6.191699 -6.170758 -6.183579
## Shibata      -6.062311 -6.203719 -6.220675 -6.196106 -6.212555
## Hannan-Quinn -6.054188 -6.194236 -6.209830 -6.186622 -6.201710
# Tạo danh sách bao gồm các phân phối và ước lượng của SET
SET_list <- list(
  garchn= SETfit,
  garcht= SETst1,
  garchst = SETst2,
  garchg = SETged1,
  garchsg = SETged2
)
# Tính toán các thông tin
SET_info_mat <- sapply(SET_list, infocriteria) 
rownames(SET_info_mat) <- rownames(infocriteria(SETfit))
print(SET_info_mat)
##                 garchn    garcht   garchst    garchg   garchsg
## Akaike       -6.771029 -6.828219 -6.833494 -6.818806 -6.827120
## Bayes        -6.738497 -6.792073 -6.793733 -6.782660 -6.787359
## Shibata      -6.771104 -6.828312 -6.833606 -6.818899 -6.827232
## Hannan-Quinn -6.758895 -6.814736 -6.818663 -6.805323 -6.812289

TRÍCH XUẤT PHẦN DƯ

VNI.res <- residuals(VNIst2)/sigma(VNIst2)
fitdist(distribution = "sstd", VNI.res, control = list())
## $pars
##           mu        sigma         skew        shape 
## -0.006437266  1.006945123  0.824410534  3.948967168 
## 
## $convergence
## [1] 0
## 
## $values
## [1] 2119.625 1932.710 1932.710
## 
## $lagrange
## [1] 0
## 
## $hessian
##            [,1]      [,2]       [,3]      [,4]
## [1,] 2273.49325  547.6364 -768.82877  29.84075
## [2,]  547.63641 1787.5356  202.94989 143.32332
## [3,] -768.82877  202.9499 1331.03255  29.73594
## [4,]   29.84075  143.3233   29.73594  16.92159
## 
## $ineqx0
## NULL
## 
## $nfuneval
## [1] 102
## 
## $outer.iter
## [1] 2
## 
## $elapsed
## Time difference of 0.06486893 secs
## 
## $vscale
## [1] 1 1 1 1 1
SET.res <- residuals(SETst2)/sigma(SETst2)
fitdist(distribution = "sstd", SET.res, control = list())
## $pars
##         mu      sigma       skew      shape 
## 0.01229265 0.99197059 0.89326609 6.29073256 
## 
## $convergence
## [1] 0
## 
## $values
## [1] 2152.401 2018.255 2018.255
## 
## $lagrange
## [1] 0
## 
## $hessian
##             [,1]       [,2]        [,3]      [,4]
## [1,] 1764.533578  240.03987 -430.255685  4.157051
## [2,]  240.039866 2026.88230  192.464738 32.880268
## [3,] -430.255685  192.46474 1170.249007  5.290859
## [4,]    4.157051   32.88027    5.290859  1.622396
## 
## $ineqx0
## NULL
## 
## $nfuneval
## [1] 121
## 
## $outer.iter
## [1] 2
## 
## $elapsed
## Time difference of 0.09074092 secs
## 
## $vscale
## [1] 1 1 1 1 1
s = pdist("sstd",VNI.res, mu = -0.006437266, sigma =  1.006945123, skew = 0.824410534, shape = 3.948967168 )
head(s,10)
##  [1] 0.90330343 0.20177741 0.84679514 0.85149378 0.63230860 0.86345748
##  [7] 0.51465155 0.94049905 0.38860692 0.01035891
s1 = pdist("sstd",SET.res, mu = 0.01229265, sigma =  0.99197059, skew = 0.89326609, shape = 6.29073256 )
head(s1,10)
##  [1] 0.7862829 0.6022263 0.4235651 0.5563165 0.4794785 0.7154878 0.7024680
##  [8] 0.8329672 0.4592902 0.7256200

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.928, 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.8967, 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.026582, p-value = 0.2525
## alternative hypothesis: two-sided

Kiểm định cho biến SET

# Kiểm định Anderson_Darling
library(nortest)
ad.test(s1)
## 
##  Anderson-Darling normality test
## 
## data:  s1
## A = 15.907, 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.1103, 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.010965, p-value = 0.9946
## alternative hypothesis: two-sided

MÔ HÌNH COPULA

library(VineCopula)
## Warning: package 'VineCopula' was built under R version 4.4.1
library(copula)
## Warning: package 'copula' was built under R version 4.4.1
## 
## 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.90163934 0.19262295 0.83811475 0.84153005 0.64344262 0.85519126
##  [7] 0.53415301 0.94535519 0.38251366 0.01434426
k <- pobs(s1)
head(k,10)
##  [1] 0.7875683 0.6010929 0.4187158 0.5587432 0.4808743 0.7178962 0.7103825
##  [8] 0.8306011 0.4590164 0.7260929
BiCopSelect(s,s1, familyset= c(1:10), selectioncrit="AIC",indeptest = FALSE, level = 0.05)
## Bivariate copula: Survival Gumbel (par = 1.16, tau = 0.14)
#Biểu đồ phân tán:
gumbel.cop <- gumbelCopula(param = 1.16, dim = 2)

plot(mhnn, xlab = "u", ylab = "k")

persp(gumbel.cop, dCopula, xlab = "u", ylab = "k", zlab = "Mật độ",
      main = "Đồ thị mật độ của copula Gumbel")

contour(gumbel.cop, dCopula, xlab = "u", ylab = "k",
        main = "Đồ thị contour của copula Gumbel")

gumbel.cop1 <- gumbelCopula(param = 1.16, dim = 2)
set.seed(123)
data12 <- rCopula(1463, gumbel.cop1)

scatterplot3d(data12[,1], data12[,2], pch = 16, color = "blue",
             type = "h", highlight.3d = TRUE,
             xlab = "u", ylab = "k", zlab = "Probability")
## Warning in scatterplot3d(data12[, 1], data12[, 2], pch = 16, color = "blue", :
## color is ignored when highlight.3d = TRUE

library(copula)
# Thiết lập Joe copula với tham số par = 1.16
theta <- 1.16
gumbel_cop <- gumbelCopula(param = theta)
# Kiểm tra Kendall's tau của Joe copula
tau <- tau(gumbel_cop)
print(tau)
## [1] 0.137931
e <- cbind(u,k)
fit <- fitCopula(gumbelCopula(), data = e, method = "ml")  
# Maximum Likelihood Estimation (MLE)
theta <- coef(fit)
print(theta)
##    alpha 
## 1.123401
# Tạo thêm dữ liệu từ Gumbel copula
set.seed(654)
e <- rCopula(1463, gumbel_cop)
x <- qnorm(e[,1])
y <- qnorm(e[,2])

# Vẽ biểu đồ hộp và râu
boxplot(x, y, 
        col = c("lightblue", "pink"),
        names = c("VNI", "SET"),
        main = "Box Plot")

plot(data12[, 1], data12[, 2], pch = 16, col = "blue", 
     main = "Scatter Plot of Gumbel Copula Data",
     xlab = "VNI", ylab = "SET")

# Tạo dữ liệu giả định
set.seed(123)
data <- data.frame(u = u, k = k)

# Vẽ đồ thị phân tán
ggplot(data, aes(x = u, y = k)) +
  geom_point(size = 1, alpha = 0.5) +
  labs(x = "VNI", y = "SET", title = "Đồ thị phân tán của VNI và SET") +
  theme_classic()

# Load necessary libraries
library(copula)
library(MASS)
## Warning: package 'MASS' was built under R version 4.4.1
library(scatterplot3d)

# Define the parameter for the Gumbel copula
theta <- 1.16

# Create the Joe copula object
gumbel_copula <- gumbelCopula(param = theta)

# Perform Kernel Density Estimation
kde2d_result <- kde2d(e[,1], e[,2], n = 50)

# Convert kde2d result to a format suitable for scatterplot3d
x <- kde2d_result$x
y <- kde2d_result$y
z <- kde2d_result$z

# Create a grid of points for scatterplot3d
grid <- expand.grid(x = x, y = y)

# Flatten z for scatterplot3d
z_flat <- as.vector(z)

# Plot the density using scatterplot3d
scatterplot3d(grid$x, grid$y, z_flat, type = "h", angle = 30, 
              main = "Density Plot of Gumbel Copula",
              xlab = "VNI", 
              ylab = "SET", 
              zlab = "Bivariate Distribution",
              pch = 20, color = "yellow")

# Load necessary libraries
library(copula)
library(MASS)

# Define the parameter for the Joe copula
theta <- 1.16

# Create the Joe copula object
gumbel_copula <- gumbelCopula(param = theta)

# Perform Kernel Density Estimation
kde2d_result <- kde2d(e[,1], e[,2], n = 1000)

# Extract the results
x <- kde2d_result$x
y <- kde2d_result$y
z <- kde2d_result$z

# Plot the PDF using persp
persp(x, y, z, phi = 30, theta = 50, col = "blue", 
      xlab = "VNI", ylab = "SET", zlab = "Density", 
      main = "PDF of Gumbel Copula")

# Plot the contour plot
contour(x, y, z, xlab = "VNI", ylab = "SET", 
        main = "Contour Plot of Gumbel Copula")