Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some closing price data for two Australian banks which track each other very closely.



Code from this web page produces the following output

Assumed hedge ratio is 2.26

ADF p-value is 0.47

When I plot the prices, I obtain a chart that looks cointegrated


What I don't understand is why my p-value is so high. My slightly adapted R code is below.


gld <- read.csv("C:\\...\\CBA.csv", stringsAsFactors=F)
gdx <- read.csv("C:\\...\\WBC.csv", stringsAsFactors=F)

gld <- zoo(gld[,5], as.Date(gld[,1]))
gdx <- zoo(gdx[,5], as.Date(gdx[,1]))

t.zoo <- merge(gld, gdx, all=FALSE)
t <- as.data.frame(t.zoo)

cat("Date range is", format(start(t.zoo)), "to", format(end(t.zoo)), "\n")

m <- lm(gld ~ gdx + 0, data=t)
beta <- coef(m)[1]

cat("Assumed hedge ratio is", beta, "\n")

sprd <- t$gld - beta*t$gdx
ht <- adf.test(sprd, alternative="stationary", k=0)

cat("ADF p-value is", ht$p.value, "\n")

if (ht$p.value < 0.05) {
    cat("The spread is likely mean-reverting\n")
} else {
    cat("The spread is not mean-reverting.\n")
share|improve this question
An added point, I noticed that you didn't check if each of the time series are I(1). You might want to do that otherwise the co-integration behaviour could be spurrious. – icequations Oct 27 '11 at 2:32
up vote 7 down vote accepted

Here is my code:


# Load data
gld <- read.csv("~/Downloads/CBA.csv", stringsAsFactors = FALSE)
gdx <- read.csv("~/Downloads/WBC.csv", stringsAsFactors = FALSE)

# Convert to xts
gld <- xts(gld[, 4], as.POSIXct(gld[, 1], tz = "GMT", format = "%Y-%m-%d", tzone =    "GMT"))
gdx <- xts(gdx[, 4], as.POSIXct(gdx[, 1], tz = "GMT", format = "%Y-%m-%d", tzone = "GMT"))

# Plot original data
par(mfrow = c(2,1))
par(mfrow = c(1,1))

# Linear regression with fixed alpha
regress <- lm(as.numeric(gld) ~ as.numeric(gdx) + 0)
cat("Beta is", coef(regress)[1])

# ADF test. We use drift type because we will an intercept
# in our data. 
adf <- ur.df(residuals(regress), type = "drift")
cat("ADF test statistic is", adf@teststat[1], "critical value is", adf@cval[1], "\n")
cat("Residuals are", ifelse(adf@teststat[1] < adf@cval[1], "stationary", "not stationary"))

# Plot residuals
plot(residuals(regress), type = "l")

It seems like your series are not cointegrated in this sample, look at residuals. What you can try to do is: 1. Look at longer sample 2. Try to construct a cointegrating vector using more than 2 price series. Hint: add Brent. You can try Johansen procedure for that stuff.

share|improve this answer
Hi m1ndst0rm, welcome to quant.SE and thanks for contributing your answer. Please register to ensure you gain the credit for your contribution. – Tal Fishman Oct 18 '11 at 11:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.