Reputation: 457
I am intending to build a code to check the cointegration of two time series of financial price data in order to make better forecasting of one of them.
For this purpose, I chose this two time series: BBVA historical price and IBEX35 and build this little code:
ibex <- new.env()
bbva <- new.env()
library(quantmod)
getSymbols("^IBEX", env = ibex, src = "yahoo", from = as.Date("2010-01-04"), to = as.Date("2015-11-30"))
getSymbols("bbva", env = bbva, src = "yahoo", from = as.Date("2010-01-04"), to = as.Date("2015-11-30"))
ibex <- ibex$IBEX
ibex <- ibex$IBEX.Adjusted
bbva <- bbva$BBVA
bbva <- bbva$BBVA.Adjusted
ldbbva <- diff(log(bbva))
ldibex <- diff(log(ibex))
mean <- mean(ldbbva, na.rm = TRUE)
ldbbva[is.na(ldbbva)] <- mean
mean <- mean(ldibex, na.rm = TRUE)
ldbbva[is.na(ldibex)] <- mean
library(urca)
jotest=ca.jo(data.frame(ldbbva,ldibex), type="trace", K=2, ecdet="none", spec="longrun")
At that point when I try to make a data frame from my time series, I face this error arguments imply differing number of rows: 1488, 1514.
What can I do?
Upvotes: 0
Views: 670
Reputation: 132706
You need to join the time series to have them properly aligned.
dat <- merge(ibex, bbva)
dat <- diff(log(dat))
#mean imputation
dat <- na.aggregate(dat)
library(urca)
jotest=ca.jo(dat, type="trace", K=2, ecdet="none", spec="longrun")
######################################################
## Johansen-Procedure Unit Root / Cointegration Test #
######################################################
#
#The value of the test statistic is: 619.1603 1473.644
Upvotes: 3