time zones in POSIXct and xts, converting from GMT in R

主宰稳场 提交于 2020-01-12 21:25:12

问题


I have a bunch of 1 minute returns in an xts object with the index being POSIXct and time zone being GMT. The returns are on NYSE so I would like to convert to the eastern time zone but I would like to take care of the daylight savings time properly. What is the best way of doing this? I am a bit confused between the EST timezone and the EDT timezone. I would like my times to convert properly to the NY time in winter and summer.


回答1:


Use indexTZ<- and the America/New_York timezone

> tail(SPY)
                    SPY.Bid.Price SPY.Ask.Price SPY.Trade.Price SPY.Mid.Price SPY.Volume
2012-08-09 19:54:00        140.47        140.48          140.48       140.475       2372
2012-08-09 19:55:00        140.46        140.47          140.46       140.465       5836
2012-08-09 19:56:00        140.47        140.48          140.48       140.475       2538
2012-08-09 19:57:00        140.47        140.48          140.47       140.475       2209
2012-08-09 19:58:00        140.48        140.49          140.49       140.485       4943
2012-08-09 19:59:00        140.58        140.59          140.58       140.585      16780
> indexTZ(SPY) <- "America/New_York"
> tail(SPY)
                    SPY.Bid.Price SPY.Ask.Price SPY.Trade.Price SPY.Mid.Price SPY.Volume
2012-08-09 15:54:00        140.47        140.48          140.48       140.475       2372
2012-08-09 15:55:00        140.46        140.47          140.46       140.465       5836
2012-08-09 15:56:00        140.47        140.48          140.48       140.475       2538
2012-08-09 15:57:00        140.47        140.48          140.47       140.475       2209
2012-08-09 15:58:00        140.48        140.49          140.49       140.485       4943
2012-08-09 15:59:00        140.58        140.59          140.58       140.585      16780
Warning message:
timezone of object (America/New_York) is different than current timezone (GMT). 


来源:https://stackoverflow.com/questions/11917185/time-zones-in-posixct-and-xts-converting-from-gmt-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!