getSymbols(quantmod)给出错误的日期 [英] getSymbols (quantmod) giving wrong dates

查看:186
本文介绍了getSymbols(quantmod)给出错误的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用quantmod软件包来获取股票数据.代码

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')

导致xts符合预期,但是仔细检查后,它显示2012-10-21(10月21日)的交易量是星期日,因此显然是错误的.还包括其他几个星期天.不幸的是,围绕周末的错误似乎使其余数据失去了一致性.

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.

是否有人在使用quantmod获取报价器之前遇到过类似的问题,如果是这样,他们是否知道解决方法?

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

谢谢

推荐答案

正如您在评论中提到的,这看起来像是时区问题,可能是由于xts函数中的POSIX日期转换(请参见

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).

Sys.getenv("TZ")为空字符串时,我可以在全新的R会话中重现该问题.将时区设置为任何有效时区(并非经过测试的所有时区),例如"America/Chicago"会产生预期的日期,即没有星期日:

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:

在一个新的会话中(2012年12月16日是星期日):

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"

然后更改时区

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"

没有星期天.

这篇关于getSymbols(quantmod)给出错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆