Reputation: 21
I'm using the following code in R to get the P-value via ADF-Test between two Time Series : TS1 and TS2:
m <- lm(TS1 ~ TS2 + 0)
beta <- coef(m)[1]
sprd <- TS1 - beta*TS2
ht <- adf.test(sprd, alternative='stationary', k=0)
pval <- as.numeric(ht$p.value)
If I want to get P-value for ADF for one or two more Time Series (i.e: TS1,TS2 and TS3 or TS1,TS2,TS3 and TS4), what would be the proper syntax considering the above code?
Thanks!
Upvotes: 0
Views: 775
Reputation: 21
I think I have found the answer:
m <- lm(pair1 ~ pair2 + pair3)
beta1 <- coef(m)[1]
beta2 <- coef(m)[2]
sprd <- pair1 - beta1*pair2 - beta2*pair3
ht <- adf.test(sprd, alternative='stationary', k=0)
Upvotes: 0
Reputation: 5152
Put your actual code into a function. You could use combn() to determine the pairs of series. After that loop for all the pairs, using paste to make the regression model, that would be passed to your function as a parameter, you will need to store the p-value into a vector or data.frame, for all the pairs . Good luck!!
t(combn(c("TS1","TS2","TS3","TS4"),2))
Upvotes: 1