Using their daily close prices, I want to model the dependency among three major indices, the SP500, SSEC, HSI, TASI, and DAX. I need to align the three-time series with the common trading days among them and omit other days.
Here is my attempt which always results in an error:
library(quantmod)
# Fetch daily close prices
sp500 <- getSymbols("^GSPC", src = "yahoo", auto.assign = FALSE, from = "2017-10-09", to = "2022-09-29")
ssec <- getSymbols("000001.SS", src = "yahoo", auto.assign = FALSE, from = "2017-10-09", to = "2022-09-29")
hsi <- getSymbols("^HSI", src = "yahoo", auto.assign = FALSE, from = "2017-10-09", to = "2022-09-29")
tasi <- getSymbols("^TASI.SR", src = "yahoo", auto.assign = FALSE, from = "2017-10-09", to = "2022-09-29")
dax <- getSymbols("^GDAXI", src = "yahoo", auto.assign = FALSE, from = "2017-10-09", to = "2022-09-29")
# Align the data
all_dates <- Reduce(intersect, list(index(sp500), index(ssec), index(hsi), index(tasi), index(dax)))
sp500_aligned <- Cl(sp500)[all_dates]
ssec_aligned <- Cl(ssec)[all_dates]
hsi_aligned <- Cl(hsi)[all_dates]
Error
sp500_aligned <- Cl(sp500)[all_dates]
Error in[.xts
(Cl(sp500), all_dates) : subscript out of bounds