#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", sheetIndex = 1, header = T)
PriceBID <- diff(log(data$BID), lag = 1)
PriceEIB <- diff(log(data$EIB), lag = 1)
mhnn <- data.frame(BID = PriceBID, EIB = PriceEIB)
head(mhnn,10)
## BID EIB
## 1 -0.009402353 0.011718678
## 2 0.025317808 -0.002908048
## 3 0.031090587 -0.023681720
## 4 -0.008968670 -0.021168846
## 5 0.014057739 0.010658591
## 6 0.067468868 0.022438968
## 7 0.042954949 0.011753007
## 8 0.005665738 -0.010298462
## 9 -0.013652089 -0.028442367
## 10 0.028234512 -0.016883160
res <- cor(mhnn)
round(res, 2)
## BID EIB
## BID 1.00 0.25
## EIB 0.25 1.00
library(Hmisc)
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
res2<-rcorr(as.matrix(mhnn[,1:2]))
res2
## BID EIB
## BID 1.00 0.25
## EIB 0.25 1.00
##
## n= 497
##
##
## P
## BID EIB
## BID 0
## EIB 0
# Hệ số tương quan Pearson
res <- cor(mhnn)
round(res, 2)
## BID EIB
## BID 1.00 0.25
## EIB 0.25 1.00
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 BID EIB 0.2522163 1.190725e-08
symnum(res, abbr.colnames = FALSE)
## BID EIB
## BID 1
## EIB 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$BID
# 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 = 101.6, 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 = -7.7697, Lag order = 7, 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 = -7.7697, Lag order = 7, 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 = 17.381, df = 10, p-value = 0.06635
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 BID
library(tseries)
library(forecast)
modeld <- auto.arima(mhnn$BID)
modeld
## Series: mhnn$BID
## ARIMA(3,0,1) with zero mean
##
## Coefficients:
## ar1 ar2 ar3 ma1
## 0.7693 -0.0222 0.1357 -0.8617
## s.e. 0.1022 0.0567 0.0449 0.0943
##
## sigma^2 = 0.0005403: log likelihood = 1166.32
## AIC=-2322.64 AICc=-2322.52 BIC=-2301.6
Kiểm định mô hình ARIMA chi biến EIB
library(tseries)
library(forecast)
modeld1 <- auto.arima(mhnn$EIB)
modeld1
## Series: mhnn$EIB
## ARIMA(1,0,1) with zero mean
##
## Coefficients:
## ar1 ma1
## 0.7338 -0.6183
## s.e. 0.1441 0.1670
##
## sigma^2 = 0.000801: log likelihood = 1067.5
## AIC=-2129 AICc=-2128.95 BIC=-2116.37
# Trích xuất phần dư
d <- residuals(modeld1)
d
## Time Series:
## Start = 1
## End = 497
## Frequency = 1
## [1] 1.155294e-02 -4.441149e-03 -2.423002e-02 -1.872809e-02 1.461712e-02
## [6] 2.365028e-02 9.908452e-03 -1.279636e-02 -2.879717e-02 -1.381762e-02
## [11] 3.845277e-03 1.010046e-02 2.479752e-02 9.489128e-03 2.911668e-02
## [16] 4.509742e-03 -3.113575e-03 5.612816e-02 -4.954224e-02 -7.603445e-03
## [21] -2.512202e-02 8.945211e-03 2.389459e-02 1.894065e-02 1.548940e-02
## [26] -4.408533e-02 1.023753e-02 -3.957462e-03 -1.761519e-02 -6.053956e-03
## [31] -5.633233e-02 2.637313e-02 4.103410e-02 -3.302354e-02 1.997436e-03
## [36] -5.494375e-02 8.787940e-03 -1.299083e-02 6.174248e-02 -9.737914e-03
## [41] 4.552694e-02 -1.946512e-02 2.910726e-02 2.816175e-02 3.809340e-03
## [46] 6.476072e-03 -2.101788e-02 -2.446961e-02 7.537888e-03 1.945442e-03
## [51] 1.935438e-02 -2.123199e-02 1.600329e-02 -2.541449e-03 1.963697e-02
## [56] -5.342517e-03 -1.482161e-02 8.817015e-03 -1.403298e-02 -9.687080e-03
## [61] 6.167808e-03 -1.023586e-02 -2.495674e-02 -3.355472e-02 1.577437e-02
## [66] -5.567233e-03 -1.773856e-01 -2.808960e-02 1.038468e-02 1.183183e-02
## [71] -1.089086e-02 4.268852e-02 -4.779220e-02 2.068021e-02 3.572301e-03
## [76] -2.529208e-02 3.674605e-03 -1.963135e-02 2.418440e-02 -1.165262e-02
## [81] -5.353221e-03 1.656376e-03 6.839423e-02 -2.385963e-03 -1.446915e-02
## [86] -8.419876e-03 1.232595e-02 -1.773562e-03 -3.664879e-02 1.973643e-02
## [91] -1.369175e-03 2.432175e-02 2.553539e-02 -4.831808e-03 4.507205e-02
## [96] -1.035018e-02 -2.804514e-02 -2.116208e-02 -1.450798e-02 -1.065313e-02
## [101] 2.208648e-03 -2.807690e-02 2.456428e-02 -2.346302e-02 5.014742e-03
## [106] 1.821200e-02 1.217863e-02 -2.129250e-02 -2.233627e-03 2.525564e-02
## [111] -5.843496e-04 1.676274e-03 5.008949e-03 3.184503e-03 -1.415876e-02
## [116] 5.365012e-04 6.501094e-02 -5.458080e-02 9.727131e-04 1.300265e-02
## [121] -1.060325e-03 2.442598e-03 -1.626260e-02 -1.920160e-02 -3.204124e-03
## [126] -1.351548e-02 1.653718e-02 -4.152578e-03 -3.881116e-03 7.645286e-03
## [131] -9.768686e-03 2.773899e-03 2.108702e-03 -1.492812e-03 3.484040e-03
## [136] -9.959196e-03 -1.223017e-02 -1.202913e-03 5.786886e-05 2.902442e-03
## [141] 5.572173e-03 4.749111e-03 1.565462e-02 -1.045170e-02 -5.425847e-03
## [146] -6.330018e-03 9.212837e-04 -6.110540e-03 1.123696e-03 -9.586093e-04
## [151] 2.273945e-03 1.927390e-04 1.191722e-04 -3.235854e-03 -6.272020e-03
## [156] 7.738041e-03 6.523413e-03 -4.195756e-03 -3.448770e-03 4.285179e-02
## [161] -1.279708e-02 -1.660368e-02 -4.478967e-03 -8.303832e-04 7.200702e-04
## [166] 2.126212e-03 9.877187e-03 -2.699464e-03 -5.398796e-03 1.494978e-02
## [171] 6.572167e-02 5.715157e-02 -4.756000e-02 1.914901e-02 6.199454e-03
## [176] -2.744009e-02 1.569603e-02 -1.194711e-02 1.141372e-02 1.001346e-02
## [181] -1.631883e-02 4.907071e-02 -7.731441e-02 -2.174487e-02 -1.818212e-02
## [186] 7.354278e-02 5.775021e-02 -2.624681e-03 -6.555408e-03 -9.434855e-03
## [191] -1.884657e-03 2.022690e-02 -2.730415e-02 3.532601e-03 1.876626e-04
## [196] 1.454594e-03 -1.421404e-03 -5.307343e-03 -7.501963e-03 6.760131e-02
## [201] 1.602888e-02 4.445015e-02 -7.405182e-02 -6.174941e-02 -1.945091e-02
## [206] -4.761097e-02 3.894350e-02 -6.563502e-02 -6.097264e-02 1.425781e-03
## [211] -6.195102e-02 -5.750351e-02 -5.426864e-02 -5.156477e-02 -5.136496e-02
## [216] -5.109012e-02 -5.067283e-02 8.791085e-02 -6.670123e-02 7.869561e-02
## [221] 7.257296e-03 -2.723227e-02 1.015567e-02 1.863578e-02 6.528628e-02
## [226] 4.727020e-02 -5.846176e-02 2.150026e-02 1.669523e-02 -7.318248e-02
## [231] -4.509545e-02 7.578600e-02 6.493822e-02 5.797684e-02 5.344799e-02
## [236] 4.853310e-02 1.162144e-02 -3.576195e-02 1.187200e-02 1.536591e-02
## [241] 4.355411e-03 -3.316804e-02 -5.210338e-03 -6.033751e-02 4.124151e-02
## [246] 2.983448e-02 -3.566230e-02 3.657326e-02 -2.266865e-02 -8.547978e-03
## [251] 1.786851e-02 1.692604e-02 2.188349e-02 -2.910010e-02 -6.996934e-02
## [256] -3.879660e-02 4.001503e-02 4.112589e-02 -2.520773e-03 -3.413068e-03
## [261] 1.409518e-02 -7.731956e-03 -3.654360e-02 3.702939e-03 -9.323192e-03
## [266] -1.295833e-02 3.519468e-03 2.174057e-02 -3.241482e-02 -1.914898e-02
## [271] 1.259907e-02 -6.960257e-02 -6.289268e-02 4.862594e-02 -4.623749e-02
## [276] 5.533927e-02 4.625184e-02 -7.858863e-03 5.042657e-02 -3.307734e-02
## [281] -7.152952e-03 -2.388233e-02 -4.861380e-02 -3.809351e-03 5.777302e-03
## [286] 2.285534e-02 -1.930147e-02 1.601798e-02 6.600628e-02 3.735086e-02
## [291] -1.002795e-02 -1.295711e-03 -2.410610e-02 -3.849683e-02 3.716897e-02
## [296] 1.264104e-03 -2.634722e-02 -3.953115e-02 -4.538290e-03 2.909650e-02
## [301] 3.723666e-04 5.433421e-03 4.779161e-03 -1.132932e-02 -4.636344e-03
## [306] 3.635954e-03 -2.292295e-03 3.685857e-02 -6.418484e-03 4.210226e-04
## [311] -1.700763e-02 -9.656190e-03 1.696305e-03 8.925804e-03 1.518830e-02
## [316] 5.860617e-04 6.121453e-03 -1.804323e-03 -1.386308e-02 2.363573e-02
## [321] -1.226145e-02 -2.576388e-02 -5.023103e-03 -1.314274e-02 8.801199e-03
## [326] 1.203334e-02 -1.075764e-02 -6.910274e-03 6.903861e-03 5.598334e-03
## [331] 7.490374e-03 2.217753e-02 -1.371808e-02 -9.138073e-04 2.053824e-03
## [336] -5.835212e-03 -2.337419e-02 1.076148e-02 3.448327e-03 2.867707e-02
## [341] -5.645373e-04 -9.962254e-03 -8.212782e-03 1.089697e-02 3.433573e-02
## [346] 5.282625e-03 -1.138009e-02 2.513115e-02 1.259534e-02 -3.072435e-02
## [351] 1.469717e-02 2.211463e-02 -3.442511e-02 -3.532687e-03 3.228986e-02
## [356] 4.265637e-03 -2.127646e-02 -1.606626e-02 4.700505e-03 -1.335869e-02
## [361] 1.451993e-02 4.843003e-03 1.142462e-02 -1.688063e-03 -1.043744e-03
## [366] -1.733779e-02 3.914308e-03 1.026783e-02 1.109184e-02 -3.280861e-02
## [371] -1.223905e-02 -1.665096e-03 -9.898951e-03 1.793503e-02 5.088137e-03
## [376] -4.795539e-04 -2.965123e-04 -5.124201e-03 2.901675e-03 3.394654e-02
## [381] -1.590377e-02 -1.558934e-02 -3.127177e-02 1.939637e-02 9.686341e-04
## [386] 1.047136e-02 -8.179658e-03 -2.082871e-03 1.780467e-02 2.721502e-02
## [391] 1.445269e-02 6.270607e-02 -3.060506e-02 5.177897e-02 -2.936137e-03
## [396] -1.837055e-04 -5.863379e-04 -1.279769e-03 -2.328265e-03 2.899140e-02
## [401] -1.646604e-02 1.473515e-02 -1.874354e-02 -7.107540e-02 8.354840e-03
## [406] 2.879181e-02 4.655752e-04 2.390077e-03 1.674316e-02 5.863476e-02
## [411] -2.804102e-02 9.167007e-03 2.417034e-02 -2.251724e-02 -1.123195e-03
## [416] -6.944813e-04 -2.417246e-03 -1.985152e-02 1.814072e-02 -4.320729e-04
## [421] -2.671544e-04 -1.651839e-04 -6.725499e-02 -2.436583e-02 2.992761e-02
## [426] -1.871855e-02 9.705560e-03 -6.941801e-02 -3.251889e-02 4.715618e-02
## [431] -3.693519e-02 3.427404e-02 -1.356366e-02 -5.326105e-02 1.941875e-02
## [436] -1.456070e-02 2.784085e-02 1.435020e-02 1.538388e-02 -2.668682e-04
## [441] -1.364284e-02 -7.303204e-05 -1.157266e-02 -1.599385e-03 -1.350043e-02
## [446] 1.120713e-02 3.495042e-02 -8.748351e-04 2.790467e-02 -1.612764e-02
## [451] -5.291063e-02 3.899951e-02 -2.953945e-02 -2.371302e-02 2.232540e-02
## [456] 2.675501e-02 8.836529e-03 8.345420e-03 -1.984601e-02 2.791901e-02
## [461] -5.929824e-03 -2.393281e-02 4.367786e-03 6.587703e-02 3.330323e-03
## [466] -1.084659e-02 -2.940145e-02 -9.524825e-03 1.016286e-02 2.954454e-02
## [471] -4.051051e-02 1.852314e-02 -2.203705e-02 -5.989691e-03 -4.225826e-04
## [476] 7.272639e-03 5.933231e-03 2.127022e-02 -1.076868e-02 1.794357e-02
## [481] 5.283610e-03 8.733587e-05 -7.118809e-03 -5.496585e-04 -3.398586e-04
## [486] -2.687838e-02 -1.065570e-02 -1.596909e-02 2.643604e-02 8.291769e-03
## [491] -9.026653e-03 4.089572e-04 -2.483118e-03 4.723211e-04 2.920403e-04
## [496] 5.645065e-03 -5.194382e-04
Kiểm định Arch LM cho biến BID
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_BID <- ugarchfit(spec = arch_spec, data = mhnn$BID)
residuals <- residuals(arch_BID)
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
arch <- bptest(arch_lm_model)
# Hiển thị kết quả
arch
##
## studentized Breusch-Pagan test
##
## data: arch_lm_model
## BP = 10.165, df = 1, p-value = 0.001431
Kiểm định Arch LM cho biến EIB
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_EIB <- ugarchfit(spec = arch_spec1, data = mhnn$EIB)
residuals1 <- residuals(arch_EIB)
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
arch1 <- bptest(arch_lm_model1)
# Hiển thị kết quả
arch1
##
## studentized Breusch-Pagan test
##
## data: arch_lm_model1
## BP = 1.8834, df = 1, p-value = 0.1699
Chạy mô hình Garch cho biến BID
library(rugarch)
BIDts<- ts(mhnn$BID)
print(BIDts)
## Time Series:
## Start = 1
## End = 497
## Frequency = 1
## [1] -0.009402353 0.025317808 0.031090587 -0.008968670 0.014057739
## [6] 0.067468868 0.042954949 0.005665738 -0.013652089 0.028234512
## [11] -0.028234512 0.067540882 0.013822655 -0.009549144 0.043802623
## [16] -0.018538121 -0.010449416 0.007326040 -0.011536573 -0.001055409
## [21] 0.021932994 0.000000000 -0.010384309 -0.068024060 0.031888353
## [26] -0.022989518 0.018651117 -0.028667895 0.012229169 0.016438726
## [31] -0.008733680 -0.022173857 -0.001121705 -0.019264052 0.009111680
## [36] -0.038132870 0.008211190 0.011614532 -0.024548281 -0.015504187
## [41] -0.026798193 0.011049836 0.021739987 -0.013229297 0.019185241
## [46] -0.011947573 0.044660771 0.009153382 -0.002280503 -0.006872879
## [51] -0.002301497 -0.006936444 0.008087855 -0.043510684 0.019048195
## [56] 0.026761341 -0.001148765 0.019351771 -0.002257337 -0.021702736
## [61] 0.004608303 -0.010398707 -0.027076404 -0.035219183 0.011063420
## [66] -0.009828089 -0.030077455 -0.034955015 0.000000000 0.000000000
## [71] 0.014388737 0.000000000 -0.071314674 0.028867984 0.008097210
## [76] -0.013532006 -0.104603914 0.000000000 0.025183175 -0.031921908
## [81] -0.071382260 0.038439124 0.008338084 -0.071783893 -0.055049652
## [86] 0.012501704 0.067554634 0.012967147 -0.007194042 -0.004334867
## [91] -0.033918447 0.011924297 0.033523059 0.005698938 0.005698568
## [96] 0.012656991 -0.012656991 -0.004254849 -0.012906736 -0.010118571
## [101] -0.004372777 -0.017718406 0.020613811 0.005831111 -0.020492723
## [106] -0.056299787 0.010909518 -0.009358802 0.009358802 -0.021903706
## [111] -0.068784023 0.026760727 0.006561290 0.016271844 0.006449765
## [116] 0.017472071 0.058118221 0.036465713 -0.040929631 0.045214915
## [121] 0.000000000 0.035034776 -0.019466784 0.019466784 -0.036450432
## [126] -0.014398537 0.053608105 -0.009674836 0.002778256 -0.009710639
## [131] -0.008439936 0.004213067 0.020834087 0.002751544 -0.027798697
## [136] -0.002797382 0.004224844 0.000000000 0.026371236 0.021683549
## [141] 0.044551587 -0.012883141 0.020539838 0.000000000 -0.007656697
## [146] -0.005127548 -0.003870278 -0.006493719 -0.002615226 0.023236908
## [151] 0.044886626 -0.012278576 -0.012403043 -0.010051474 -0.006337446
## [156] -0.023147371 0.026948951 -0.005091107 0.000000000 0.002548794
## [161] -0.010205490 0.020307880 0.005027265 -0.012587341 0.013826150
## [166] -0.057830625 -0.029528692 0.008134601 -0.002683829 -0.002721673
## [171] -0.008178873 -0.020776241 -0.007022456 -0.037287468 0.027398084
## [176] -0.011446384 0.011446384 -0.011446384 -0.039624206 0.008934629
## [181] -0.005936328 0.000000000 0.011870866 -0.071862867 -0.017584138
## [186] 0.025482286 -0.025482286 -0.059807042 0.027031760 -0.051289340
## [191] 0.066165740 0.063622147 0.016804803 -0.009124965 0.003028011
## [196] 0.006096953 0.004531447 -0.016728186 -0.071529382 0.030821165
## [201] 0.012700287 0.067123606 -0.002962866 0.021928895 -0.014554672
## [206] -0.010345895 -0.020984399 0.009042452 0.000000000 0.046935250
## [211] 0.035182616 -0.040946694 0.036792061 -0.002789839 -0.072166076
## [216] 0.066594505 -0.001421464 0.008404601 -0.012617668 0.026408414
## [221] 0.025728915 0.015932424 0.051299225 -0.012587341 0.037268959
## [226] 0.002443210 -0.052459974 0.054869877 0.001230097 -0.053531615
## [231] -0.002568359 0.000000000 0.005130138 -0.028458390 0.015612478
## [236] 0.002588226 0.005127548 -0.002574972 -0.002552576 -0.007755593
## [241] 0.002572424 0.010310717 0.000000000 -0.005127548 0.030462693
## [246] 0.046404759 -0.046404759 -0.035645862 0.065180594 -0.009729896
## [251] -0.001243661 0.021855057 -0.015734614 0.007284510 -0.001201300
## [256] 0.004823752 0.008419677 0.067066125 0.005581129 0.003328790
## [261] 0.018689357 -0.030957907 -0.001113614 0.013382164 -0.052344611
## [266] 0.008155176 0.004611845 0.037376323 -0.027031760 0.015850862
## [271] -0.011307325 -0.024159396 0.033210385 -0.022769970 0.013718980
## [276] 0.022488223 0.017598965 0.030125753 -0.020331835 -0.027392883
## [281] 0.012146402 -0.021076044 -0.007888937 -0.003392817 0.034532517
## [286] 0.016307104 -0.010841803 -0.002187459 0.023754779 0.023180082
## [291] -0.007328112 -0.010555944 -0.019256887 -0.026291644 0.038111769
## [296] -0.011820125 0.001071498 -0.020731355 0.000000000 0.016414012
## [301] -0.004360614 -0.007640021 0.009822705 0.000000000 0.004326736
## [306] 0.000000000 0.000000000 -0.006509420 0.002182684 -0.010936608
## [311] 0.010936608 -0.007647986 -0.021029774 -0.006728581 0.000000000
## [316] 0.012309710 -0.011193582 0.012321105 -0.008929641 -0.004507592
## [321] 0.004507592 -0.009010099 -0.011384446 -0.003435586 0.012548378
## [326] -0.004558850 -0.009154621 0.005734672 -0.006875189 0.028356732
## [331] 0.008909919 -0.002201267 0.000000000 0.000000000 -0.002231220
## [336] 0.002231220 -0.004467430 -0.003351100 -0.005618703 0.000000000
## [341] -0.012463130 -0.008024503 0.005734672 -0.008017008 0.011436957
## [346] -0.002261514 0.004543537 -0.002282023 0.018061593 0.000000000
## [351] 0.002241222 -0.010087178 -0.014769578 -0.005741197 0.004605918
## [356] 0.015904857 -0.007933614 -0.003412141 -0.003423823 -0.009196599
## [361] 0.004595919 -0.002282336 0.012591440 0.007917091 0.000000000
## [366] 0.000000000 0.023431698 -0.018913924 -0.026195425 0.026195425
## [371] -0.011307325 0.007933614 -0.009061154 0.007917091 0.058109067
## [376] -0.008557259 0.003214543 0.004286065 -0.003224878 -0.011833023
## [381] 0.010771836 -0.009674796 0.000000000 0.010735983 0.001084142
## [386] 0.007436762 0.004245278 -0.013827369 0.000000000 0.010657039
## [391] 0.020955915 0.018508109 -0.011263304 -0.003091839 0.009246986
## [396] -0.004091498 -0.009308454 -0.035893234 0.004280280 0.019096910
## [401] -0.012698659 0.010589429 -0.008457768 -0.063537332 0.031174094
## [406] 0.004364612 -0.002167595 0.002167595 -0.013176335 0.004427978
## [411] 0.008748357 0.008696879 0.016114551 0.011644964 -0.004208030
## [416] 0.001047719 -0.007429117 -0.010678531 0.010678531 0.000000000
## [421] -0.005337064 0.001084142 -0.022697253 -0.012093125 0.011008740
## [426] -0.011008740 0.018623800 -0.020845164 -0.016755875 0.001117375
## [431] -0.001117375 0.000000000 -0.009061154 -0.056161953 0.022606044
## [436] -0.021413406 0.014335331 -0.005945862 0.002387949 -0.001206677
## [441] 0.003562202 0.008280463 -0.020195132 -0.008450104 -0.031966129
## [446] 0.004974086 0.007428957 -0.004937180 0.024500266 -0.013404953
## [451] -0.004906795 0.035114318 -0.024087081 -0.019707532 -0.004974086
## [456] 0.040416233 -0.003604975 0.007197001 0.000000000 0.025972030
## [461] -0.001156465 -0.015290534 -0.002379458 0.021161588 0.026379930
## [466] -0.009102510 -0.019612552 0.005814579 0.018372405 -0.008006118
## [471] -0.013845734 0.015008150 -0.015008150 0.017972643 0.011516442
## [476] -0.011516442 0.014057739 0.010101096 -0.003775964 0.008788506
## [481] 0.014888612 0.031517760 -0.012004946 0.012004946 -0.007185660
## [486] 0.000000000 -0.002406740 -0.012121361 0.004866190 0.002424244
## [491] 0.012033840 0.015430573 0.017513582 -0.004640380 0.000000000
## [496] -0.007001195 0.016260521
library(lmtest)
BIDspec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(3,1), include.mean =TRUE), distribution.model = 'norm')
print(BIDspec)
##
## *---------------------------------*
## * 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
BIDfit <- ugarchfit(spec = BIDspec, BIDts)
print(BIDfit)
##
## *---------------------------------*
## * 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.000113 0.001082 -0.10476 0.916564
## ar1 0.788022 0.091605 8.60234 0.000000
## ar2 0.005128 0.062224 0.08242 0.934313
## ar3 0.100704 0.048986 2.05578 0.039804
## ma1 -0.880250 0.083035 -10.60096 0.000000
## omega 0.000005 0.000005 0.95662 0.338761
## alpha1 0.014630 0.016861 0.86768 0.385570
## beta1 0.939977 0.013106 71.71924 0.000000
## gamma1 0.067348 0.025143 2.67854 0.007394
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu -0.000113 0.002106 -0.053825 0.957075
## ar1 0.788022 0.058473 13.476756 0.000000
## ar2 0.005128 0.061995 0.082725 0.934070
## ar3 0.100704 0.049300 2.042676 0.041085
## ma1 -0.880250 0.038689 -22.752143 0.000000
## omega 0.000005 0.000021 0.237317 0.812411
## alpha1 0.014630 0.040916 0.357568 0.720666
## beta1 0.939977 0.014531 64.689743 0.000000
## gamma1 0.067348 0.043319 1.554693 0.120019
##
## LogLikelihood : 1206.888
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.8205
## Bayes -4.7443
## Shibata -4.8211
## Hannan-Quinn -4.7906
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.0001522 0.9902
## Lag[2*(p+q)+(p+q)-1][11] 3.7751289 1.0000
## Lag[4*(p+q)+(p+q)-1][19] 6.6676625 0.9345
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.09649 0.7561
## Lag[2*(p+q)+(p+q)-1][5] 3.27964 0.3583
## Lag[4*(p+q)+(p+q)-1][9] 4.73773 0.4689
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.9825 0.500 2.000 0.3216
## ARCH Lag[5] 1.8882 1.440 1.667 0.4965
## ARCH Lag[7] 2.8504 2.315 1.543 0.5422
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.1488
## Individual Statistics:
## mu 0.04957
## ar1 0.20316
## ar2 0.20940
## ar3 0.16055
## ma1 0.25087
## omega 0.08611
## alpha1 0.16855
## beta1 0.18953
## gamma1 0.11350
##
## 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.56258 0.5740
## Negative Sign Bias 0.05868 0.9532
## Positive Sign Bias 0.05887 0.9531
## Joint Effect 0.51794 0.9149
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 33.26 0.02242
## 2 30 42.09 0.05507
## 3 40 57.77 0.02685
## 4 50 64.07 0.07285
##
##
## Elapsed time : 0.7578611
bidst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "std")
bidst1<- ugarchfit(bidst.spec,BIDts)
print(bidst1)
##
## *---------------------------------*
## * 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.000019 0.000656 0.029132 0.976760
## ar1 0.755217 0.102993 7.332726 0.000000
## ar2 0.071969 0.054799 1.313313 0.189077
## ar3 0.069317 0.040126 1.727481 0.084081
## ma1 -0.910602 0.094302 -9.656242 0.000000
## omega 0.000003 0.000006 0.515175 0.606430
## alpha1 0.017523 0.022937 0.763960 0.444891
## beta1 0.948742 0.021952 43.219088 0.000000
## gamma1 0.056696 0.027662 2.049628 0.040401
## shape 4.205016 0.932747 4.508206 0.000007
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000019 0.000673 0.028394 0.977348
## ar1 0.755217 0.054167 13.942500 0.000000
## ar2 0.071969 0.052481 1.371333 0.170271
## ar3 0.069317 0.036909 1.878060 0.060373
## ma1 -0.910602 0.034414 -26.459834 0.000000
## omega 0.000003 0.000016 0.178942 0.857984
## alpha1 0.017523 0.042124 0.415986 0.677420
## beta1 0.948742 0.049240 19.267893 0.000000
## gamma1 0.056696 0.035047 1.617720 0.105723
## shape 4.205016 1.525640 2.756232 0.005847
##
## LogLikelihood : 1228.797
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.9046
## Bayes -4.8199
## Shibata -4.9054
## Hannan-Quinn -4.8714
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.552 0.2128
## Lag[2*(p+q)+(p+q)-1][11] 6.583 0.1658
## Lag[4*(p+q)+(p+q)-1][19] 10.088 0.4537
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1257 0.7229
## Lag[2*(p+q)+(p+q)-1][5] 3.4429 0.3321
## Lag[4*(p+q)+(p+q)-1][9] 5.8213 0.3193
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 1.278 0.500 2.000 0.2583
## ARCH Lag[5] 2.276 1.440 1.667 0.4135
## ARCH Lag[7] 4.313 2.315 1.543 0.3036
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.0145
## Individual Statistics:
## mu 0.09987
## ar1 0.05554
## ar2 0.05071
## ar3 0.05488
## ma1 0.05836
## omega 0.36771
## alpha1 0.10863
## beta1 0.09946
## gamma1 0.10358
## shape 0.09945
##
## 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.63823 0.5236
## Negative Sign Bias 0.15660 0.8756
## Positive Sign Bias 0.07355 0.9414
## Joint Effect 0.57288 0.9026
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 20.22 0.3813
## 2 30 34.61 0.2176
## 3 40 30.89 0.8197
## 4 50 55.21 0.2515
##
##
## Elapsed time : 0.8513491
# Phân phối Student đối xứng (sstd)
bidst1.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "sstd")
bidst2<- ugarchfit(bidst1.spec,BIDts)
print(bidst2)
##
## *---------------------------------*
## * 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.000050 0.000728 0.06831 0.945539
## ar1 0.755251 0.104380 7.23562 0.000000
## ar2 0.071419 0.055179 1.29431 0.195557
## ar3 0.069505 0.040257 1.72655 0.084249
## ma1 -0.910398 0.095654 -9.51760 0.000000
## omega 0.000003 0.000006 0.51177 0.608815
## alpha1 0.017469 0.022958 0.76089 0.446723
## beta1 0.948727 0.022025 43.07574 0.000000
## gamma1 0.056841 0.027790 2.04540 0.040816
## skew 1.005537 0.056541 17.78435 0.000000
## shape 4.197873 0.934579 4.49172 0.000007
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000050 0.000803 0.061942 0.950609
## ar1 0.755251 0.057039 13.240938 0.000000
## ar2 0.071419 0.053587 1.332772 0.182607
## ar3 0.069505 0.036995 1.878748 0.060279
## ma1 -0.910398 0.035916 -25.348241 0.000000
## omega 0.000003 0.000016 0.177326 0.859253
## alpha1 0.017469 0.042414 0.411862 0.680440
## beta1 0.948727 0.049563 19.142006 0.000000
## gamma1 0.056841 0.035246 1.612686 0.106813
## skew 1.005537 0.056181 17.898107 0.000000
## shape 4.197873 1.512106 2.776176 0.005500
##
## LogLikelihood : 1228.802
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.9006
## Bayes -4.8075
## Shibata -4.9016
## Hannan-Quinn -4.8641
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.543 0.2142
## Lag[2*(p+q)+(p+q)-1][11] 6.567 0.1724
## Lag[4*(p+q)+(p+q)-1][19] 10.070 0.4566
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1255 0.7231
## Lag[2*(p+q)+(p+q)-1][5] 3.4426 0.3321
## Lag[4*(p+q)+(p+q)-1][9] 5.8318 0.3180
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 1.279 0.500 2.000 0.2582
## ARCH Lag[5] 2.272 1.440 1.667 0.4142
## ARCH Lag[7] 4.325 2.315 1.543 0.3021
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 2.2114
## Individual Statistics:
## mu 0.09839
## ar1 0.05551
## ar2 0.05035
## ar3 0.05402
## ma1 0.05823
## omega 0.36844
## alpha1 0.10962
## beta1 0.10006
## gamma1 0.10461
## skew 0.12719
## shape 0.09949
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.49 2.75 3.27
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.63786 0.5239
## Negative Sign Bias 0.15810 0.8744
## Positive Sign Bias 0.07102 0.9434
## Joint Effect 0.57316 0.9025
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 20.14 0.3860
## 2 30 33.52 0.2571
## 3 40 30.24 0.8414
## 4 50 58.03 0.1767
##
##
## Elapsed time : 1.16914
# Phân phối Generalized Error Distribution(ged)
bidged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "ged")
bidged1 <- ugarchfit(bidged.spec,BIDts)
print(bidged1)
##
## *---------------------------------*
## * 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.000073 0.000045 1.61362 0.10661
## ar1 0.836107 0.008185 102.15098 0.00000
## ar2 0.087804 0.004732 18.55520 0.00000
## ar3 0.041928 0.004085 10.26358 0.00000
## ma1 -0.987153 0.001298 -760.25737 0.00000
## omega 0.000004 0.000005 0.89496 0.37081
## alpha1 0.014703 0.017627 0.83416 0.40419
## beta1 0.945961 0.016285 58.08836 0.00000
## gamma1 0.055075 0.023186 2.37540 0.01753
## shape 1.080325 0.092369 11.69574 0.00000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000073 0.000008 9.34967 0.00000
## ar1 0.836107 0.005602 149.25218 0.00000
## ar2 0.087804 0.000752 116.77545 0.00000
## ar3 0.041928 0.000603 69.50738 0.00000
## ma1 -0.987153 0.000619 -1595.86546 0.00000
## omega 0.000004 0.000011 0.40313 0.68685
## alpha1 0.014703 0.017616 0.83464 0.40392
## beta1 0.945961 0.014620 64.70417 0.00000
## gamma1 0.055075 0.024792 2.22146 0.02632
## shape 1.080325 0.091677 11.78401 0.00000
##
## LogLikelihood : 1232.26
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.9186
## Bayes -4.8339
## Shibata -4.9193
## Hannan-Quinn -4.8853
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.485 2.229e-01
## Lag[2*(p+q)+(p+q)-1][11] 10.052 8.080e-09
## Lag[4*(p+q)+(p+q)-1][19] 16.010 1.328e-02
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1387 0.7096
## Lag[2*(p+q)+(p+q)-1][5] 3.7653 0.2848
## Lag[4*(p+q)+(p+q)-1][9] 5.7616 0.3265
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.9756 0.500 2.000 0.3233
## ARCH Lag[5] 2.4168 1.440 1.667 0.3863
## ARCH Lag[7] 3.8238 2.315 1.543 0.3727
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.1319
## Individual Statistics:
## mu 0.13956
## ar1 0.04719
## ar2 0.04430
## ar3 0.05003
## ma1 0.09364
## omega 0.08297
## alpha1 0.11221
## beta1 0.09392
## gamma1 0.06809
## shape 0.04957
##
## 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.1230 0.2620
## Negative Sign Bias 0.2211 0.8251
## Positive Sign Bias 0.2423 0.8087
## Joint Effect 1.6610 0.6456
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 19.18 0.4455
## 2 30 27.25 0.5585
## 3 40 32.82 0.7467
## 4 50 48.77 0.4822
##
##
## Elapsed time : 1.773942
# Phân phối Generalized Error Distribution đối xứng ("sged")
bidged.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "sged")
bidged2 <- ugarchfit(bidged.spec,BIDts)
print(bidged2)
##
## *---------------------------------*
## * 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.000074 0.000085 0.86619 0.386385
## ar1 0.836390 0.008064 103.72168 0.000000
## ar2 0.087384 0.004593 19.02538 0.000000
## ar3 0.042156 0.003870 10.89325 0.000000
## ma1 -0.987204 0.001266 -779.53639 0.000000
## omega 0.000004 0.000005 0.89620 0.370145
## alpha1 0.014635 0.017630 0.83015 0.406453
## beta1 0.946002 0.016230 58.28651 0.000000
## gamma1 0.055089 0.023276 2.36681 0.017942
## skew 1.000386 0.022491 44.47894 0.000000
## shape 1.080407 0.092363 11.69746 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000074 0.000025 2.94729 0.003206
## ar1 0.836390 0.005602 149.30365 0.000000
## ar2 0.087384 0.000790 110.57957 0.000000
## ar3 0.042156 0.000595 70.81190 0.000000
## ma1 -0.987204 0.000617 -1598.86225 0.000000
## omega 0.000004 0.000011 0.40383 0.686340
## alpha1 0.014635 0.017624 0.83040 0.406311
## beta1 0.946002 0.014509 65.20130 0.000000
## gamma1 0.055089 0.024757 2.22518 0.026069
## skew 1.000386 0.013511 74.04217 0.000000
## shape 1.080407 0.091713 11.78027 0.000000
##
## LogLikelihood : 1232.26
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.9145
## Bayes -4.8214
## Shibata -4.9155
## Hannan-Quinn -4.8780
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.474 2.248e-01
## Lag[2*(p+q)+(p+q)-1][11] 10.030 9.385e-09
## Lag[4*(p+q)+(p+q)-1][19] 15.982 1.357e-02
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.1384 0.7099
## Lag[2*(p+q)+(p+q)-1][5] 3.7624 0.2852
## Lag[4*(p+q)+(p+q)-1][9] 5.7579 0.3270
## d.o.f=2
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[3] 0.9715 0.500 2.000 0.3243
## ARCH Lag[5] 2.4151 1.440 1.667 0.3866
## ARCH Lag[7] 3.8213 2.315 1.543 0.3731
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.3655
## Individual Statistics:
## mu 0.13926
## ar1 0.04720
## ar2 0.04276
## ar3 0.04966
## ma1 0.09121
## omega 0.08293
## alpha1 0.11269
## beta1 0.09418
## gamma1 0.06832
## skew 0.06332
## shape 0.04960
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 2.49 2.75 3.27
## Individual Statistic: 0.35 0.47 0.75
##
## Sign Bias Test
## ------------------------------------
## t-value prob sig
## Sign Bias 0.9436 0.3458
## Negative Sign Bias 0.1294 0.8971
## Positive Sign Bias 0.1587 0.8740
## Joint Effect 1.2908 0.7313
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 19.18 0.4455
## 2 30 27.73 0.5325
## 3 40 34.11 0.6924
## 4 50 49.18 0.4660
##
##
## Elapsed time : 2.474279
# Tạo danh sách bao gồm các phân phối và ước lượng
BID_list <- list(BIDfit,bidst1,bidst2,bidged1,bidged2)
# Tính toán các thông tin
sii_info_mat <- sapply(BID_list, infocriteria)
print(sii_info_mat)
## [,1] [,2] [,3] [,4] [,5]
## [1,] -4.820475 -4.904617 -4.900612 -4.918553 -4.914529
## [2,] -4.744263 -4.819937 -4.807465 -4.833873 -4.821381
## [3,] -4.821116 -4.905406 -4.901564 -4.919342 -4.915480
## [4,] -4.790562 -4.871380 -4.864052 -4.885316 -4.877968
rownames(sii_info_mat)<-rownames(infocriteria(BIDfit))
print(rownames(sii_info_mat))
## [1] "Akaike" "Bayes" "Shibata" "Hannan-Quinn"
# Ước lượng mô hình Garch(2,2) với phân phối Student đối xứng (sttd)
bidst.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2,2)), mean.model = list(armaOrder = c(3, 1), include.mean = TRUE), distribution.model = "sstd")
bidst2 <- ugarchfit(bidst.spec,BIDts)
print(bidst2)
##
## *---------------------------------*
## * GARCH Model Fit *
## *---------------------------------*
##
## Conditional Variance Dynamics
## -----------------------------------
## GARCH Model : gjrGARCH(2,2)
## Mean Model : ARFIMA(3,0,1)
## Distribution : sstd
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000028 0.000724 0.038327 0.969427
## ar1 0.770523 0.117506 6.557315 0.000000
## ar2 0.060427 0.054872 1.101235 0.270794
## ar3 0.063152 0.039519 1.598009 0.110041
## ma1 -0.908374 0.108951 -8.337468 0.000000
## omega 0.000004 0.000006 0.666968 0.504792
## alpha1 0.021484 0.088328 0.243230 0.807827
## alpha2 0.000001 0.085305 0.000017 0.999986
## beta1 0.653087 0.063230 10.328745 0.000000
## beta2 0.280700 0.057115 4.914613 0.000001
## gamma1 0.212493 0.142424 1.491975 0.135706
## gamma2 -0.135209 0.130408 -1.036816 0.299821
## skew 1.006292 0.057230 17.583189 0.000000
## shape 4.231502 0.874678 4.837783 0.000001
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.000028 0.000757 0.036693 0.970730
## ar1 0.770523 0.057578 13.382242 0.000000
## ar2 0.060427 0.054141 1.116106 0.264377
## ar3 0.063152 0.038205 1.653000 0.098331
## ma1 -0.908374 0.035783 -25.385334 0.000000
## omega 0.000004 0.000012 0.322552 0.747034
## alpha1 0.021484 0.112165 0.191540 0.848102
## alpha2 0.000001 0.106044 0.000014 0.999989
## beta1 0.653087 0.013307 49.079763 0.000000
## beta2 0.280700 0.033648 8.342343 0.000000
## gamma1 0.212493 0.142970 1.486278 0.137206
## gamma2 -0.135209 0.129933 -1.040603 0.298060
## skew 1.006292 0.057326 17.553736 0.000000
## shape 4.231502 0.998305 4.238687 0.000022
##
## LogLikelihood : 1229.938
##
## Information Criteria
## ------------------------------------
##
## Akaike -4.8931
## Bayes -4.7746
## Shibata -4.8946
## Hannan-Quinn -4.8466
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 1.185 0.2764
## Lag[2*(p+q)+(p+q)-1][11] 6.257 0.3248
## Lag[4*(p+q)+(p+q)-1][19] 9.967 0.4738
## d.o.f=4
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.8558 0.3549
## Lag[2*(p+q)+(p+q)-1][11] 6.7278 0.3438
## Lag[4*(p+q)+(p+q)-1][19] 8.4891 0.6201
## d.o.f=4
##
## Weighted ARCH LM Tests
## ------------------------------------
## Statistic Shape Scale P-Value
## ARCH Lag[5] 0.4761 0.500 2.000 0.4902
## ARCH Lag[7] 2.3982 1.473 1.746 0.4225
## ARCH Lag[9] 2.5709 2.402 1.619 0.6469
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 1.9044
## Individual Statistics:
## mu 0.10249
## ar1 0.04944
## ar2 0.04302
## ar3 0.05107
## ma1 0.05009
## omega 0.22021
## alpha1 0.10068
## alpha2 0.09055
## beta1 0.10095
## beta2 0.10152
## gamma1 0.08624
## gamma2 0.08409
## skew 0.12932
## shape 0.09004
##
## 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 0.4827 0.6295
## Negative Sign Bias 0.7732 0.4398
## Positive Sign Bias 0.0247 0.9803
## Joint Effect 0.6297 0.8896
##
##
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
## group statistic p-value(g-1)
## 1 20 18.86 0.4662
## 2 30 21.33 0.8468
## 3 40 31.05 0.8141
## 4 50 38.31 0.8646
##
##
## Elapsed time : 1.799646
# Trích xuất chuỗi phần dư v của chuỗi lợi suất AGR
bid.res <- residuals(bidst2)/sigma(bidst2)
fitdist(distribution = "sstd", bid.res, control = list())
## $pars
## mu sigma skew shape
## 0.01715115 1.03799308 1.01914732 3.89117200
##
## $convergence
## [1] 0
##
## $values
## [1] 709.5176 678.7749 678.7749
##
## $lagrange
## [1] 0
##
## $hessian
## [,1] [,2] [,3] [,4]
## [1,] 675.905857 -42.46921 -266.742764 -4.640171
## [2,] -42.469209 458.27743 12.771585 36.568972
## [3,] -266.742764 12.77159 384.524076 3.936309
## [4,] -4.640171 36.56897 3.936309 4.586604
##
## $ineqx0
## NULL
##
## $nfuneval
## [1] 91
##
## $outer.iter
## [1] 2
##
## $elapsed
## Time difference of 0.06324887 secs
##
## $vscale
## [1] 1 1 1 1 1
bid.res
## m.c.seq.row..seq.n...seq.col..drop...FALSE.
## 0001-01-01 -0.40583360
## 0002-01-01 1.08837996
## 0003-01-01 1.33681674
## 0004-01-01 -0.24558645
## 0005-01-01 0.54821985
## 0006-01-01 3.02281350
## 0007-01-01 2.16277883
## 0008-01-01 0.59034688
## 0009-01-01 -0.53016249
## 0010-01-01 1.05801230
## ...
## 0488-01-01 -0.90168342
## 0489-01-01 0.18701453
## 0490-01-01 0.15494975
## 0491-01-01 0.91411870
## 0492-01-01 1.26633042
## 0493-01-01 1.50235198
## 0494-01-01 -0.10439694
## 0495-01-01 0.01947996
## 0496-01-01 -0.58421005
## 0497-01-01 1.13152899
s = pdist("sstd",bid.res, mu = 0.01715115, sigma = 1.03799308, skew = 1.01914732, shape = 3.89117200 )
s
## [1] 0.298244028 0.891854823 0.926824003 0.371593439 0.749421987 0.992088614
## [7] 0.977827242 0.764618276 0.248071153 0.886519085 0.081706523 0.985444438
## [13] 0.837336033 0.395286601 0.964115848 0.213684991 0.265154216 0.569968729
## [19] 0.235986740 0.422585427 0.864584540 0.547675952 0.270125284 0.004611508
## [25] 0.745603179 0.101237345 0.762390263 0.097944597 0.653212725 0.779363279
## [31] 0.380787973 0.136942924 0.400069780 0.143375001 0.617582729 0.042802852
## [37] 0.556893468 0.705898065 0.137983197 0.192011690 0.081562682 0.613280694
## [43] 0.857543289 0.310529780 0.827180395 0.286916209 0.968464714 0.777255758
## [49] 0.540323153 0.344126099 0.412668830 0.314357387 0.657544090 0.021156788
## [55] 0.719024975 0.922117172 0.582598845 0.870028173 0.501546699 0.116962996
## [61] 0.525389293 0.236846288 0.067148565 0.041207477 0.577866027 0.263053570
## [67] 0.070366551 0.051219964 0.381096132 0.452612036 0.770520072 0.547772637
## [73] 0.006735004 0.720995299 0.654541052 0.324862682 0.002923602 0.364236728
## [79] 0.772995550 0.186599139 0.026805102 0.745314448 0.627336457 0.038874938
## [85] 0.073490138 0.503793735 0.951039436 0.750209364 0.492726015 0.444514878
## [91] 0.144519100 0.583709731 0.847338229 0.644871077 0.617663286 0.682894334
## [97] 0.348662811 0.420946404 0.291445165 0.319079237 0.394445890 0.226125409
## [103] 0.752279293 0.622215294 0.222387890 0.027836948 0.519962812 0.307032060
## [109] 0.636464848 0.193676407 0.017886848 0.671027783 0.596694353 0.755063886
## [115] 0.642016982 0.773129534 0.970503181 0.937330699 0.112678314 0.911979820
## [121] 0.550396569 0.913109489 0.262618941 0.773915028 0.081212549 0.239073363
## [127] 0.954776507 0.437524112 0.581305744 0.316661715 0.321973100 0.537028860
## [133] 0.824591710 0.607973805 0.110519237 0.374582659 0.534064130 0.502696938
## [139] 0.895154680 0.886842602 0.975817493 0.378971008 0.858837567 0.531237353
## [145] 0.346213740 0.346342951 0.368350219 0.316835758 0.397514605 0.893898837
## [151] 0.983342542 0.379872120 0.233410797 0.210171668 0.284771905 0.074450639
## [157] 0.881845315 0.415192748 0.522525016 0.552198257 0.246152430 0.876986634
## [163] 0.685932785 0.223896405 0.793203751 0.005089747 0.093496727 0.499448557
## [169] 0.421549891 0.444092083 0.309548297 0.121133957 0.289317839 0.033088537
## [175] 0.819797024 0.280460047 0.731858137 0.274615644 0.034659066 0.547355799
## [181] 0.336124175 0.498474276 0.740055800 0.006078666 0.203163978 0.801219142
## [187] 0.165265773 0.021886708 0.705432727 0.032351490 0.946836145 0.979476474
## [193] 0.849673316 0.458237769 0.541107166 0.590209517 0.587380022 0.250060008
## [199] 0.013843242 0.703932383 0.694131000 0.974847633 0.604711627 0.826290919
## [205] 0.313715016 0.323503195 0.173429215 0.579562148 0.491521519 0.951562191
## [211] 0.934639973 0.093497553 0.878939567 0.481925202 0.013712358 0.919595823
## [217] 0.543836007 0.678484638 0.312403632 0.825877626 0.859769712 0.798996289
## [223] 0.966237637 0.412989775 0.925633098 0.604511910 0.033274727 0.921224732
## [229] 0.582921375 0.040322405 0.356977694 0.421122155 0.575020240 0.127040025
## [235] 0.677802400 0.545340659 0.610195625 0.462433155 0.445055252 0.337937717
## [241] 0.520416663 0.689738430 0.528089364 0.400534866 0.916178540 0.977026005
## [247] 0.045335485 0.068372555 0.968064095 0.433632682 0.527922522 0.830805170
## [253] 0.255576761 0.621054952 0.464513719 0.600988008 0.680472192 0.991807752
## [259] 0.775202341 0.669413880 0.836371637 0.075359170 0.405450204 0.726515000
## [265] 0.017444497 0.520063761 0.542773580 0.945417962 0.139290931 0.751846981
## [271] 0.270167060 0.111544883 0.897269694 0.147614344 0.732945884 0.875083754
## [277] 0.861649684 0.943430434 0.198106369 0.079447955 0.627431055 0.119281567
## [283] 0.295655993 0.359673969 0.944324958 0.865363860 0.348009001 0.428643870
## [289] 0.892623691 0.919979915 0.426862449 0.251936843 0.102747927 0.062573400
## [295] 0.932352078 0.295005044 0.543326883 0.103256738 0.429900663 0.820508096
## [301] 0.442025801 0.312948068 0.706431138 0.518733264 0.632392061 0.511733769
## [307] 0.502761554 0.307201221 0.532955004 0.197076445 0.753866501 0.287010484
## [313] 0.069083921 0.242150639 0.423511609 0.812074289 0.225624379 0.806548917
## [319] 0.253801066 0.341062615 0.606830024 0.228756541 0.158850932 0.318791723
## [325] 0.824693072 0.391626600 0.214255094 0.640807884 0.266124415 0.971988851
## [331] 0.851537117 0.530875518 0.504023125 0.486560535 0.405177130 0.569395707
## [337] 0.324154300 0.341953766 0.251882366 0.453098433 0.103261053 0.182180318
## [343] 0.645527407 0.210912172 0.843249679 0.445669309 0.699486186 0.417372054
## [349] 0.947749510 0.597278220 0.644447904 0.144019062 0.068247895 0.212870645
## [355] 0.613710506 0.929618611 0.279193846 0.351251479 0.308755202 0.149648488
## [361] 0.622855177 0.395088039 0.894122104 0.840010990 0.583618965 0.518213572
## [367] 0.977137635 0.061391015 0.023114184 0.913282952 0.174125140 0.753395275
## [373] 0.201724764 0.735937331 0.997945841 0.494364594 0.688261674 0.629926451
## [379] 0.400038605 0.143602916 0.762092013 0.198884371 0.468313725 0.812868456
## [385] 0.588559989 0.775308785 0.689819546 0.114847466 0.430147411 0.820140832
## [391] 0.960632983 0.958501352 0.230486123 0.355925056 0.774604461 0.365560553
## [397] 0.171435013 0.007758264 0.461802873 0.925260391 0.218942580 0.785537711
## [403] 0.247956616 0.002165401 0.781075347 0.630224035 0.512004937 0.552083273
## [409] 0.213309826 0.564809039 0.704525839 0.741073725 0.863040305 0.819879448
## [415] 0.451854812 0.528071383 0.286378760 0.202298644 0.723218307 0.517687405
## [421] 0.355948950 0.504774300 0.057964729 0.165190790 0.711375272 0.217432450
## [427] 0.884502712 0.089083452 0.118530744 0.424019902 0.434576920 0.497781827
## [433] 0.237459635 0.004244073 0.712033949 0.076240904 0.746818039 0.368545064
## [439] 0.563428656 0.468748433 0.591752292 0.713304104 0.120983112 0.255793851
## [445] 0.033049099 0.499497382 0.659188161 0.412525900 0.918445021 0.250247544
## [451] 0.366521177 0.963515280 0.111400770 0.116224647 0.280340227 0.972820476
## [457] 0.542671527 0.731180537 0.515608431 0.938689827 0.562397313 0.167061811
## [463] 0.367497370 0.900495665 0.956182827 0.374735763 0.093426847 0.557169436
## [469] 0.889426930 0.343444751 0.152753311 0.803125793 0.144675960 0.868093620
## [475] 0.831321932 0.241569458 0.831189852 0.805425956 0.443093472 0.761142806
## [481] 0.885844021 0.981591674 0.279045899 0.830851010 0.277653735 0.478926849
## [487] 0.381996734 0.137040490 0.591211003 0.575236361 0.857432204 0.918319235
## [493] 0.943252082 0.442110472 0.506025824 0.228305442 0.898998955
library("copula")
library("scatterplot3d")
#Chuyển đôi dữ liệu phân phối đều
u <- pobs(s)
u
## [1] 0.295180723 0.883534137 0.923694779 0.373493976 0.744979920 0.995983936
## [7] 0.983935743 0.765060241 0.238955823 0.877510040 0.088353414 0.991967871
## [13] 0.833333333 0.395582329 0.961847390 0.198795181 0.259036145 0.588353414
## [19] 0.222891566 0.425702811 0.857429719 0.566265060 0.263052209 0.008032129
## [25] 0.740963855 0.100401606 0.763052209 0.098393574 0.670682731 0.783132530
## [31] 0.383534137 0.132530120 0.401606426 0.140562249 0.638554217 0.052208835
## [37] 0.576305221 0.708835341 0.136546185 0.174698795 0.086345382 0.634538153
## [43] 0.847389558 0.305220884 0.821285141 0.283132530 0.967871486 0.781124498
## [49] 0.550200803 0.341365462 0.411646586 0.313253012 0.674698795 0.026104418
## [55] 0.718875502 0.917670683 0.600401606 0.863453815 0.497991968 0.120481928
## [61] 0.532128514 0.224899598 0.064257028 0.050200803 0.594377510 0.257028112
## [67] 0.072289157 0.056224900 0.385542169 0.461847390 0.767068273 0.568273092
## [73] 0.014056225 0.720883534 0.672690763 0.329317269 0.004016064 0.361445783
## [79] 0.769076305 0.172690763 0.032128514 0.738955823 0.648594378 0.046184739
## [85] 0.074297189 0.504016064 0.947791165 0.746987952 0.485943775 0.453815261
## [91] 0.146586345 0.606425703 0.839357430 0.666666667 0.640562249 0.688755020
## [97] 0.349397590 0.419678715 0.289156627 0.321285141 0.391566265 0.212851406
## [103] 0.751004016 0.644578313 0.206827309 0.034136546 0.524096386 0.297188755
## [109] 0.658634538 0.176706827 0.024096386 0.680722892 0.618473896 0.757028112
## [115] 0.662650602 0.771084337 0.969879518 0.931726908 0.114457831 0.899598394
## [121] 0.570281124 0.901606426 0.255020080 0.773092369 0.084337349 0.228915663
## [127] 0.951807229 0.443775100 0.598393574 0.315261044 0.323293173 0.548192771
## [133] 0.813253012 0.630522088 0.108433735 0.375502008 0.546184739 0.500000000
## [139] 0.891566265 0.879518072 0.977911647 0.379518072 0.849397590 0.542168675
## [145] 0.343373494 0.345381526 0.369477912 0.317269076 0.397590361 0.887550201
## [151] 0.989959839 0.381526104 0.220883534 0.190763052 0.279116466 0.076305221
## [157] 0.871485944 0.415662651 0.530120482 0.574297189 0.234939759 0.867469880
## [163] 0.690763052 0.208835341 0.789156627 0.010040161 0.094377510 0.493975904
## [169] 0.423694779 0.451807229 0.303212851 0.128514056 0.287148594 0.040160643
## [175] 0.805220884 0.277108434 0.728915663 0.267068273 0.044176707 0.564257028
## [181] 0.331325301 0.491967871 0.734939759 0.012048193 0.188755020 0.793172691
## [187] 0.160642570 0.028112450 0.706827309 0.036144578 0.943775100 0.985943775
## [193] 0.841365462 0.465863454 0.552208835 0.612449799 0.608433735 0.240963855
## [199] 0.020080321 0.702811245 0.698795181 0.975903614 0.626506024 0.819277108
## [205] 0.311244980 0.325301205 0.166666667 0.596385542 0.483935743 0.949799197
## [211] 0.929718876 0.096385542 0.869477912 0.479919679 0.018072289 0.911646586
## [217] 0.560240964 0.684738956 0.307228916 0.817269076 0.851405622 0.791164659
## [223] 0.963855422 0.413654618 0.921686747 0.624497992 0.042168675 0.915662651
## [229] 0.602409639 0.048192771 0.357429719 0.421686747 0.590361446 0.130522088
## [235] 0.682730924 0.562248996 0.632530120 0.469879518 0.455823293 0.333333333
## [241] 0.528112450 0.694779116 0.538152610 0.403614458 0.905622490 0.979919679
## [247] 0.054216867 0.068273092 0.965863454 0.439759036 0.534136546 0.823293173
## [253] 0.251004016 0.642570281 0.471887550 0.622489960 0.686746988 0.993975904
## [259] 0.777108434 0.678714859 0.831325301 0.078313253 0.407630522 0.724899598
## [265] 0.022088353 0.526104418 0.556224900 0.941767068 0.138554217 0.748995984
## [271] 0.265060241 0.112449799 0.893574297 0.150602410 0.730923695 0.865461847
## [277] 0.853413655 0.937751004 0.180722892 0.082329317 0.650602410 0.124497992
## [283] 0.293172691 0.359437751 0.939759036 0.859437751 0.347389558 0.433734940
## [289] 0.885542169 0.913654618 0.431726908 0.246987952 0.102409639 0.062248996
## [295] 0.927710843 0.291164659 0.558232932 0.104417671 0.435742972 0.811244980
## [301] 0.445783133 0.309236948 0.710843373 0.522088353 0.656626506 0.512048193
## [307] 0.502008032 0.299196787 0.544176707 0.178714859 0.755020080 0.285140562
## [313] 0.070281124 0.232931727 0.427710843 0.801204819 0.210843373 0.799196787
## [319] 0.248995984 0.335341365 0.628514056 0.216867470 0.156626506 0.319277108
## [325] 0.815261044 0.389558233 0.200803213 0.660642570 0.261044177 0.971887550
## [331] 0.843373494 0.540160643 0.506024096 0.481927711 0.405622490 0.586345382
## [337] 0.327309237 0.337349398 0.244979920 0.463855422 0.106425703 0.170682731
## [343] 0.668674699 0.192771084 0.837349398 0.457831325 0.700803213 0.417670683
## [349] 0.945783133 0.620481928 0.664658635 0.144578313 0.066265060 0.194779116
## [355] 0.636546185 0.925702811 0.273092369 0.351405622 0.301204819 0.152610442
## [361] 0.646586345 0.393574297 0.889558233 0.835341365 0.604417671 0.520080321
## [367] 0.981927711 0.060240964 0.030120482 0.903614458 0.168674699 0.753012048
## [373] 0.184738956 0.732931727 0.997991968 0.487951807 0.692771084 0.652610442
## [379] 0.399598394 0.142570281 0.761044177 0.182730924 0.473895582 0.803212851
## [385] 0.610441767 0.779116466 0.696787149 0.116465863 0.437751004 0.809236948
## [391] 0.957831325 0.955823293 0.218875502 0.353413655 0.775100402 0.363453815
## [397] 0.164658635 0.016064257 0.467871486 0.919678715 0.204819277 0.787148594
## [403] 0.236947791 0.002008032 0.785140562 0.654618474 0.514056225 0.572289157
## [409] 0.196787149 0.584337349 0.704819277 0.736947791 0.855421687 0.807228916
## [415] 0.459839357 0.536144578 0.281124498 0.186746988 0.722891566 0.518072289
## [421] 0.355421687 0.508032129 0.058232932 0.158634538 0.712851406 0.202811245
## [427] 0.873493976 0.090361446 0.122489960 0.429718876 0.441767068 0.489959839
## [433] 0.226907631 0.006024096 0.714859438 0.080321285 0.742971888 0.371485944
## [439] 0.582329317 0.475903614 0.616465863 0.716867470 0.126506024 0.253012048
## [445] 0.038152610 0.495983936 0.676706827 0.409638554 0.909638554 0.242971888
## [451] 0.365461847 0.959839357 0.110441767 0.118473896 0.275100402 0.973895582
## [457] 0.554216867 0.726907631 0.516064257 0.933734940 0.580321285 0.162650602
## [463] 0.367469880 0.897590361 0.953815261 0.377510040 0.092369478 0.578313253
## [469] 0.881526104 0.339357430 0.154618474 0.795180723 0.148594378 0.861445783
## [475] 0.829317269 0.230923695 0.827309237 0.797188755 0.449799197 0.759036145
## [481] 0.875502008 0.987951807 0.271084337 0.825301205 0.269076305 0.477911647
## [487] 0.387550201 0.134538153 0.614457831 0.592369478 0.845381526 0.907630522
## [493] 0.935742972 0.447791165 0.510040161 0.214859438 0.895582329
k <- pobs(d)
k
## [1] 0.730923695 0.395582329 0.152610442 0.202811245 0.759036145 0.847389558
## [7] 0.700803213 0.269076305 0.120481928 0.246987952 0.608433735 0.704819277
## [13] 0.859437751 0.694779116 0.893574297 0.618473896 0.417670683 0.961847390
## [19] 0.058232932 0.341365462 0.144578313 0.690763052 0.849397590 0.811244980
## [25] 0.773092369 0.072289157 0.710843373 0.401606426 0.208835341 0.361445783
## [31] 0.038152610 0.867469880 0.925702811 0.100401606 0.564257028 0.040160643
## [37] 0.680722892 0.263052209 0.971887550 0.315261044 0.939759036 0.190763052
## [43] 0.891566265 0.881526104 0.606425703 0.656626506 0.182730924 0.148594378
## [49] 0.668674699 0.562248996 0.815261044 0.178714859 0.781124498 0.425702811
## [55] 0.821285141 0.377510040 0.232931727 0.684738956 0.242971888 0.317269076
## [61] 0.652610442 0.303212851 0.146586345 0.094377510 0.779116466 0.369477912
## [67] 0.002008032 0.122489960 0.714859438 0.734939759 0.287148594 0.931726908
## [73] 0.062248996 0.827309237 0.598393574 0.142570281 0.602409639 0.188755020
## [79] 0.853413655 0.279116466 0.375502008 0.556224900 0.989959839 0.433734940
## [85] 0.238955823 0.331325301 0.742971888 0.447791165 0.084337349 0.823293173
## [91] 0.459839357 0.855421687 0.865461847 0.387550201 0.937751004 0.301204819
## [97] 0.126506024 0.180722892 0.236947791 0.297188755 0.572289157 0.124497992
## [103] 0.857429719 0.162650602 0.630522088 0.805220884 0.740963855 0.174698795
## [109] 0.439759036 0.863453815 0.485943775 0.558232932 0.628514056 0.586345382
## [115] 0.240963855 0.536144578 0.977911647 0.042168675 0.546184739 0.748995984
## [121] 0.469879518 0.578313253 0.220883534 0.196787149 0.415662651 0.255020080
## [127] 0.787148594 0.399598394 0.403614458 0.670682731 0.313253012 0.580321285
## [133] 0.568273092 0.455823293 0.592369478 0.309236948 0.275100402 0.465863454
## [139] 0.514056225 0.584337349 0.640562249 0.622489960 0.775100402 0.299196787
## [145] 0.371485944 0.355421687 0.542168675 0.359437751 0.548192771 0.473895582
## [151] 0.574297189 0.522088353 0.518072289 0.413654618 0.357429719 0.672690763
## [157] 0.658634538 0.397590361 0.409638554 0.933734940 0.267068273 0.214859438
## [163] 0.393574297 0.479919679 0.540160643 0.570281124 0.698795181 0.421686747
## [169] 0.373493976 0.765060241 0.981927711 0.963855422 0.066265060 0.813253012
## [175] 0.654618474 0.130522088 0.777108434 0.277108434 0.726907631 0.702811245
## [181] 0.218875502 0.951807229 0.004016064 0.172690763 0.206827309 0.991967871
## [187] 0.965863454 0.423694779 0.351405622 0.323293173 0.443775100 0.825301205
## [193] 0.132530120 0.596385542 0.520080321 0.554216867 0.457831325 0.379518072
## [199] 0.343373494 0.987951807 0.785140562 0.935742972 0.006024096 0.028112450
## [205] 0.192771084 0.064257028 0.919678715 0.022088353 0.030120482 0.552208835
## [211] 0.026104418 0.036144578 0.044176707 0.050200803 0.052208835 0.054216867
## [217] 0.056224900 0.997991968 0.020080321 0.995983936 0.662650602 0.134538153
## [223] 0.706827309 0.809236948 0.979919679 0.945783133 0.034136546 0.831325301
## [229] 0.789156627 0.008032129 0.070281124 0.993975904 0.975903614 0.967871486
## [235] 0.957831325 0.947791165 0.732931727 0.088353414 0.736947791 0.769076305
## [241] 0.614457831 0.096385542 0.381526104 0.032128514 0.929718876 0.897590361
## [247] 0.090361446 0.911646586 0.166666667 0.329317269 0.797188755 0.793172691
## [253] 0.835341365 0.118473896 0.012048193 0.078313253 0.923694779 0.927710843
## [259] 0.427710843 0.411646586 0.751004016 0.339357430 0.086345382 0.604417671
## [265] 0.325301205 0.265060241 0.594377510 0.833333333 0.106425703 0.198795181
## [271] 0.746987952 0.014056225 0.024096386 0.949799197 0.068273092 0.959839357
## [277] 0.941767068 0.337349398 0.953815261 0.098393574 0.345381526 0.158634538
## [283] 0.060240964 0.405622490 0.646586345 0.843373494 0.194779116 0.783132530
## [289] 0.985943775 0.917670683 0.305220884 0.461847390 0.154618474 0.080321285
## [295] 0.915662651 0.550200803 0.138554217 0.076305221 0.391566265 0.889558233
## [301] 0.526104418 0.638554217 0.624497992 0.285140562 0.389558233 0.600401606
## [307] 0.437751004 0.913654618 0.353413655 0.530120482 0.212851406 0.319277108
## [313] 0.560240964 0.688755020 0.767068273 0.538152610 0.650602410 0.445783133
## [319] 0.244979920 0.845381526 0.271084337 0.140562249 0.385542169 0.261044177
## [325] 0.682730924 0.738955823 0.293172691 0.349397590 0.660642570 0.642570281
## [331] 0.666666667 0.839357430 0.248995984 0.475903614 0.566265060 0.367469880
## [337] 0.164658635 0.718875502 0.590361446 0.883534137 0.487951807 0.307228916
## [343] 0.333333333 0.720883534 0.907630522 0.634538153 0.283132530 0.861445783
## [349] 0.744979920 0.110441767 0.761044177 0.837349398 0.092369478 0.407630522
## [355] 0.901606426 0.612449799 0.176706827 0.224899598 0.620481928 0.259036145
## [361] 0.757028112 0.626506024 0.728915663 0.449799197 0.471887550 0.210843373
## [367] 0.610441767 0.712851406 0.722891566 0.102409639 0.273092369 0.451807229
## [373] 0.311244980 0.799196787 0.632530120 0.493975904 0.502008032 0.383534137
## [379] 0.582329317 0.903614458 0.228915663 0.230923695 0.108433735 0.817269076
## [385] 0.544176707 0.716867470 0.335341365 0.441767068 0.795180723 0.873493976
## [391] 0.755020080 0.973895582 0.112449799 0.955823293 0.419678715 0.508032129
## [397] 0.483935743 0.463855422 0.435742972 0.887550201 0.216867470 0.763052209
## [403] 0.200803213 0.010040161 0.678714859 0.885542169 0.532128514 0.576305221
## [409] 0.791164659 0.969879518 0.128514056 0.692771084 0.851405622 0.168674699
## [415] 0.467871486 0.481927711 0.431726908 0.184738956 0.803212851 0.495983936
## [421] 0.504016064 0.510040161 0.018072289 0.150602410 0.899598394 0.204819277
## [427] 0.696787149 0.016064257 0.104417671 0.943775100 0.082329317 0.905622490
## [433] 0.253012048 0.046184739 0.819277108 0.234939759 0.875502008 0.753012048
## [439] 0.771084337 0.506024096 0.251004016 0.512048193 0.281124498 0.453815261
## [445] 0.257028112 0.724899598 0.909638554 0.477911647 0.877510040 0.222891566
## [451] 0.048192771 0.921686747 0.114457831 0.160642570 0.841365462 0.871485944
## [457] 0.686746988 0.676706827 0.186746988 0.879518072 0.365461847 0.156626506
## [463] 0.616465863 0.983935743 0.588353414 0.289156627 0.116465863 0.321285141
## [469] 0.708835341 0.895582329 0.074297189 0.807228916 0.170682731 0.363453815
## [475] 0.497991968 0.664658635 0.648594378 0.829317269 0.291164659 0.801204819
## [481] 0.636546185 0.516064257 0.347389558 0.489959839 0.500000000 0.136546185
## [487] 0.295180723 0.226907631 0.869477912 0.674698795 0.327309237 0.528112450
## [493] 0.429718876 0.534136546 0.524096386 0.644578313 0.491967871
# 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 497 2-dimensional observations.
## Normal copula, dim. d = 2
## Estimate Std. Error
## rho.1 0.3023 0.04
## The maximized loglikelihood is 22.93
## Optimization converged
## Number of loglikelihood evaluations:
## function gradient
## 7 7
# Kiểm định Anderson_Darling
library(nortest)
ad.test(s)
##
## Anderson-Darling normality test
##
## data: s
## A = 4.9749, p-value = 2.564e-12
# Kiểm định Cramer-von Mises
cvm.test(s)
##
## Cramer-von Mises normality test
##
## data: s
## W = 0.6398, p-value = 1.755e-07
# Kiểm định Kolmogorov-Smirnov
ks.test(s, y = "punif")
##
## Asymptotic one-sample Kolmogorov-Smirnov test
##
## data: s
## D = 0.025954, p-value = 0.8913
## alternative hypothesis: two-sided
#
mycop<-normalCopula(c(0.25),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(497,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(497,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)