[R-SIG-Finance] Using adf.test to test time series stationarity of stock price
Adrian Trapletti
adrian at trapletti.org
Sat May 4 16:41:54 CEST 2013
Hi Matthieu
For me it looks like adf.test does not correctly handle xts and/or zoo
inputs due to the subsetting code:
> adf.test(stock2[,1])
Augmented Dickey-Fuller Test
data: stock2[, 1]
Dickey-Fuller = 2.7174, Lag order = 12, p-value = 0.99
alternative hypothesis: stationary
Warning message:
In adf.test(stock2[, 1]) : p-value greater than printed p-value
> adf.test(unclass(stock2[,1]))
Augmented Dickey-Fuller Test
data: unclass(stock2[, 1])
Dickey-Fuller = -2.4579, Lag order = 12, p-value = 0.3845
alternative hypothesis: stationary
At the time when adf.test was written neither xts nor zoo existed. A
quick fix is to revise the documentation of adf.test: "x: a numeric
vector."
Best regards
Adrian
> Date: Fri, 3 May 2013 10:25:31 +0200
> From: Matthieu Stigler<matthieu.stigler at gmail.com>
> To: "Brian G. Peterson"<brian at braverock.com>,yitaoz at stanford.edu,
> Kurt.Hornik at r-project.org
> Cc:"r-sig-finance at r-project.org" <r-sig-finance at r-project.org>
> Subject: Re: [R-SIG-Finance] Using adf.test to test time series
> stationarity of stock price
> Message-ID:
> <CAEYvig+hrDqKGXaetr=H=vy1FYsXiuB60hSkZoDt6L3L31od8Q at mail.gmail.com>
> Content-Type: text/plain
>
> Hi
>
> With our stated background in stats, we should have realised that the
> result you obtain is indeed surprising, since your t-stat is large, but
> positive! A positive t-stat implies actually that your rho is bigger than
> 1... So in this case, you will not reject the alternative of stationarity,
> but that of explosivity, try:
>
> adf.test(stock2[,1], alternative="explosive")
>
> That said, we should have also realised that results in adf.test seem to be
> incorrect, since they do not correspond to the ones in:
> library(urca)
> ur.df(stock2[,1], lags=12, type="trend")
> # or the corresponding "ADF" regression from tsDyn:
> library(tsDyn)
> ar_ts <- linear(stock2[,1], m=12, include="both", type="ADF")
> summary(ar_ts)$coef["phi.1",]
>
> Both urca and tsDyn agree closely on the t-stat, at -2.4578550 for urca,
> and -2.466884912 for tsDyn (differences come from the way of counting
> degrees of freedom, urca discards the initial values, while tsDyn does not,
> as in ar()). Looking closer at the code of adf.test(), it looks like the
> regression is \Delta y_t = const + trend + y_t while I would have expected
> a y_{t-1}. I guess code should be corrected as:
> xt1 <- x[(k-1):(n-1)]
> instead of
> xt1 <- x[k:n]
>
> once this done, adf.test does correspond to the others. And now Brian's
> point that prices are usually non-stationary holds.
>
> I am ccing the maintainer of tseries on this.
>
> Best
>
> Matthieu
>
>
>
>
> 2013/4/22 Brian G. Peterson<brian at braverock.com>
>
>> On 04/21/2013 06:28 PM, Yitao Zhang wrote:
>>
>>> Hey guys,
>>>
>>> I'm trying to do a augmented Dickey-Fuller test to test the stationarity
>>> of a stock price.
>>>
>> With your stated economics background, one would assume that you'd realize
>> that price is almost never stationary.
>>
>> Perhaps try on returns?
>>
>> --
>> Brian G. Peterson
>> http://braverock.com/brian/
>> Ph: 773-459-4973
>> IM: bgpbraverock
>>
>>
>> ______________________________**_________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>>
--
Dr. Adrian Trapletti
Steinstrasse 9b
CH-8610 Uster
Switzerland
Phone : +41 (0) 44 9945630
Mobile : +41 (0) 79 1037131
Email : adrian at trapletti.org
WWW : www.trapletti.org
More information about the R-SIG-Finance
mailing list