library(knitr)
library(copula)
## Warning: package 'copula' was built under R version 4.4.1
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.1
library(plotly)
## Warning: package 'plotly' was built under R version 4.4.1
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.4.1
library(VC2copula)
## Warning: package 'VC2copula' was built under R version 4.4.1
library(VineCopula)
## Warning: package 'VineCopula' was built under R version 4.4.1
##
## Attaching package: 'VineCopula'
## The following objects are masked from 'package:VC2copula':
##
## BB1Copula, BB6Copula, BB7Copula, BB8Copula, copulaFromFamilyIndex,
## joeBiCopula, r270BB1Copula, r270BB6Copula, r270BB7Copula,
## r270BB8Copula, r270ClaytonCopula, r270GumbelCopula,
## r270JoeBiCopula, r270TawnT1Copula, r270TawnT2Copula, r90BB1Copula,
## r90BB6Copula, r90BB7Copula, r90BB8Copula, r90ClaytonCopula,
## r90GumbelCopula, r90JoeBiCopula, r90TawnT1Copula, r90TawnT2Copula,
## surBB1Copula, surBB6Copula, surBB7Copula, surBB8Copula,
## surClaytonCopula, surGumbelCopula, surJoeBiCopula, surTawnT1Copula,
## surTawnT2Copula, tawnT1Copula, tawnT2Copula, vineCopula
## The following object is masked from 'package:copula':
##
## pobs
library(gridGraphics)
## Warning: package 'gridGraphics' was built under R version 4.4.1
## Loading required package: grid
library(png)
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.1
library(ggcorrplot)
library(ggplot2)
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(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
# Tạo hàm vẽ biểu đồ phân tán và phối cảnh PDF của Copula họ Elip
scatter_plot <- function(random_data, cl) {
ggplot(data.frame(random_data), aes(random_data[,1], random_data[,2])) +
geom_point(alpha = 0.5, col = cl) +
theme_minimal() +
labs(x = "u", y = "v")
} #for scatter
persp_plot <- function(copula_obj, file_name, cl) {
png(file_name)
persp(copula_obj, dCopula,
xlab = 'u', ylab = 'v', col = cl, ltheta = 120,
ticktype = "detailed", cex.axis = 0.8)
dev.off()
rasterGrob(readPNG(file_name),interpolate = TRUE)
}# for pdf
set.seed(123)
#Mô phỏng copula gauss với p=0.8
cop_nor <- normalCopula(param = 0.8, dim = 2)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_nor <- rCopula(copula = cop_nor,n = 7600)
#Mô phỏng copula với p=0.8
cop_std <- tCopula(param = 0.8, dim = 2, df = 1)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_std <- rCopula(copula = cop_std,n = 7600)
#Vẽ biểu đồ
png('nors.png') #Lưu ảnh biểu đồ
scatter_plot(random_nor, '#CCFF33')
dev.off()
## png
## 2
nors <- rasterGrob(readPNG('nors.png'), interpolate = TRUE) #Chuyển ảnh sang dạng Grob
png('stds.png')
scatter_plot(random_std, '#FF33FF')
dev.off()
## png
## 2
stds <- rasterGrob(readPNG('stds.png'), interpolate = TRUE)
nor_per <- persp_plot(cop_nor, 'norp.png', '#CCFF33')
std_per <- persp_plot(cop_std, 'stdp.png', '#FF33FF')
legend <- legendGrob(
labels = c("Gauss", "Student"), pch = 15,
gp = gpar(col = c('#FF33FF', '#CCFF33'), fill = c('#FF33FF', '#CCFF33'))
)
grid.arrange(nors, nor_per, stds, std_per, legend, ncol = 3,
layout_matrix = rbind(c(1, 2, 5), c(3, 4, 5)),
widths = c(2, 2, 1),
top = textGrob("Biểu đồ phân tán và phối cảnh PDF của Copula họ Elip",
gp = gpar(fontsize = 15, font = 2))
)

# Biểu đồ phân tán và PDF của Copula Clayton và Glumbel
set.seed(123)
#Mô phỏng copula clayton với p=4
cop_clay <- claytonCopula(param = 4, dim = 2)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_clay <- rCopula(copula = cop_clay,n = 7600)
#Mô phỏng copula gumbel với p=5
cop_gum <- gumbelCopula(param = 5, dim = 2)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_gum <- rCopula(copula = cop_gum,n = 7600)
#Vẽ biểu đồ
png('clays.png')
scatter_plot(random_clay,'#00CCFF')
dev.off()
## png
## 2
clays <- rasterGrob(readPNG('clays.png'), interpolate = TRUE)
png('gums.png')
scatter_plot(random_gum,'#FFFF00')
dev.off()
## png
## 2
gums <- rasterGrob(readPNG('gums.png'), interpolate = TRUE)
png('clays.png')
scatter_plot(random_clay,'#00CCFF')
dev.off()
## png
## 2
clays <- rasterGrob(readPNG('clays.png'), interpolate = TRUE)
png('gums.png')
scatter_plot(random_gum,'#FFFF00')
dev.off()
## png
## 2
gums <- rasterGrob(readPNG('gums.png'), interpolate = TRUE)
clayp <- persp_plot(cop_clay,'clayp.png','#00CCFF')
gump <- persp_plot(cop_gum,'gump.png','#FFFF00')
legend <- legendGrob(
labels = c("Clayton", "Gumbel"), pch = 15,
gp = gpar(col = c('#00CCFF', '#FFFF00'), fill = c('#00CCFF', '#FFFF00'))
)
grid.arrange(clays, clayp, gums, gump, legend, ncol = 3,
layout_matrix = rbind(c(1, 2, 5), c(3, 4, 5)),
widths = c(2, 2, 1),
top = textGrob("Biểu đồ phân tán và PDF của Copula Clayton và Gumbel",
gp = gpar(fontsize = 15, font = 2))
)

# Biểu đồ phân tán và PDF của Copula Sur Clayton và Glumbel
set.seed(123)
#Mô phỏng copula survival gumbel
cop_surgum <- VC2copula::surGumbelCopula(param = 5)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_surgum <- rCopula(copula = cop_surgum,n = 7600)
#Mô phỏng copula survival clayton với p=4
cop_surclay <- VC2copula::surClaytonCopula(param = 4)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_surclay <- rCopula(copula = cop_surclay,n = 7600)
png('surclays.png')
scatter_plot(random_surclay,'#CCFF99')
dev.off()
## png
## 2
surclays <- rasterGrob(readPNG('surclays.png'), interpolate = TRUE)
png('surgums.png')
scatter_plot(random_surgum,'#9999FF')
dev.off()
## png
## 2
surgums <- rasterGrob(readPNG('surgums.png'), interpolate = TRUE)
surclayp <- persp_plot(cop_surclay, "surclayp.png","#CCFF99")
surgump <- persp_plot(cop_surgum, "surgump.png","#9999FF")
legend <- legendGrob(labels = c("Survival Clayton","Survival Gumbel"), pch = 15,
gp = gpar(col = c('#CCFF99','#9999FF'), fill = c('#CCFF99','#9999FF' )))
grid.arrange(surclays, surclayp,surgums, surgump, legend, ncol = 3,
layout_matrix = rbind(c(1,2,5),c(3,4,5)),
widths = c(2,2,1),
top = textGrob("Biểu đồ phân tán và PDF của Copula Sur Clayton và Gumbel",
gp = gpar(fontsize = 15, font = 2))
)

# Biểu đồ phân tán và PDF của Copula Frank và Joe
set.seed(123)
#Mô phỏng copula Frank
cop_frank <- frankCopula(param = 9.2)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_frank <- rCopula(copula = cop_frank,n = 7600)
#Mô phỏng copula survival clayton với p=4
cop_joe <- joeCopula(param = 3)
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_joe <- rCopula(copula = cop_joe,n = 7600)
png('franks.png')
scatter_plot(random_frank,'#00FF33')
dev.off()
## png
## 2
franks <- rasterGrob(readPNG('franks.png'), interpolate = TRUE)
png('joes.png')
scatter_plot(random_joe,'#33CCFF')
dev.off()
## png
## 2
joes <- rasterGrob(readPNG('joes.png'), interpolate = TRUE)
frankp <- persp_plot(cop_frank, "frankp.png","#00FF33")
joep <- persp_plot(cop_joe, "joep.png","#33CCFF")
legend <- legendGrob(labels = c("Franl","Joe"), pch = 15,
gp = gpar(col = c('#00FF33','#33CCFF'), fill = c('#00FF33','#33CCFF')))
grid.arrange(franks, frankp,joes, joep, legend, ncol = 3,
layout_matrix = rbind(c(1,2,5),c(3,4,5)),
widths = c(2,2,1),
top = textGrob("Biểu đồ phân tán và PDF của Copula Frank và Joe",
gp = gpar(fontsize = 15, font = 2))
)

# Biểu đồ phân tán và PDF của Copula BB1 và BB6
set.seed(123)
#Mô phỏng copula BB1
cop_bb1 <- VC2copula::BB1Copula(param = c(2,1.7))
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_bb1 <- rCopula(copula = cop_bb1,n = 7600)
#Mô phỏng copula BB6
cop_bb6 <- VC2copula::BB6Copula(param = c(2,4.5))
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_bb6 <- rCopula(copula = cop_bb6,n = 7600)
png('bb1s.png')
scatter_plot(random_bb1,'#FF00FF')
dev.off()
## png
## 2
bb1s <- rasterGrob(readPNG('bb1s.png'), interpolate = TRUE)
png('bb6s.png')
scatter_plot(random_bb6,'#FFFF00')
dev.off()
## png
## 2
bb6s <- rasterGrob(readPNG('bb6s.png'), interpolate = TRUE)
bb1p <- persp_plot(cop_bb1, "bb1p.png","#FF00FF")
bb6p <- persp_plot(cop_bb6, "bb6p.png","#FFFF00")
legend <- legendGrob(labels = c("BB1","BB6"), pch = 15,
gp = gpar(col = c('#FF00FF','#FFFF00'), fill = c('#FF00FF','#FFFF00')))
grid.arrange(bb1s, bb1p,bb6s, bb6p, legend, ncol = 3,
layout_matrix = rbind(c(1,2,5),c(3,4,5)),
widths = c(2,2,1),
top = textGrob("Biểu đồ phân tán và PDF của Copula BB1 và BB6",
gp = gpar(fontsize = 15, font = 2))
)

# Biểu đồ phân tán và PDF cuả Copula BB7 và BB8
set.seed(123)
#Mô phỏng copula BB7
cop_bb7 <- VC2copula::BB7Copula(param = c(2,4.5))
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_bb7 <- rCopula(copula = cop_bb7,n = 7600)
#Mô phỏng copula BB8
cop_bb8 <- VC2copula::BB8Copula(param = c(4,0.8))
#Mô phỏng 7600 quan sát ngẫu nhiên dựa trên copula có sẵn
random_bb8 <- rCopula(copula = cop_bb8,n = 7600)
png('bb7s.png')
scatter_plot(random_bb7,'#99FFCC')
dev.off()
## png
## 2
bb7s <- rasterGrob(readPNG('bb7s.png'), interpolate = TRUE)
png('bb8s.png')
scatter_plot(random_bb8,'#FFFF99')
dev.off()
## png
## 2
bb8s <- rasterGrob(readPNG('bb8s.png'), interpolate = TRUE)
bb7p <- persp_plot(cop_bb7, "bb7p.png","#99FFCC")
bb8p <- persp_plot(cop_bb8, "bb8p.png","#FFFF99")
legend <- legendGrob(labels = c("BB7","BB8"), pch = 15,
gp = gpar(col = c('#99FFCC','#FFFF99'), fill = c('#99FFCC','#FFFF99')))
grid.arrange(bb7s, bb7p,bb8s, bb8p, legend, ncol = 3,
layout_matrix = rbind(c(1,2,5),c(3,4,5)),
widths = c(2,2,1),
top = textGrob("Biểu đồ phân tán và PDF của Copula BB7 và BB8",
gp = gpar(fontsize = 15, font = 2))
)

# Nhập dữ liệu vào R
options(repos = c(CRAN = "https://cloud.r-project.org/"))
install.packages("dplyr")
## Installing package into 'C:/Users/Admin/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'dplyr' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'dplyr'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\Admin\AppData\Local\R\win-library\4.4\00LOCK\dplyr\libs\x64\dplyr.dll
## to C:\Users\Admin\AppData\Local\R\win-library\4.4\dplyr\libs\x64\dplyr.dll:
## Permission denied
## Warning: restored 'dplyr'
##
## The downloaded binary packages are in
## C:\Users\Admin\AppData\Local\Temp\Rtmp6NpjXz\downloaded_packages
install.packages("moments")
## Installing package into 'C:/Users/Admin/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'moments' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Admin\AppData\Local\Temp\Rtmp6NpjXz\downloaded_packages
library(openxlsx)
## Warning: package 'openxlsx' was built under R version 4.4.1
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.4.1
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:copula':
##
## interval
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.1
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:xts':
##
## first, last
## The following object is masked from 'package:gridExtra':
##
## combine
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(moments)
##
## Attaching package: 'moments'
## The following objects are masked from 'package:PerformanceAnalytics':
##
## kurtosis, skewness
dulieu1 <- read.xlsx("C:/Users/Admin/Desktop/mpnn.xlsx",sheet=1 )
dulieu1$VNI <- as.numeric(dulieu1$VNI)
dulieu1$NIKKEI <- as.numeric(dulieu1$NIKKEI)
dulieu1$DATE <- dmy(dulieu1$DATE)
# Thống kê mô tả
dl <- as.data.frame(dulieu1)
c <- dl %>% summarise(Min = min(VNI),
Max = max(VNI),
Mean = mean(VNI),
StDev = sd(VNI),
Skewness = skewness(VNI),
Kurtosis = kurtosis(VNI))
d <- dl %>% summarise(Min = min(NIKKEI),
Max = max(NIKKEI),
Mean = mean(NIKKEI),
StDev = sd(NIKKEI),
Skewness = skewness(NIKKEI),
Kurtosis = kurtosis(NIKKEI))
e <- rbind(c,d)
e
## Min Max Mean StDev Skewness Kurtosis
## 1 0.9473545 1.089038 0.9999596 0.01328254 1.1686463 8.563589
## 2 0.9255995 1.064745 0.9997711 0.01235787 0.1707483 6.211270
# Hệ số tương quan
pearson1<- cor(dulieu1$VNI,dulieu1$NIKKEI, method="pearson")
spearman1 <- cor(dulieu1$VNI,dulieu1$NIKKEI, method="spearman")
kendall1 <- cor(dulieu1$VNI,dulieu1$NIKKEI, method="kendall")
pearson1
## [1] 0.2806682
spearman1
## [1] 0.2585451
kendall1
## [1] 0.1771111
# Ma trận tương quan
df <- dulieu1[,2:3]
cor_matrix <- cor(df, method = "pearson")
cor_matrix
## VNI NIKKEI
## VNI 1.0000000 0.2806682
## NIKKEI 0.2806682 1.0000000
ggcorrplot(cor_matrix,
hc.order = TRUE,
lab = TRUE,
lab_size = 3,
colors = c("blue", "white", "#CCCCFF"))+
ggtitle("Ma trận hệ số tương quan")+ theme(plot.title = element_text(hjust = 0.5, family = "Times New Roman",
size=13))
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
## not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database

## Tùy biến một số dạng
## tròn
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.4.1
## corrplot 0.92 loaded
df <- dulieu1[,2:3]
cor <- cor(df)
cor
## VNI NIKKEI
## VNI 1.0000000 0.2806682
## NIKKEI 0.2806682 1.0000000
round(cor, 2)
## VNI NIKKEI
## VNI 1.00 0.28
## NIKKEI 0.28 1.00
corrplot(cor, type = "upper", order = "hclust",tl.col = "black", tl.srt = 45)

## dạng số
corrplot(cor, method = "number",type = "upper", order = "hclust", tl.col = "black",
tl.srt = 45)

chart.Correlation(df, histogram=TRUE, pch=19)
## Warning in par(usr): argument 1 does not name a graphical parameter

## Sử dụng heatmap() vẽ ma trận tương quan dưới dạng biểu đồ nhiệt
heatmap(
x = cor,
col = colorRampPalette(c("blue", "white", "red"))(20),
symm = TRUE,
cexCol = 0.8,
cexRow = 0.8,
margins = c(10, 10))

# (Biểu đồ thể hiện sự biến động của VNI)
ggplot(dulieu1, aes(x =DATE , y= VNI))+
geom_line()+
labs(title = "VNI",x = "Ngày", y="Độ biến động")+
theme(plot.title = element_text(hjust = 0.5))

# Biểu đồ thể hiện sự biến động của NIKKEI
ggplot(dulieu1, aes(x =DATE , y= NIKKEI))+
geom_line()+
labs(title = "NIKKEI",x = "Ngày", y="Độ biến động")+
theme(plot.title = element_text(hjust = 0.5))

# Biểu đồ SCatter TSG VNI và NIKKEI
dulieu1 %>% ggplot(aes(VNI, NIKKEI)) +
geom_point(col = '#3399FF',shape = TRUE) +
geom_smooth(method = 'lm',se = T, col = '#FF3333') + #thêm đường hồi quy với phương pháp hồi quy tuyến tính
labs(title = 'Biểu đồ Scatter TSG của VNI và NIKKEI', x = 'VNI', y = 'STI')
## `geom_smooth()` using formula = 'y ~ x'

# Mô hình ARMa
install.packages("rugarch")
## Warning: package 'rugarch' is in use and will not be installed
library(rugarch)
length(dulieu1[,2])
## [1] 1544
autoarfima(dulieu1[, 2],ar.max = 2, ma.max = 2, criterion = "AIC", method = "full")$fit
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(1,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.999960 0.000356 2806.1231 0.00000
## ar1 0.051437 0.025460 2.0203 0.04335
## sigma 0.013283 0.000240 55.4324 0.00000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.999960 0.000374 2675.8713 0.00000
## ar1 0.051437 0.033136 1.5523 0.12059
## sigma 0.013283 0.000742 17.8951 0.00000
##
## LogLikelihood : 4483.795
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.8041
## Bayes -5.7938
## Shibata -5.8041
## Hannan-Quinn -5.8003
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.001488 0.9692
## Lag[2*(p+q)+(p+q)-1][2] 0.284971 0.9953
## Lag[4*(p+q)+(p+q)-1][5] 1.139724 0.9238
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 37.56 8.866e-10
## Lag[2*(p+q)+(p+q)-1][2] 54.37 4.441e-15
## Lag[4*(p+q)+(p+q)-1][5] 92.84 0.000e+00
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 61.44 2 4.563e-14
## ARCH Lag[5] 96.25 5 0.000e+00
## ARCH Lag[10] 147.25 10 0.000e+00
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 0.5577
## Individual Statistics:
## mu 0.06957
## ar1 0.06503
## sigma 0.34688
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 0.846 1.01 1.35
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.01872396
autoarfima(dulieu1[, 3],ar.max = 2, ma.max = 2, criterion = "AIC", method = "full")$fit
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
## Warning in .makearfimafitmodel(f = .arfimaLLH, T = T, m = m, timer = timer, :
## rugarch-->warning: failed to invert hessian
##
## *----------------------------------*
## * ARFIMA Model Fit *
## *----------------------------------*
## Mean Model : ARFIMA(2,0,0)
## Distribution : norm
##
## Optimal Parameters
## ------------------------------------
## Estimate Std. Error t value Pr(>|t|)
## mu 0.999772 0.000337 2968.0466 0.000000
## ar1 0.000000 NA NA NA
## ar2 0.066427 0.025523 2.6026 0.009251
## sigma 0.012358 0.000223 55.3595 0.000000
##
## Robust Standard Errors:
## Estimate Std. Error t value Pr(>|t|)
## mu 0.999772 0.000336 2974.0842 0.000000
## ar1 0.000000 NA NA NA
## ar2 0.066427 0.036040 1.8432 0.065307
## sigma 0.012358 0.000359 34.3962 0.000000
##
## LogLikelihood : 4596.552
##
## Information Criteria
## ------------------------------------
##
## Akaike -5.9502
## Bayes -5.9398
## Shibata -5.9502
## Hannan-Quinn -5.9463
##
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 0.08584 0.7695
## Lag[2*(p+q)+(p+q)-1][5] 0.41398 1.0000
## Lag[4*(p+q)+(p+q)-1][9] 2.64757 0.9367
##
## H0 : No serial correlation
##
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
## statistic p-value
## Lag[1] 142.8 0
## Lag[2*(p+q)+(p+q)-1][2] 170.0 0
## Lag[4*(p+q)+(p+q)-1][5] 210.1 0
##
##
## ARCH LM Tests
## ------------------------------------
## Statistic DoF P-Value
## ARCH Lag[2] 157.8 2 0
## ARCH Lag[5] 173.1 5 0
## ARCH Lag[10] 242.0 10 0
##
## Nyblom stability test
## ------------------------------------
## Joint Statistic: 0.6307
## Individual Statistics:
## mu 0.09120
## ar2 0.06583
## sigma 0.47462
##
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic: 0.846 1.01 1.35
## Individual Statistic: 0.35 0.47 0.75
##
##
## Elapsed time : 0.03762698
# ước lượng các dạng mô hình GARCH
## GJR - GARCH(11)VNI
vni.garch11n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "norm")
vni.garch11n.fit <- ugarchfit(spec = vni.garch11n.spec, data = dulieu1[, 2])
vni.garch11t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "std")
vni.garch11t.fit <- ugarchfit(spec = vni.garch11t.spec, data = dulieu1[, 2])
vni.garch11st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sstd")
vni.garch11st.fit <- ugarchfit(spec = vni.garch11st.spec, data = dulieu1[, 2])
vni.garch11g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "ged")
vni.garch11g.fit <- ugarchfit(spec = vni.garch11g.spec, data =dulieu1[, 2])
vni.garch11sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sged")
vni.garch11sg.fit <- ugarchfit(spec = vni.garch11sg.spec, data =dulieu1[, 2])
## GJR-GARCH(12)VNI
vni.garch12n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "norm")
vni.garch12n.fit <- ugarchfit(spec = vni.garch12n.spec, data = dulieu1[, 2])
vni.garch12t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "std")
vni.garch12t.fit <- ugarchfit(spec = vni.garch12t.spec, data = dulieu1[, 2])
vni.garch12st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sstd")
vni.garch12st.fit <- ugarchfit(spec = vni.garch12st.spec, data = dulieu1[, 2])
vni.garch12g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "ged")
vni.garch12g.fit <- ugarchfit(spec = vni.garch12g.spec, data = dulieu1[, 2])
vni.garch12sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sged")
vni.garch12sg.fit <- ugarchfit(spec = vni.garch12sg.spec, data = dulieu1[, 2])
## GJR-GARCH(21)VNI
vni.garch21n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "norm")
vni.garch21n.fit <- ugarchfit(spec = vni.garch21n.spec, data = dulieu1[, 2])
vni.garch21t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "std")
vni.garch21t.fit <- ugarchfit(spec = vni.garch21t.spec, data = dulieu1[, 2])
vni.garch21st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sstd")
vni.garch21st.fit <- ugarchfit(spec = vni.garch21st.spec, data = dulieu1[, 2])
vni.garch21g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)), mean.model= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "ged")
vni.garch21g.fit <- ugarchfit(spec = vni.garch21g.spec, data = dulieu1[, 2])
vni.garch21sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sged")
vni.garch21sg.fit <- ugarchfit(spec = vni.garch21sg.spec, data = dulieu1[, 2])
vni.garch22n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "norm")
vni.garch22n.fit <- ugarchfit(spec = vni.garch22n.spec, data = dulieu1[, 2])
## GJR-GARCH(22)VNI
vni.garch22t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)), mean.model
= list(armaOrder =c(1, 0), include.mean = TRUE), distribution.model = "std")
vni.garch22t.fit <- ugarchfit(spec = vni.garch22t.spec, data = dulieu1[, 2])
vni.garch22st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sstd")
vni.garch22st.fit <- ugarchfit(spec = vni.garch22st.spec, data = dulieu1[, 2])
vni.garch22g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)), mean.model
= list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "ged")
vni.garch22g.fit <- ugarchfit(spec = vni.garch22g.spec, data = dulieu1[, 2])
vni.garch22sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(1, 0), include.mean = TRUE), distribution.model = "sged")
vni.garch22sg.fit <- ugarchfit(spec = vni.garch22sg.spec, data =dulieu1[, 2])
# Các dạng MH GJR-GARCH cho chuỗi lợi suất NIKKEI
## GJR-GARCH(11)NIKKEI
nikkei.garch11n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "norm")
nikkei.garch11n.fit <- ugarchfit(spec = nikkei.garch11n.spec, data = dulieu1[, 3])
nikkei.garch11t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "std")
nikkei.garch11t.fit <- ugarchfit(spec = nikkei.garch11t.spec, data = dulieu1[, 3])
nikkei.garch11st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sstd")
nikkei.garch11st.fit <- ugarchfit(spec = nikkei.garch11st.spec, data = dulieu1[, 3])
nikkei.garch11g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "ged")
nikkei.garch11g.fit <- ugarchfit(spec = nikkei.garch11g.spec, data = dulieu1[, 3])
nikkei.garch11sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sged")
nikkei.garch11sg.fit <- ugarchfit(spec = nikkei.garch11sg.spec, data = dulieu1[, 3])
## GJR-GARCH(12)nikkei
nikkei.garch12n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "norm")
nikkei.garch12n.fit <- ugarchfit(spec = nikkei.garch12n.spec, data = dulieu1[, 3])
nikkei.garch12t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "std")
nikkei.garch12t.fit <- ugarchfit(spec = nikkei.garch12t.spec, data = dulieu1[, 3])
nikkei.garch12st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sstd")
nikkei.garch12st.fit <- ugarchfit(spec = nikkei.garch12st.spec, data = dulieu1[, 3])
nikkei.garch12g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "ged")
nikkei.garch12g.fit <- ugarchfit(spec = nikkei.garch12g.spec, data = dulieu1[, 3])
nikkei.garch12sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sged")
nikkei.garch12sg.fit <- ugarchfit(spec = nikkei.garch12sg.spec, data = dulieu1[, 3])
## GJR-GARCH(21)nikkei
nikkei.garch21n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "norm")
nikkei.garch21n.fit <- ugarchfit(spec = nikkei.garch21n.spec, data = dulieu1[, 3])
nikkei.garch21t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "std")
nikkei.garch21t.fit <- ugarchfit(spec = nikkei.garch21t.spec, data =dulieu1[, 3])
nikkei.garch21st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sstd")
nikkei.garch21st.fit <- ugarchfit(spec = nikkei.garch21st.spec, data = dulieu1[, 3])
nikkei.garch21g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "ged")
nikkei.garch21g.fit <- ugarchfit(spec = nikkei.garch21g.spec, data = dulieu1[, 3])
nikkei.garch21sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 1)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sged")
nikkei.garch21sg.fit <- ugarchfit(spec = nikkei.garch21sg.spec, data = dulieu1[, 3])
## GJR-GARCH(22)nikkei
nikkei.garch22n.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "norm")
nikkei.garch22n.fit <- ugarchfit(spec = nikkei.garch22n.spec, data = dulieu1[, 3])
nikkei.garch22t.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "std")
nikkei.garch22t.fit <- ugarchfit(spec = nikkei.garch22t.spec, data = dulieu1[, 3])
nikkei.garch22st.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sstd")
nikkei.garch22st.fit <- ugarchfit(spec = nikkei.garch22st.spec, data =dulieu1[, 3])
nikkei.garch22g.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "ged")
nikkei.garch22g.fit <- ugarchfit(spec = nikkei.garch22g.spec, data = dulieu1[, 3])
nikkei.garch22sg.spec <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(2, 2)),
mean.model = list(armaOrder = c(2, 0), include.mean = TRUE), distribution.model = "sged")
nikkei.garch22sg.fit <- ugarchfit(spec = nikkei.garch22sg.spec, data = dulieu1[, 3])
# LỰA CHỌN MO HINH GJR-GARCH ###
## Lựa chọn mô hình biên phù hợp nhất cho chuỗi VNI
vni.model.list <- list(
garch11n = vni.garch11n.fit,
garch11t = vni.garch11t.fit,
garch11st = vni.garch11st.fit,
garch11g = vni.garch11g.fit,
garch11sg = vni.garch11sg.fit,
garch12n = vni.garch12n.fit,
garch12t = vni.garch12t.fit,
garch12st = vni.garch12st.fit,
garch12g = vni.garch12g.fit,
garch12sg = vni.garch12sg.fit,
garch21n = vni.garch21n.fit,
garch21t = vni.garch21t.fit,
garch21st = vni.garch21st.fit,
garch21g = vni.garch21g.fit,
garch21sg = vni.garch21sg.fit,
garch22n = vni.garch22n.fit,
garch22t = vni.garch22t.fit,
garch22st = vni.garch22st.fit,
garch22g = vni.garch22g.fit,
garch22sg = vni.garch22sg.fit
)
vni.info.mat <- sapply(vni.model.list, infocriteria)
rownames(vni.info.mat) <- rownames(infocriteria(vni.garch11n.fit))
vni.info.mat
## garch11n garch11t garch11st garch11g garch11sg garch12n
## Akaike -6.009122 -6.201409 -6.219212 -6.182524 -6.202915 -6.009595
## Bayes -5.988363 -6.177189 -6.191532 -6.158304 -6.175236 -5.985376
## Shibata -6.009152 -6.201450 -6.219265 -6.182565 -6.202969 -6.009636
## Hannan-Quinn -6.001400 -6.192399 -6.208915 -6.173514 -6.192619 -6.000586
## garch12t garch12st garch12g garch12sg garch21n garch21t
## Akaike -6.200640 -6.218964 -6.181687 -6.202337 -6.016022 -6.200715
## Bayes -6.172961 -6.187824 -6.154008 -6.171197 -5.988343 -6.169575
## Shibata -6.200694 -6.219031 -6.181741 -6.202404 -6.016075 -6.200782
## Hannan-Quinn -6.190344 -6.207380 -6.171391 -6.190753 -6.005725 -6.189131
## garch21st garch21g garch21sg garch22n garch22t garch22st
## Akaike -6.218050 -6.182146 -6.201940 -6.014727 -6.199805 -6.217599
## Bayes -6.183451 -6.151007 -6.167341 -5.983587 -6.165206 -6.179540
## Shibata -6.218133 -6.182213 -6.202024 -6.014794 -6.199888 -6.217700
## Hannan-Quinn -6.205179 -6.170562 -6.189070 -6.003143 -6.186934 -6.203441
## garch22g garch22sg
## Akaike -6.181200 -6.201198
## Bayes -6.146601 -6.163139
## Shibata -6.181283 -6.201298
## Hannan-Quinn -6.168329 -6.187040
vni.inds <- which(vni.info.mat == min(vni.info.mat), arr.ind=TRUE)
model.vni <- colnames(vni.info.mat)[vni.inds[,2]]
model.vni
## [1] "garch11st"