Hi Adrian! Well spotted! Indeed, the issue comes from the fact that diff.xts keeps the first NA (as has na.pad=TRUE), while diff.zoo does not (na.pad=FALSE), as well as na.ts ...
A simple solution seems to be to add then: diff(y, na.pad=FALSE) or simply: y<- y[!is.na(y)] which seems to lead to correct results in both cases, but I haven't tested thoroughly... Best 2013/5/4 Adrian Trapletti <[email protected]> > 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@**gmail.com<[email protected]> >> > >> To: "Brian G. Peterson"<[email protected]>**,[email protected], >> [email protected] >> Cc:"r-sig-finance@r-project.**org <[email protected]>" < >> [email protected]> >> Subject: Re: [R-SIG-Finance] Using adf.test to test time series >> stationarity of stock price >> Message-ID: >> <CAEYvig+hrDqKGXaetr=H=vy1FYsX**iuB60hSkZoDt6L3L31od8Q@mail.** >> gmail.com <[email protected]>> >> 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<[email protected]> >> >> 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 >>> >>> >>> ______________________________****_________________ >>> [email protected] mailing list >>> https://stat.ethz.ch/mailman/****listinfo/r-sig-finance<https://stat.ethz.ch/mailman/**listinfo/r-sig-finance> >>> <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 : [email protected] > WWW : www.trapletti.org > > ______________________________**_________________ > [email protected] 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. > [[alternative HTML version deleted]] _______________________________________________ [email protected] mailing list 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.
