I'm having an issue using PP.test or adf.test as stationarity tests. I am
looking for the right tests to use to see if a series is mean reverting for
a pairs-trading like strategy.
Basically if the series is trending the tests still say the series is
stationary, but this would not be something I can use in pairs trading.
Short of writing code to detrend and test for trending - what would be
recommended for a test that a series is mean-reverting tradeable.
Example code to illustrate:
aSeries <- sin(seq(1,numElems)/pi)*5
bSeries <- seq(1,numElems)
cSeries <- aSeries*10 + bSeries
dSeries <- cumsum(rnorm(numElems,sd=5))+200
staTest = function(inSeries) {
ht <- adf.test(inSeries, alternative="stationary")
cat("ADF p-value is", ht$p.value, "\n")
ht$p.value
}
ssa <- staTest(aSeries)
ssb <- staTest(bSeries)
ssc <- staTest(cSeries)
ssd <- staTest(dSeries)
cat('STA test A=', ssa, 'B = ', ssb, 'C = ', ssc, 'D =', ssd, '\n')
// Results obtained:
STA test A= 0.01 B = 0.99 C = 0.01 D = 0.2764712
Clearly A is the only series that should be stationary and the p test of
0.01 'confirms' this. However C is trending upwards and the P test is still
saying it's stationary.
I would appreciate any help.