N. McA.
N. McA.

Reputation: 4946

getSymbols (quantmod) giving wrong dates

I'm using the quantmod package to fetch stock data. The code

Data = getSymbols('LON:ADN',src="google",auto.assign=FALSE, from = '2011-08-10')

Results in an xts as expected, however on closer examination it shows a volume of trades for 2012-10-21 (October 21st) which was a sunday, and is therefore clearly erroneous. Several other sundays are also included. Unfortunately the errors surrounding the weekends seem to have moved the rest of the data out of alignment.

Has anyone experienced similar problems fetching tickers with quantmod before, and if so, are they aware of a way around them?

Thanks

Upvotes: 4

Views: 2276

Answers (1)

BenBarnes
BenBarnes

Reputation: 19454

As you mentioned in the comments, this looks like a timezone issue, possibly due to POSIX date conversion in the xts function (see this answer).

I am able to reproduce the issue in a fresh R session when Sys.getenv("TZ") is an empty character string. Setting the timezone to any valid timezone (not all tested), for example, "America/Chicago" yields expected dates, i.e., no Sundays:

In a fresh session (December 16th 2012 was a Sunday):

Sys.getenv("TZ")
# [1] ""

library(quantmod)
Data <- getSymbols('LON:ADN',src="google",auto.assign=FALSE, from = '2011-08-10')
tail(index(Data))
# [1] "2012-12-13" "2012-12-16" "2012-12-17" "2012-12-18" "2012-12-19" "2012-12-20"

Then change the timezone

Sys.setenv(TZ="America/Chicago")

Data <- getSymbols('LON:ADN',src="google",auto.assign=FALSE, from = '2011-08-10')
tail(index(Data))
# [1] "2012-12-14" "2012-12-17" "2012-12-18" "2012-12-19" "2012-12-20" "2012-12-21"

No Sundays.

Upvotes: 3

Related Questions