Tecnológico de Monterrey
Doctor Teófilo Ozuna
Alumna:
Avril Lobato Delgado A00833113
Librerias
library(ggplot2)
library(dplyr)
library(readxl)
library(tidyr)
library(lubridate)
library(purrr)
library(plotly)
library(forecast)
library(readxl)
library(DataExplorer)
library(dplyr)
library(ggplot2)
library(tm)
library(wordcloud)
library(cluster)
library(factoextra)
library(gridExtra)
library(purrr)
library(pROC)
library(rpart)
library(rpart.plot)
library(e1071)
library(ggpubr)
library(dlookr)
library(zoo)
library(caret)
library(stats)
library(tseries)
library(readr)
library(vars)
library(syuzhet)
library(kableExtra)
library(plotly)
library(scales)
library(readxl)
library(readr)
# Especifica el delimitador adecuado (si es necesario)
index_alt <- read_csv("C:/Users/AVRIL/Desktop/Spillovers/all_daily_index.csv")
# Convertir la columna `Date` a tipo Date si está en formato "dd/mm/yyyy"
index_alt$Date <- as.Date(index_alt$Date, format = "%d/%m/%Y")
# Mostrar estructura y resumen
str(index_alt)
## spc_tbl_ [2,052 × 15] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Date : Date[1:2052], format: "2019-01-07" "2019-01-08" ...
## $ AI_INDEX : num [1:2052] 1000 1009 1017 1026 1035 ...
## $ Returns...3 : num [1:2052] NA 0.00865 0.00858 0.00851 0.00844 ...
## $ Cumulative return...4 : num [1:2052] 100 101 102 103 103 ...
## $ Fintech_Index : num [1:2052] 1000 999 999 998 997 ...
## $ Returns...6 : num [1:2052] NA -0.000675 -0.000675 -0.000676 -0.000676 ...
## $ Cumulative return...7 : num [1:2052] 100 99.9 99.9 99.8 99.7 ...
## $ Blockchain_Index : num [1:2052] 1000 1002 1004 1006 1008 ...
## $ Returns...9 : num [1:2052] NA 0.00205 0.00204 0.00204 0.00203 ...
## $ Cumulative return...10: num [1:2052] 100 100 100 101 101 ...
## $ Nasdaq Composite : num [1:2052] 1000 1005 1010 1015 1020 ...
## $ Dax 40 : num [1:2052] 1000 1002 1003 1005 1006 ...
## $ Dow Jones Industrial : num [1:2052] 1000 1003 1007 1010 1014 ...
## $ KFTX Index : num [1:2052] 1000 1012 1023 1029 1028 ...
## $ S&P Financials Index : num [1:2052] 1000 1003 1005 1006 1008 ...
## - attr(*, "spec")=
## .. cols(
## .. Date = col_character(),
## .. AI_INDEX = col_double(),
## .. Returns...3 = col_double(),
## .. `Cumulative return...4` = col_double(),
## .. Fintech_Index = col_double(),
## .. Returns...6 = col_double(),
## .. `Cumulative return...7` = col_double(),
## .. Blockchain_Index = col_double(),
## .. Returns...9 = col_double(),
## .. `Cumulative return...10` = col_double(),
## .. `Nasdaq Composite` = col_double(),
## .. `Dax 40` = col_double(),
## .. `Dow Jones Industrial` = col_double(),
## .. `KFTX Index` = col_double(),
## .. `S&P Financials Index` = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
## Date AI_INDEX Returns...3 Cumulative return...4
## Min. :2019-01-07 Min. :1000 Min. :-0.0180390 Min. :100.0
## 1st Qu.:2020-06-02 1st Qu.:2062 1st Qu.:-0.0026589 1st Qu.:206.2
## Median :2021-10-28 Median :2755 Median : 0.0010241 Median :275.5
## Mean :2021-10-28 Mean :2700 Mean : 0.0007285 Mean :270.0
## 3rd Qu.:2023-03-25 3rd Qu.:3323 3rd Qu.: 0.0050013 3rd Qu.:332.3
## Max. :2024-08-19 Max. :4398 Max. : 0.0165334 Max. :439.8
## NA's :1
## Fintech_Index Returns...6 Cumulative return...7 Blockchain_Index
## Min. : 914.2 Min. :-0.0068872 Min. : 91.42 Min. : 950.4
## 1st Qu.:1051.9 1st Qu.:-0.0009810 1st Qu.:105.19 1st Qu.:1366.1
## Median :1160.8 Median : 0.0003000 Median :116.08 Median :1681.5
## Mean :1209.8 Mean : 0.0002515 Mean :120.98 Mean :1761.8
## 3rd Qu.:1278.8 3rd Qu.: 0.0015300 3rd Qu.:127.88 3rd Qu.:2201.7
## Max. :1737.3 Max. : 0.0054064 Max. :173.73 Max. :2766.4
## NA's :1
## Returns...9 Cumulative return...10 Nasdaq Composite Dax 40
## Min. :-0.0242600 Min. : 95.04 Min. :1000 Min. : 829.2
## 1st Qu.:-0.0020959 1st Qu.:136.61 1st Qu.:1434 1st Qu.:1184.5
## Median : 0.0007566 Median :168.15 Median :1810 Median :1320.3
## Mean : 0.0004415 Mean :176.18 Mean :1798 Mean :1329.4
## 3rd Qu.: 0.0035842 3rd Qu.:220.17 3rd Qu.:2098 3rd Qu.:1459.4
## Max. : 0.0209105 Max. :276.64 Max. :2723 Max. :1743.4
## NA's :1
## Dow Jones Industrial KFTX Index S&P Financials Index
## Min. : 818.2 Min. : 881.8 Min. : 727.6
## 1st Qu.:1185.7 1st Qu.:1289.4 1st Qu.:1153.2
## Median :1409.3 Median :1403.9 Median :1370.8
## Mean :1357.5 Mean :1466.5 Mean :1347.8
## 3rd Qu.:1482.5 3rd Qu.:1680.7 3rd Qu.:1537.2
## Max. :1757.1 Max. :1925.3 Max. :1811.6
##
# Select only the relevant columns for the model
data_selected <- index_alt[, c("Date","AI_INDEX", "Fintech_Index", "Blockchain_Index")]
# Convert to matrix format for the ConnectednessApproach package
data_matrix <- as.matrix(data_selected)
# Convertir a objeto zoo
data_zoo <- zoo(data_selected[, -1], order.by = data_selected$Date)
# Instalar y cargar el paquete ConnectednessApproach, si no está ya instalado
if (!requireNamespace("ConnectednessApproach", quietly = TRUE)) {
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
devtools::install_github("GabauerDavid/ConnectednessApproach")
}
library(ConnectednessApproach)
# Configuración de parámetros para TVPVAR
nlag <- 2 # Orden del rezago
lambda <- c(0.99, 0.99) # Valores de decaimiento para el filtro
# Crear la lista de configuración necesaria
config <- list(l = lambda, nlag = nlag)
# Estimar el modelo TVP-VAR con los parámetros especificados
tvpvar_model <- TVPVAR(data_zoo, configuration = config)
partition = c(pi+0.00001, pi/5, 0)
dca = ConnectednessApproach(data_zoo,
model="TVP-VAR",
connectedness="Frequency",
nlag=1,
nfore=100,
window.size=200,
VAR_config=list(TVPVAR=list(kappa1=0.99, kappa2=0.99, prior="BayesPrior")),
Connectedness_config = list(
FrequencyConnectedness=list(partition=partition, generalized=TRUE, scenario="ABS")
))
AI_INDEX.Total | Fintech_Index.Total | Blockchain_Index.Total | FROM.Total | AI_INDEX.1-5 | Fintech_Index.1-5 | Blockchain_Index.1-5 | FROM.1-5 | AI_INDEX.5-Inf | Fintech_Index.5-Inf | Blockchain_Index.5-Inf | FROM.5-Inf | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
AI_INDEX | 64.70 | 13.88 | 21.42 | 35.30 | 0.91 | 0.11 | 0.10 | 0.21 | 63.79 | 13.76 | 21.32 | 35.08 |
Fintech_Index | 27.91 | 48.62 | 23.47 | 51.38 | 0.17 | 1.03 | 0.14 | 0.32 | 27.74 | 47.59 | 23.32 | 51.06 |
Blockchain_Index | 35.08 | 14.82 | 50.10 | 49.90 | 0.18 | 0.17 | 0.85 | 0.35 | 34.89 | 14.65 | 49.25 | 49.54 |
TO | 62.99 | 28.70 | 44.89 | 136.57 | 0.36 | 0.29 | 0.24 | 0.88 | 62.63 | 28.41 | 44.64 | 135.69 |
Inc.Own | 127.69 | 77.32 | 94.99 | cTCI/TCI | 1.27 | 1.32 | 1.10 | cTCI/TCI | 126.42 | 76.00 | 93.89 | cTCI/TCI |
Net | 27.69 | -22.68 | -5.01 | 68.29/45.52 | 0.14 | -0.03 | -0.11 | 0.44/0.29 | 27.55 | -22.65 | -4.90 | 67.84/45.23 |
NPDC | 2.00 | 0.00 | 1.00 | 2.00 | 1.00 | 0.00 | 2.00 | 0.00 | 1.00 |
______________________________________ ## Transformación de base
de datos
library(knitr)
library(rmgarch)
library(devtools)
library(openxlsx)
library(relaimpo)
library(stargazer)
library(RColorBrewer)
library(PerformanceAnalytics)
library(ConnectednessApproach)
library(readr)
library(readxl)
library(tseries)
library(forecast)
library(urca)
library(fGarch)
library(MTS)
library(MASS)
library(nortest)
library(outliers)
library(moments)
library(FinTS)
library(WeightedPortTest)
# Lee el archivo CSV y selecciona las columnas relevantes
index_alt <- read_csv("C:/Users/AVRIL/Desktop/Spillovers/all_daily_index.csv")
data_selected <- index_alt[, c("Date", "AI_INDEX", "Fintech_Index", "Blockchain_Index")]
# Function for summary statistics
summary_stats <- function(data) {
return(data.frame(
Mean = mean(data, na.rm = TRUE),
StdDev = sd(data, na.rm = TRUE),
Min = min(data, na.rm = TRUE),
P25 = quantile(data, 0.25, na.rm = TRUE),
P50 = median(data, na.rm = TRUE),
P75 = quantile(data, 0.75, na.rm = TRUE),
Max = max(data, na.rm = TRUE),
Skewness = skewness(data, na.rm = TRUE),
Kurtosis = kurtosis(data, na.rm = TRUE)
))
}
# Calculate statistics and tests for each index
results <- data.frame(
Test = c(
"Mean", "Standard Deviation", "Minimum", "25th Percentile", "Median",
"75th Percentile", "Maximum", "Skewness", "Kurtosis", "Jarque-Bera (p-value)",
"ADF Test (p-value)", "KPSS Test (p-value)", "PP Test (p-value)", "ERS Test",
"ARCH Test (p-value)", "Weighted Portmanteau Test (p-value)", "Q2(20) Test (p-value)",
"Outlier detection (Chen and Liu)","Correlation Matrix and R-squared"
),
AI_INDEX = NA, Fintech_Index = NA, Blockchain_Index = NA
)
# Populate the table with summary stats
stats_ai <- summary_stats(data_selected$AI_INDEX)
stats_fintech <- summary_stats(data_selected$Fintech_Index)
stats_blockchain <- summary_stats(data_selected$Blockchain_Index)
results$AI_INDEX[1:9] <- as.numeric(stats_ai)
results$Fintech_Index[1:9] <- as.numeric(stats_fintech)
results$Blockchain_Index[1:9] <- as.numeric(stats_blockchain)
# Normality and stationarity tests
results$AI_INDEX[10] <- jarque.bera.test(data_selected$AI_INDEX)$p.value
results$Fintech_Index[10] <- jarque.bera.test(data_selected$Fintech_Index)$p.value
results$Blockchain_Index[10] <- jarque.bera.test(data_selected$Blockchain_Index)$p.value
results$AI_INDEX[11] <- adf.test(data_selected$AI_INDEX)$p.value
results$Fintech_Index[11] <- adf.test(data_selected$Fintech_Index)$p.value
results$Blockchain_Index[11] <- adf.test(data_selected$Blockchain_Index)$p.value
results$AI_INDEX[12] <- kpss.test(data_selected$AI_INDEX)$p.value
results$Fintech_Index[12] <- kpss.test(data_selected$Fintech_Index)$p.value
results$Blockchain_Index[12] <- kpss.test(data_selected$Blockchain_Index)$p.value
results$AI_INDEX[13] <- pp.test(data_selected$AI_INDEX)$p.value
results$Fintech_Index[13] <- pp.test(data_selected$Fintech_Index)$p.value
results$Blockchain_Index[13] <- pp.test(data_selected$Blockchain_Index)$p.value
results$AI_INDEX[14] <- ur.ers(data_selected$AI_INDEX, type = "DF-GLS")@teststat
results$Fintech_Index[14] <- ur.ers(data_selected$Fintech_Index, type = "DF-GLS")@teststat
results$Blockchain_Index[14] <- ur.ers(data_selected$Blockchain_Index, type = "DF-GLS")@teststat
# ARCH test
results$AI_INDEX[15] <- ArchTest(data_selected$AI_INDEX)$p.value
results$Fintech_Index[15] <- ArchTest(data_selected$Fintech_Index)$p.value
results$Blockchain_Index[15] <- ArchTest(data_selected$Blockchain_Index)$p.value
# Portmanteau test
results$portmanteau_ai <- Weighted.Box.test(data_selected$AI_INDEX)$p.value
results$portmanteau_fintech <- Weighted.Box.test(data_selected$Fintech_Index)$p.value
results$portmanteau_blockchain <- Weighted.Box.test(data_selected$Blockchain_Index)$p.value
# Q2(20) test
results$AI_INDEX[17] <- Box.test(data_selected$AI_INDEX^2, lag = 20, type = "Ljung-Box")$p.value
results$Fintech_Index[17] <- Box.test(data_selected$Fintech_Index^2, lag = 20, type = "Ljung-Box")$p.value
results$Blockchain_Index[17] <- Box.test(data_selected$Blockchain_Index^2, lag = 20, type = "Ljung-Box")$p.value
# Outlier detection (Chen and Liu)
results$outliers_ai <- sum(scores(data_selected$AI_INDEX, type = "chisq", prob = 0.05) != 0)
results$outliers_fintech <- sum(scores(data_selected$Fintech_Index, type = "chisq", prob = 0.05) != 0)
results$outliers_blockchain <- sum(scores(data_selected$Blockchain_Index, type = "chisq", prob = 0.05) != 0)
# Correlation Matrix and R-squared
cor_matrix <- cor(data_selected[, -1], use = "complete.obs")
r_squared <- cor_matrix^2
print(results)
## Test AI_INDEX Fintech_Index
## 1 Mean 2699.7315936 1209.7872783
## 2 Standard Deviation 850.1473182 206.6297993
## 3 Minimum 1000.0000000 914.2184504
## 4 25th Percentile 2062.1671428 1051.8628547
## 5 Median 2755.3700000 1160.7644460
## 6 75th Percentile 3322.8946430 1278.8496108
## 7 Maximum 4397.7200000 1737.2841440
## 8 Skewness -0.0947793 0.9544354
## 9 Kurtosis 2.0739102 2.9587914
## 10 Jarque-Bera (p-value) 0.0000000 0.0000000
## 11 ADF Test (p-value) 0.5827919 0.7454094
## 12 KPSS Test (p-value) 0.0100000 0.0100000
## 13 PP Test (p-value) 0.7266787 0.8964073
## 14 ERS Test 0.9026858 1.9007764
## 15 ARCH Test (p-value) 0.0000000 0.0000000
## 16 Weighted Portmanteau Test (p-value) NA NA
## 17 Q2(20) Test (p-value) 0.0000000 0.0000000
## 18 Outlier detection (Chen and Liu) NA NA
## 19 Correlation Matrix and R-squared NA NA
## Blockchain_Index portmanteau_ai portmanteau_fintech portmanteau_blockchain
## 1 1761.7621693 0 0 0
## 2 464.6372545 0 0 0
## 3 950.4030182 0 0 0
## 4 1366.1408790 0 0 0
## 5 1681.5327235 0 0 0
## 6 2201.7356433 0 0 0
## 7 2766.3975000 0 0 0
## 8 0.2230307 0 0 0
## 9 1.8636058 0 0 0
## 10 0.0000000 0 0 0
## 11 0.8015316 0 0 0
## 12 0.0100000 0 0 0
## 13 0.9193304 0 0 0
## 14 0.2302577 0 0 0
## 15 0.0000000 0 0 0
## 16 NA 0 0 0
## 17 0.0000000 0 0 0
## 18 NA 0 0 0
## 19 NA 0 0 0
## outliers_ai outliers_fintech outliers_blockchain
## 1 1899 1981 1985
## 2 1899 1981 1985
## 3 1899 1981 1985
## 4 1899 1981 1985
## 5 1899 1981 1985
## 6 1899 1981 1985
## 7 1899 1981 1985
## 8 1899 1981 1985
## 9 1899 1981 1985
## 10 1899 1981 1985
## 11 1899 1981 1985
## 12 1899 1981 1985
## 13 1899 1981 1985
## 14 1899 1981 1985
## 15 1899 1981 1985
## 16 1899 1981 1985
## 17 1899 1981 1985
## 18 1899 1981 1985
## 19 1899 1981 1985
library(dplyr)
library(tseries)
library(forecast)
library(rugarch)
# Crear columnas de diferencias para hacer estacionarios los datos
data_selected2 <- data_selected %>%
mutate(
AI_INDEX_diff = c(NA, diff(AI_INDEX, differences = 1)),
Fintech_Index_diff = c(NA, diff(Fintech_Index, differences = 1)),
Blockchain_Index_diff = c(NA, diff(Blockchain_Index, differences = 1))
)
# Remover las filas con NA después de la diferenciación
data_selected2 <- na.omit(data_selected2)
Se realiza análisis de:
ADF Test (Prueba de Dickey-Fuller Aumentada): Este test ayuda a determinar si una serie es estacionaria. Un valor p-value bajo (típicamente < 0.05) sugiere que la serie es estacionaria. En tu caso, ambos índices (AI_INDEX_diff y Fintech_Index_diff) tienen p-values bajos en el ADF, indicando que probablemente sean estacionarios en sus diferencias.
KPSS Test: Contrario al ADF, el KPSS prueba si una serie es no estacionaria. Un p-value bajo indica no estacionariedad. En este caso, los p-values son relativamente altos (> 0.05), lo cual es consistente con la idea de que las series diferenciales son estacionarias.
PP Test (Prueba de Phillips-Perron): No hay datos en la tabla para el PP test, pero este también se usa para confirmar la estacionariedad. Si tienes otros resultados de PP, podrían complementar el análisis.
ERS Test (Elliot-Rothenberg-Stock): Este es otro test para estacionariedad, donde el valor debe ser cercano a cero para indicar estacionariedad. Dado que tienes valores negativos altos, esto también sugiere que las series pueden ser estacionarias.
ARCH Test: Esta prueba evalúa la heterocedasticidad condicional en la serie (es decir, si la varianza cambia con el tiempo). Un p-value bajo (como en este caso, 0.000000 para ambos índices) indica que existe heterocedasticidad, lo cual es común en datos financieros y sugiere la presencia de volatilidad cambiante.
Weighted Portmanteau Test y Q2(20) Test: Ambos sirven para evaluar la autocorrelación en las series de tiempo. Valores p-value extremadamente bajos indican que existe autocorrelación significativa. Esto sugiere que las series tienen dependencia temporal, lo cual es importante para un modelo de series de tiempo como el TVP-VAR.
Outlier Detection: Los valores altos en detección de outliers pueden indicar puntos atípicos que podrían afectar la estabilidad del modelo. En este caso, ambos índices tienen valores altos, lo que sugiere presencia de outliers. Para un TVP-VAR, es importante considerar cómo los outliers podrían influir en los parámetros cambiantes a lo largo del tiempo.
En conclusión, las series son estacionarias, lo cual es un permite generar modelos de series temporales como TVP-VAR. La presencia de autocorrelación y heterocedasticidad es consistente con datos financieros, lo que justifica el uso de un modelo que capture dinámicas temporales cambiantes, como el TVP-VAR. Sin embargo, la detección de outliers sugiere que se necesita un preprocesamiento para no afectar la estabilidad dy/o estimación de los parámetros en el modelo.
# Function for summary statistics
AI_INDEX_diff <- na.omit(data_selected2$AI_INDEX_diff)
Fintech_Index_diff <- na.omit(data_selected2$Fintech_Index_diff)
Blockchain_Index_diff <- na.omit(data_selected2$Blockchain_Index_diff)
summary_stats <- function(data) {
return(data.frame(
Mean = mean(data, na.rm = TRUE),
StdDev = sd(data, na.rm = TRUE),
Min = min(data, na.rm = TRUE),
P25 = quantile(data, 0.25, na.rm = TRUE),
P50 = median(data, na.rm = TRUE),
P75 = quantile(data, 0.75, na.rm = TRUE),
Max = max(data, na.rm = TRUE),
Skewness = skewness(data, na.rm = TRUE),
Kurtosis = kurtosis(data, na.rm = TRUE)
))
}
# Calculate statistics and tests for each differenced index
results <- data.frame(
Test = c(
"Mean", "Standard Deviation", "Minimum", "25th Percentile", "Median",
"75th Percentile", "Maximum", "Skewness", "Kurtosis", "Jarque-Bera (p-value)",
"ADF Test (p-value)", "KPSS Test (p-value)", "PP Test (p-value)", "ERS Test",
"ARCH Test (p-value)", "Weighted Portmanteau Test (p-value)", "Q2(20) Test (p-value)",
"Outlier detection (Chen and Liu)", "Correlation Matrix and R-squared"
),
AI_INDEX_diff = NA, Fintech_Index_diff = NA, Blockchain_Index_diff = NA
)
# Populate the table with summary stats
stats_ai <- summary_stats(data_selected2$AI_INDEX_diff)
stats_fintech <- summary_stats(data_selected2$Fintech_Index_diff)
stats_blockchain <- summary_stats(data_selected2$Blockchain_Index_diff)
results$AI_INDEX_diff[1:9] <- as.numeric(stats_ai)
results$Fintech_Index_diff[1:9] <- as.numeric(stats_fintech)
results$Blockchain_Index_diff[1:9] <- as.numeric(stats_blockchain)
# Normality and stationarity tests
results$AI_INDEX_diff[10] <- jarque.bera.test(data_selected2$AI_INDEX_diff)$p.value
results$Fintech_Index_diff[10] <- jarque.bera.test(data_selected2$Fintech_Index_diff)$p.value
results$Blockchain_Index_diff[10] <- jarque.bera.test(data_selected2$Blockchain_Index_diff)$p.value
#results$AI_INDEX_diff[11] <- adf.test(na.omit(data_selected$AI_INDEX_diff), alternative = "stationary")$p.value
#results$Fintech_Index_diff[11] <- adf.test(na.omit(data_selected$Fintech_Index_diff), alternative = "stationary")$p.value
#results$Blockchain_Index_diff[11] <- adf.test(na.omit(data_selected$Blockchain_Index_diff), alternative = "stationary")$p.value
results$AI_INDEX_diff[12] <- kpss.test(data_selected2$AI_INDEX_diff)$p.value
results$Fintech_Index_diff[12] <- kpss.test(data_selected2$Fintech_Index_diff)$p.value
results$Blockchain_Index_diff[12] <- kpss.test(data_selected2$Blockchain_Index_diff)$p.value
results$AI_INDEX_diff[13] <- pp.test(data_selected2$AI_INDEX_diff)$p.value
results$Fintech_Index_diff[13] <- pp.test(data_selected2$Fintech_Index_diff)$p.value
results$Blockchain_Index_diff[13] <- pp.test(data_selected2$Blockchain_Index_diff)$p.value
results$AI_INDEX_diff[14] <- ur.ers(data_selected2$AI_INDEX_diff, type = "DF-GLS")@teststat
results$Fintech_Index_diff[14] <- ur.ers(data_selected2$Fintech_Index_diff, type = "DF-GLS")@teststat
results$Blockchain_Index_diff[14] <- ur.ers(data_selected2$Blockchain_Index_diff, type = "DF-GLS")@teststat
# ARCH test
results$AI_INDEX_diff[15] <- ArchTest(data_selected2$AI_INDEX_diff)$p.value
results$Fintech_Index_diff[15] <- ArchTest(data_selected2$Fintech_Index_diff)$p.value
results$Blockchain_Index_diff[15] <- ArchTest(data_selected2$Blockchain_Index_diff)$p.value
# Portmanteau test
results$AI_INDEX_diff[16] <- Weighted.Box.test(data_selected2$AI_INDEX_diff)$p.value
results$Fintech_Index_diff[16] <- Weighted.Box.test(data_selected2$Fintech_Index_diff)$p.value
results$Blockchain_Index_diff[16] <- Weighted.Box.test(data_selected2$Blockchain_Index_diff)$p.value
# Q2(20) test
results$AI_INDEX_diff[17] <- Box.test(data_selected2$AI_INDEX_diff^2, lag = 20, type = "Ljung-Box")$p.value
results$Fintech_Index_diff[17] <- Box.test(data_selected2$Fintech_Index_diff^2, lag = 20, type = "Ljung-Box")$p.value
results$Blockchain_Index_diff[17] <- Box.test(data_selected2$Blockchain_Index_diff^2, lag = 20, type = "Ljung-Box")$p.value
# Outlier detection (Chen and Liu)
results$AI_INDEX_diff[18] <- sum(scores(data_selected2$AI_INDEX_diff, type = "chisq", prob = 0.05) != 0)
results$Fintech_Index_diff[18] <- sum(scores(data_selected2$Fintech_Index_diff, type = "chisq", prob = 0.05) != 0)
results$Blockchain_Index_diff[18] <- sum(scores(data_selected2$Blockchain_Index_diff, type = "chisq", prob = 0.05) != 0)
# Correlation Matrix and R-squared
cor_matrix <- cor(data_selected2[, c("AI_INDEX_diff", "Fintech_Index_diff", "Blockchain_Index_diff")], use = "complete.obs")
r_squared <- cor_matrix^2
# Display the final results table
print(results)
## Test AI_INDEX_diff Fintech_Index_diff
## 1 Mean 1.605022e+00 3.260165e-01
## 2 Standard Deviation 1.662849e+01 2.325218e+00
## 3 Minimum -4.960429e+01 -6.911148e+00
## 4 25th Percentile -7.454286e+00 -1.224464e+00
## 5 Median 2.644286e+00 3.266700e-01
## 6 75th Percentile 1.180429e+01 1.755698e+00
## 7 Maximum 4.099429e+01 8.302190e+00
## 8 Skewness -4.090636e-01 6.410631e-02
## 9 Kurtosis 3.295603e+00 3.627935e+00
## 10 Jarque-Bera (p-value) 9.103829e-15 2.387007e-08
## 11 ADF Test (p-value) NA NA
## 12 KPSS Test (p-value) 1.000000e-01 8.650384e-02
## 13 PP Test (p-value) 1.000000e-02 1.000000e-02
## 14 ERS Test -1.417563e+01 -1.281487e+01
## 15 ARCH Test (p-value) 0.000000e+00 0.000000e+00
## 16 Weighted Portmanteau Test (p-value) 1.147220e-320 0.000000e+00
## 17 Q2(20) Test (p-value) 0.000000e+00 0.000000e+00
## 18 Outlier detection (Chen and Liu) 1.890000e+03 1.974000e+03
## 19 Correlation Matrix and R-squared NA NA
## Blockchain_Index_diff
## 1 0.6841407
## 2 9.5406084
## 3 -31.7119610
## 4 -3.7044970
## 5 1.1562560
## 6 5.5124395
## 7 40.7862190
## 8 -0.2052831
## 9 4.9185513
## 10 0.0000000
## 11 NA
## 12 0.1000000
## 13 0.0100000
## 14 -14.2342870
## 15 0.0000000
## 16 0.0000000
## 17 0.0000000
## 18 1890.0000000
## 19 NA
## AI_INDEX_diff Fintech_Index_diff Blockchain_Index_diff
## AI_INDEX_diff 1.00000000 -0.07104258 0.15822325
## Fintech_Index_diff -0.07104258 1.00000000 0.03717008
## Blockchain_Index_diff 0.15822325 0.03717008 1.00000000
## AI_INDEX_diff Fintech_Index_diff Blockchain_Index_diff
## AI_INDEX_diff 1.000000000 0.005047048 0.025034598
## Fintech_Index_diff 0.005047048 1.000000000 0.001381615
## Blockchain_Index_diff 0.025034598 0.001381615 1.000000000
data_zoo2 <- zoo(data_selected2[, c("AI_INDEX_diff", "Fintech_Index_diff", "Blockchain_Index_diff")],
order.by = data_selected2$Date)
# Configuración de parámetros para TVPVAR
nlag <- 2 # Orden del rezago
lambda <- c(0.99, 0.99) # Valores de decaimiento para el filtro
# Crear la lista de configuración necesaria
config <- list(l = lambda, nlag = nlag)
# Estimar el modelo TVP-VAR con los parámetros especificados
tvpvar_model <- TVPVAR(data_zoo2, configuration = config)
dca = ConnectednessApproach(data_zoo2,
nlag=1,
nfore=10,
model="TVP-VAR",
connectedness="Time",
window.size=200,
VAR_config=list(TVPVAR=list(kappa1=0.99, kappa2=0.99, prior="BayesPrior")))
AI_INDEX_diff | Fintech_Index_diff | Blockchain_Index_diff | FROM | |
---|---|---|---|---|
AI_INDEX_diff | 93.53 | 3.12 | 3.36 | 6.47 |
Fintech_Index_diff | 3.33 | 94.12 | 2.55 | 5.88 |
Blockchain_Index_diff | 3.67 | 1.84 | 94.49 | 5.51 |
TO | 7.00 | 4.96 | 5.91 | 17.87 |
Inc.Own | 100.53 | 99.07 | 100.40 | cTCI/TCI |
NET | 0.53 | -0.93 | 0.40 | 8.93/5.96 |
NPT | 2.00 | 0.00 | 1.00 |
# CONNECTEDNESS DECOMPOSITION
int = InternalConnectedness(dca, groups=list("Group1"=c(1), "Group2"=c(2), "Group3"=c(3)))
ext = ExternalConnectedness(dca, groups=list("Group1"=c(1), "Group2"=c(2), "Group3"=c(3)))
kable(int$TABLE)
AI_INDEX_diff | Fintech_Index_diff | Blockchain_Index_diff | FROM | |
---|---|---|---|---|
AI_INDEX_diff | 93.53 | 0.00 | 0.00 | 0.00 |
Fintech_Index_diff | 0.00 | 94.12 | 0.00 | 0.00 |
Blockchain_Index_diff | 0.00 | 0.00 | 94.49 | 0.00 |
TO | 0.00 | 0.00 | 0.00 | 0.00 |
Inc.Own | 93.53 | 94.12 | 94.49 | cTCI/TCI |
NET | 0.00 | 0.00 | 0.00 | 0.00/0.00 |
NPT | 0.00 | 0.00 | 0.00 |
AI_INDEX_diff | Fintech_Index_diff | Blockchain_Index_diff | FROM | |
---|---|---|---|---|
AI_INDEX_diff | 0.00 | 3.12 | 3.36 | 6.47 |
Fintech_Index_diff | 3.33 | 0.00 | 2.55 | 5.88 |
Blockchain_Index_diff | 3.67 | 1.84 | 0.00 | 5.51 |
TO | 7.00 | 4.96 | 5.91 | 17.87 |
Inc.Own | 7.00 | 4.96 | 5.91 | cTCI/TCI |
NET | 0.53 | -0.93 | 0.40 | 8.93/5.96 |
NPT | 2.00 | 0.00 | 1.00 |
# Convierte la columna 'Date' a formato Date
date <- as.Date(data_selected2$Date, format="%d/%m/%Y")
# Crea la serie de tiempo (zoo) solo con las columnas seleccionadas
Y <- zoo(data_selected2[, c("Fintech_Index_diff", "AI_INDEX_diff", "Blockchain_Index_diff")], order.by = date)
# Asegúrate de que los datos sean numéricos y elimina valores NA
Y <- na.omit(zoo(data.frame(
Fintech_Index_diff = as.numeric(data_selected2$Fintech_Index_diff),
AI_INDEX_diff = as.numeric(data_selected2$AI_INDEX_diff),
Blockchain_Index_diff = as.numeric(data_selected2$Blockchain_Index_diff)
), order.by = date))
# Reemplaza los valores NA restantes por 0
Y[is.na(Y)] <- 0
# Establece 'dimnames' de Y con números como índices (como en Y2) sin cambiar el índice de fecha
dimnames(Y) <- list(as.character(1:nrow(Y)), colnames(Y))
NAMES = colnames(Y)
k = ncol(Y)
t = nrow(Y)
# Verifica la estructura de Y
str(Y)
## 'zoo' series from 2019-01-08 to 2024-08-19
## Data: num [1:2051, 1:3] -0.675 -0.675 -0.675 -0.675 -0.675 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:2051] "1" "2" "3" "4" ...
## ..$ : chr [1:3] "Fintech_Index_diff" "AI_INDEX_diff" "Blockchain_Index_diff"
## Index: Date[1:2051], format: "2019-01-08" "2019-01-09" "2019-01-10" "2019-01-11" "2019-01-12" ...
Fintech_Index_diff | AI_INDEX_diff | Blockchain_Index_diff | |
---|---|---|---|
Mean | 0.326*** | 1.605*** | 0.684*** |
(0.000) | (0.000) | (0.001) | |
Variance | 5.407 | 276.507 | 91.023 |
Skewness | 0.064 | -0.409*** | -0.205*** |
(0.235) | (0.000) | (0.000) | |
Ex.Kurtosis | 0.628*** | 0.296** | 1.919*** |
(0.000) | (0.013) | (0.000) | |
JB | 35.101*** | 64.667*** | 328.964*** |
(0.000) | (0.000) | (0.000) | |
ERS | -12.815 | -14.176 | -14.234 |
(0.000) | (0.000) | (0.000) | |
Q(20) | 3862.325*** | 3300.007*** | 3762.681*** |
(0.000) | (0.000) | (0.000) | |
Q2(20) | 3643.339*** | 5087.508*** | 4171.154*** |
(0.000) | (0.000) | (0.000) | |
kendall | Fintech_Index_diff | AI_INDEX_diff | Blockchain_Index_diff |
Fintech_Index_diff | 1.000*** | -0.065*** | 0.016 |
AI_INDEX_diff | -0.065*** | 1.000*** | 0.120*** |
Blockchain_Index_diff | 0.016 | 0.120*** | 1.000*** |
par(mfcol = c(ceiling(k/2),2), oma = c(0, 1, 0, 0) + 0.5, mar = c(1, 1, 1, 1) + 0.5, mgp = c(1, 0.4, 0))
for (i in 1:k) {
plot(date,Y[,i],type='l',las=1,xaxs='i',yaxs='i',ylim=c(-50,50),xlab='',ylab='',main=paste(NAMES[i]),tck=-.02,col='steelblue4')
grid(NA,NULL)
lines(date,Y[,i],col='steelblue4')
abline(h=0,lty=3)
box()
}
spec <- list()
# Itera sobre cada columna de Y
for (i in 1:k) {
# Intenta seleccionar el mejor modelo GARCH para cada serie
u <- tryCatch({
GARCHselection(Y[, i],
distributions = c("norm", "std", "sstd", "ged", "sged"),
models = c("sGARCH", "gjrGARCH", "eGARCH", "iGARCH", "AVGARCH", "TGARCH"))
}, error = function(e) {
warning(paste("Error al seleccionar modelo GARCH para la variable", i, ":", e$message))
NULL
})
# Si 'u' no es NULL y tiene un mejor modelo, agrega a 'spec'
if (!is.null(u) && !is.null(u$best_ugarch)) {
spec[[i]] <- u$best_ugarch
} else {
# Si no se seleccionó un modelo, asigna un modelo GARCH(1,1) por defecto
warning(paste("No se seleccionó ningún modelo GARCH para", NAMES[i], ". Usando modelo GARCH(1,1) con distribución normal"))
spec[[i]] <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(0, 0)),
distribution.model = "norm")
}
}
# Verifica que 'spec' tenga modelos para cada serie en Y
if (length(spec) != k) {
stop("spec no contiene modelos válidos para todas las series de Y")
}
# Ejecuta el modelo DCC-GARCH si spec es válida
fit <- BivariateDCCGARCH(Y, spec)
## [1] "DCC-GARCH estimation based on Fintech_Index_diff and AI_INDEX_diff"
## [1] "DCC-GARCH estimation based on Fintech_Index_diff and Blockchain_Index_diff"
## [1] "DCC-GARCH estimation based on AI_INDEX_diff and Blockchain_Index_diff"
H = fit$H_t
R = fit$R_t
uGARCH_table = NULL
for (i in 1:k) {
fit = ugarchfit(spec[[i]], Y[,i])
gt = GARCHtests(fit, lag=20)
uGARCH_table = rbind(uGARCH_table, gt$TABLE)
}
kable(uGARCH_table)
SignBias | WARCH(20) | VaR | CVaR | VaR Dur. | |
---|---|---|---|---|---|
statistics | 0.1948239 | 0.3148009 | 113.6998 | -93.6559 | 0.1666667 |
pvalues | 0.8455501 | 1.0000000 | 0.0000 | 0.0230 | 0.2505399 |
statistics | 1.8538228 | 4.2396416 | Inf | -2049.9756 | 20.0098039 |
pvalues | 0.0639084 | 0.9801528 | 0.0000 | 1.0000 | 0.0000000 |
statistics | 0.9732951 | 13.9600165 | Inf | -1795.8416 | 10.9705882 |
pvalues | 0.3305217 | 0.1719617 | 0.0000 | 1.0000 | 0.0004832 |
par(mfcol = c(ceiling(k/2),2), oma = c(0, 1, 0, 0) + 0.5, mar = c(1, 1, 1, 1) + 0.5, mgp = c(1, 0.4, 0))
for (j in 1:k) {
plot(date,R[j,j,],type='l',las=1,xaxs='i',yaxs='i',xlab='',ylab='',main=paste(NAMES[j]),tck=-.02,col=j,ylim=c(-1.1,1.1))
grid(NA,NULL)
for (i in 1:k) {
lines(date,R[j,i,],col=i)
abline(h=0,lty=3)
box()
}
legend("bottom",NAMES[-j],fill=c(1:k)[-j],bty="n",cex=0.75,ncol=k)
}
## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |== | 4% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========= | 14% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================ | 24% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================= | 34% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================ | 41% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |============================== | 44% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================ | 64% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |=================================================== | 74% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |========================================================== | 84% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100%
Fintech_Index_diff | AI_INDEX_diff | Blockchain_Index_diff | FROM | |
---|---|---|---|---|
Fintech_Index_diff | 100.00 | 37.80 | 31.55 | 69.35 |
AI_INDEX_diff | 33.59 | 100.00 | 43.99 | 77.57 |
Blockchain_Index_diff | 30.34 | 47.00 | 100.00 | 77.34 |
TO | 63.93 | 84.80 | 75.54 | 224.27 |
Inc.Own | 163.93 | 184.80 | 175.54 | cTCI/TCI |
NET | -5.42 | 7.23 | -1.81 | 112.14/74.76 |
NPT | 0.00 | 2.00 | 1.00 |
r2c = apply(dca$CT,c(1,3),sum)-1
par(mfcol = c(ceiling(k/2),2), oma = c(0, 1, 0, 0) + 0.5, mar = c(1, 1, 1, 1) + 0.5, mgp = c(1, 0.4, 0))
for (j in 1:k) {
r2dd = matrix(0,ncol=k,nrow=t)
for (i in 1:t) {
ded = rep(0,k)
ded[j] = 1
r2dd[i,] = cumsum(dca$CT[j,,i]-ded)
}
plot(date,100*r2c[j,]*NA,type="l",las=1,xlab="",ylab="",ylim=c(0,100),xaxs="i",tck=-0.01,yaxs="i",main=NAMES[j])
grid(NA,NULL)
for (i in k:1) {
polygon(c(date, rev(date)), c(c(rep(0, t)), rev(100*r2dd[,i])), col=i, border=i)
}
box()
legend("topleft",NAMES[-j],fill=c(1:k)[-j],bty="n",cex=0.75,ncol=1)
}
par(mfcol = c(1,1), oma = c(0, 1, 0, 0) + 0.5, mar = c(1, 1, 1, 1) + 0.5, mgp = c(1, 0.4, 0))
plot(date,dca$TCI*NA,type='l',las=1,xaxs='i',yaxs='i',xlab='',ylab='',main='',tck=-.01, ylim=c(0,110))#c(max(c(0,min(TCI)-10)),max(TCI)+10))
grid(NA,NULL)
polygon(c(date, rev(date)), c(c(rep(0, t)), rev(dca$TCI)), col=1, border=1)
box()
par(mfcol = c(ceiling(k/2),2), oma = c(0, 0, 0, 0) + 0.5, mar = c(1, 1, 1, 1) + 0.5, mgp = c(1, 0.4, 0))
for (i in 1:k) {
plot(date,dca$NET[,i]*NA,type='l',las=1,xaxs='i',yaxs='i',ylim=c(-20,20),xlab='',ylab='',main=paste("NET",NAMES[i]),tck=-.025)
grid(NA,NULL)
polygon(c(date, rev(date)), c(c(rep(0, t)), rev(dca$NET[,i])), col=1, border=1)
abline(h=0,lty=3)
box()
}
method = "cumsum"
statistics = "Fisher"
metric = "StdDev"
hr = HedgeRatio(Y/100, H, statistics=statistics, method=method, metric=metric, digit=3)
kable(hr$TABLE)
Mean | Std.Dev. | 5% | 95% | HE | p-value | Return | Std.Dev | SR | |
---|---|---|---|---|---|---|---|---|---|
Fintech_Index_diff/AI_INDEX_diff | -0.007 | 0.204 | -0.322 | 0.312 | 0.159 | 0.001 | 7.325 | 0.339 | 21.638 |
Fintech_Index_diff/Blockchain_Index_diff | 0.028 | 0.372 | -0.582 | 0.662 | 0.219 | 0.000 | 5.956 | 0.326 | 18.264 |
AI_INDEX_diff/Fintech_Index_diff | 44.205 | 1233.519 | -23.939 | 29.336 | -30925.409 | 0.000 | NaN | 464.214 | NaN |
AI_INDEX_diff/Blockchain_Index_diff | 0.303 | 2.634 | -4.300 | 4.424 | 0.139 | 0.000 | NaN | 2.449 | NaN |
Blockchain_Index_diff/Fintech_Index_diff | 43.850 | 1219.484 | -15.240 | 14.257 | -96079.861 | 0.000 | NaN | 469.456 | NaN |
Blockchain_Index_diff/AI_INDEX_diff | 0.070 | 0.772 | -1.138 | 1.198 | 0.272 | 0.001 | NaN | 1.292 | NaN |
mhp = MultivariateHedgingPortfolio(Y/100, H, statistics=statistics, method=method, digit=3)
kable(mhp$TABLE)
Mean | Std.Dev. | 5% | 95% | HE | p-value | Return | Risk | SR | |
---|---|---|---|---|---|---|---|---|---|
Fintech_Index_diff/AI_INDEX_diff | -0.002 | 0.303 | -0.323 | 0.347 | -0.042 | 0.356 | 7.109 | 0.377 | 18.869 |
Fintech_Index_diff/Blockchain_Index_diff | 0.032 | 0.517 | -0.554 | 0.604 | -0.042 | 0.356 | 7.109 | 0.377 | 18.869 |
AI_INDEX_diff/Fintech_Index_diff | 9.773 | 305.244 | -13.666 | 14.813 | -1267.873 | 0.000 | 21512.103 | 94.029 | 228.781 |
AI_INDEX_diff/Blockchain_Index_diff | 0.269 | 8.526 | -3.096 | 3.286 | -1267.873 | 0.000 | 21512.103 | 94.029 | 228.781 |
Blockchain_Index_diff/Fintech_Index_diff | -104.680 | 5196.637 | -7.010 | 7.259 | -574302.289 | 0.000 | 400.170 | 1147.749 | 0.349 |
Blockchain_Index_diff/AI_INDEX_diff | 14.618 | 654.793 | -0.956 | 1.118 | -574302.289 | 0.000 | 400.170 | 1147.749 | 0.349 |
par(mfcol = c(ceiling(k/2),2), oma = c(0, 1, 0, 0) + 0.5, mar = c(1, 1, 1, 1) + 0.5, mgp = c(1, 0.4, 0))
for (j in 1:k) {
plot(date,mhp$Beta[j,j,]*NA,type='l',las=1,xaxs='i',yaxs='i',xlab='',ylab='',
main=paste(NAMES[j]),tck=-.02,col=j,ylim=c(-0.5,80))
grid(NA,NULL)
coefs = lm(Y[,j]~Y[,-j])$coefficients[-1]
for (i in 1:k) {
if (i!=j) {
lines(date,mhp$Beta[j,i,],col=i)
abline(h=0,lty=3)
box()
}
}
col = 1:k
col = col[-j]
abline(h=coefs,lty=3,col=col)
legend("bottom",NAMES[-j],fill=c(1:k)[-j],bty="n",cex=0.6,ncol=k)
}
bpw = BivariatePortfolio(Y/100, H, statistics=statistics, method=method, metric=metric, digit=3)
## The optimal bivariate portfolios are computed according to:
## Kroner, K. F., & Ng, V. K. (1998). Modeling asymmetric comovements of asset returns. The Review of Financial Studies, 11(4), 817-844.
##
## Hedging effectiveness is calculated according to:
## Ederington, L. H. (1979). The hedging performance of the new futures markets. The Journal of Finance, 34(1), 157-170.
##
## Statistics of the hedging effectiveness measure are implemented according to:
## Antonakakis, N., Cunado, J., Filis, G., Gabauer, D., & de Gracia, F. P. (2020). Oil and asset classes implied volatilities: Investment strategies and hedging effectiveness. Energy Economics, 91, 104762.
kable(bpw$TABLE)
Mean | Std.Dev. | 5% | 95% | HE | p-value | SR | |
---|---|---|---|---|---|---|---|
Fintech_Index_diff/AI_INDEX_diff | 0.917 | 0.121 | 0.660 | 1.000 | 0.323 | 0.000 | 20.620 |
Fintech_Index_diff/Blockchain_Index_diff | 0.823 | 0.237 | 0.352 | 1.000 | 0.292 | 0.000 | 15.807 |
AI_INDEX_diff/Fintech_Index_diff | 0.083 | 0.121 | 0.000 | 0.340 | 0.987 | 0.000 | 20.620 |
AI_INDEX_diff/Blockchain_Index_diff | 0.267 | 0.311 | 0.000 | 1.000 | 0.826 | 0.000 | 8.265 |
Blockchain_Index_diff/Fintech_Index_diff | 0.177 | 0.237 | 0.000 | 0.648 | 0.958 | 0.000 | 15.807 |
Blockchain_Index_diff/AI_INDEX_diff | 0.733 | 0.311 | 0.000 | 1.000 | 0.471 | 0.000 | 8.265 |
PCIc = dca$PCI
PCIg = dca$CT
for (l in 1:dim(dca$CT)[3]) {
for (i in 1:k) {
for (j in 1:k) {
PCIg[i,j,l] = (2*R[i,j,l]^2)/(1+R[i,j,l]^2)
}
}
}
mvp = MinimumConnectednessPortfolio(Y/100, H, statistics=statistics, method=method, metric=metric, digit=3)
## The minimum connectedness portfolio is implemented according to:
## Broadstock, D. C., Chatziantoniou, I., & Gabauer, D. (2022). Minimum connectedness portfolios and the market for green bonds: Advocating socially responsible investment (SRI) activity. In Applications in Energy Finance (pp. 217-253). Palgrave Macmillan, Cham.
##
## Hedging effectiveness is calculated according to:
## Ederington, L. H. (1979). The hedging performance of the new futures markets. The Journal of Finance, 34(1), 157-170.
##
## Statistics of the hedging effectiveness measure are implemented according to:
## Antonakakis, N., Cunado, J., Filis, G., Gabauer, D., & de Gracia, F. P. (2020). Oil and asset classes implied volatilities: Investment strategies and hedging effectiveness. Energy Economics, 91, 104762.
mcp = MinimumConnectednessPortfolio(Y/100, R, statistics=statistics, method=method, metric=metric, digit=3)
## The minimum connectedness portfolio is implemented according to:
## Broadstock, D. C., Chatziantoniou, I., & Gabauer, D. (2022). Minimum connectedness portfolios and the market for green bonds: Advocating socially responsible investment (SRI) activity. In Applications in Energy Finance (pp. 217-253). Palgrave Macmillan, Cham.
##
## Hedging effectiveness is calculated according to:
## Ederington, L. H. (1979). The hedging performance of the new futures markets. The Journal of Finance, 34(1), 157-170.
##
## Statistics of the hedging effectiveness measure are implemented according to:
## Antonakakis, N., Cunado, J., Filis, G., Gabauer, D., & de Gracia, F. P. (2020). Oil and asset classes implied volatilities: Investment strategies and hedging effectiveness. Energy Economics, 91, 104762.
mpc = MinimumConnectednessPortfolio(Y/100, PCIc, statistics=statistics, method=method, metric=metric, digit=3)
## The minimum connectedness portfolio is implemented according to:
## Broadstock, D. C., Chatziantoniou, I., & Gabauer, D. (2022). Minimum connectedness portfolios and the market for green bonds: Advocating socially responsible investment (SRI) activity. In Applications in Energy Finance (pp. 217-253). Palgrave Macmillan, Cham.
##
## Hedging effectiveness is calculated according to:
## Ederington, L. H. (1979). The hedging performance of the new futures markets. The Journal of Finance, 34(1), 157-170.
##
## Statistics of the hedging effectiveness measure are implemented according to:
## Antonakakis, N., Cunado, J., Filis, G., Gabauer, D., & de Gracia, F. P. (2020). Oil and asset classes implied volatilities: Investment strategies and hedging effectiveness. Energy Economics, 91, 104762.
mpg = MinimumConnectednessPortfolio(Y/100, PCIg, statistics=statistics, method=method, metric=metric, digit=3)
## The minimum connectedness portfolio is implemented according to:
## Broadstock, D. C., Chatziantoniou, I., & Gabauer, D. (2022). Minimum connectedness portfolios and the market for green bonds: Advocating socially responsible investment (SRI) activity. In Applications in Energy Finance (pp. 217-253). Palgrave Macmillan, Cham.
##
## Hedging effectiveness is calculated according to:
## Ederington, L. H. (1979). The hedging performance of the new futures markets. The Journal of Finance, 34(1), 157-170.
##
## Statistics of the hedging effectiveness measure are implemented according to:
## Antonakakis, N., Cunado, J., Filis, G., Gabauer, D., & de Gracia, F. P. (2020). Oil and asset classes implied volatilities: Investment strategies and hedging effectiveness. Energy Economics, 91, 104762.
mrp = MinimumConnectednessPortfolio(Y/100, dca$CT, statistics=statistics, method=method, metric=metric, digit=3)
## The minimum connectedness portfolio is implemented according to:
## Broadstock, D. C., Chatziantoniou, I., & Gabauer, D. (2022). Minimum connectedness portfolios and the market for green bonds: Advocating socially responsible investment (SRI) activity. In Applications in Energy Finance (pp. 217-253). Palgrave Macmillan, Cham.
##
## Hedging effectiveness is calculated according to:
## Ederington, L. H. (1979). The hedging performance of the new futures markets. The Journal of Finance, 34(1), 157-170.
##
## Statistics of the hedging effectiveness measure are implemented according to:
## Antonakakis, N., Cunado, J., Filis, G., Gabauer, D., & de Gracia, F. P. (2020). Oil and asset classes implied volatilities: Investment strategies and hedging effectiveness. Energy Economics, 91, 104762.
MVA = rbind(mvp$TABLE, mcp$TABLE, mpc$TABLE, mpg$TABLE, mrp$TABLE)
kable(MVA)
Mean | Std.Dev. | 5% | 95% | HE | p-value | SR | |
---|---|---|---|---|---|---|---|
Fintech_Index_diff | 0.733 | 0.260 | 0.205 | 1.000 | 0.080 | 0.060 | 27.348 |
AI_INDEX_diff | 0.083 | 0.114 | 0.000 | 0.303 | 0.982 | 0.000 | 27.348 |
Blockchain_Index_diff | 0.184 | 0.211 | 0.000 | 0.599 | 0.945 | 0.000 | 27.348 |
Fintech_Index_diff | 0.317 | 0.193 | 0.000 | 0.500 | -9.666 | 0.000 | 7.012 |
AI_INDEX_diff | 0.359 | 0.210 | 0.000 | 0.608 | 0.791 | 0.000 | 7.012 |
Blockchain_Index_diff | 0.324 | 0.202 | 0.000 | 0.539 | 0.366 | 0.000 | 7.012 |
Fintech_Index_diff | 0.437 | 0.057 | 0.336 | 0.526 | -4.470 | 0.000 | 2.358 |
AI_INDEX_diff | 0.247 | 0.153 | 0.000 | 0.491 | 0.893 | 0.000 | 2.358 |
Blockchain_Index_diff | 0.316 | 0.142 | 0.000 | 0.496 | 0.675 | 0.000 | 2.358 |
Fintech_Index_diff | 0.442 | 0.121 | 0.000 | 0.527 | -7.446 | 0.000 | 1.280 |
AI_INDEX_diff | 0.201 | 0.244 | 0.000 | 0.523 | 0.835 | 0.000 | 1.280 |
Blockchain_Index_diff | 0.357 | 0.226 | 0.000 | 0.544 | 0.498 | 0.000 | 1.280 |
Fintech_Index_diff | 0.369 | 0.029 | 0.312 | 0.397 | -6.206 | 0.000 | 4.049 |
AI_INDEX_diff | 0.311 | 0.047 | 0.245 | 0.415 | 0.859 | 0.000 | 4.049 |
Blockchain_Index_diff | 0.320 | 0.045 | 0.245 | 0.403 | 0.572 | 0.000 | 4.049 |
library(PerformanceAnalytics)
library(xts)
port.mat = data.frame(
MVP=mvp$portfolio_return,
MCP=mcp$portfolio_return,
MPC=mpc$portfolio_return,
MPG=mpg$portfolio_return,
MRP=mrp$portfolio_return
)
port.xts = xts(port.mat, order.by=date)
ir = matrix(NA, nrow=1, ncol=ncol(port.xts))
colnames(ir) = colnames(port.xts)
rownames(ir) = "GRE"
for (i in 1:ncol(port.xts)) {
ir[,i] = InformationRatio(Ra=port.xts[,i], Rb=Y[,1]/100)
}
k = ncol(port.xts)
table = matrix(NA, ncol=k, nrow=5)
for (i in 1:k) {
table[,i] = c(
# Retorno anualizado
Return.annualized(port.xts[,i]),
# Desviación estándar anualizada
StdDev.annualized(port.xts[,i]),
# Ratio de Sharpe anualizado
SharpeRatio.annualized(port.xts[,i]),
# Valor en Riesgo (VaR) con distribución normal y percentil del 95%
VaR(as.numeric(port.xts[,i]), p=0.95, method="gaussian"),
# Expectativa de Pérdida (ES) con distribución normal y percentil del 95%
ES(as.numeric(port.xts[,i]), p=0.95, method="gaussian")
)
}
colnames(table) = colnames(port.xts)
rownames(table) = c("Return","StdDev","Sharpe Ratio (StdDev)","Sharpe Ratio (VaR)","Sharpe Ratio (CVaR)")
kable(rbind(table, ir))
MVP | MCP | MPC | MPG | MRP | |
---|---|---|---|---|---|
Return | 9.6835486 | 8.4523430 | 2.0357765 | 1.3735988 | 4.0116097 |
StdDev | 0.3540848 | 1.2054953 | 0.8633213 | 1.0727126 | 0.9908285 |
Sharpe Ratio (StdDev) | 27.3481082 | 7.0115107 | 2.3580751 | 1.2804910 | 4.0487427 |
Sharpe Ratio (VaR) | -0.0364074 | -0.1330273 | -0.0876863 | -0.0871908 | -0.1010270 |
Sharpe Ratio (CVaR) | -0.0072764 | -0.0039005 | -0.0002557 | 0.0017861 | -0.0026197 |
GRE | 21.1391511 | 5.7893087 | 1.0376525 | 0.2320275 | 2.8269034 |