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.
Asked
Active
Viewed 6,015 times
7

Alex
- 19,533
- 37
- 126
- 195
-
"EST" is Eastern Standard Time and "EDT" is Eastern Daylight Time. – Joshua Ulrich Aug 11 '12 at 20:43
-
so which does that mean EDT includes the daylight savings time changes and EST does not? i just don't know the diff. – Alex Aug 11 '12 at 20:52
-
They're the same timezone. "EDT" is when DST is in effect. – Joshua Ulrich Aug 12 '12 at 00:33
-
It can be a bit ambiguous to call EST & EDT timezones; in practice they are subsets of a time zone, depending on the date. The OP wants the time zone to automatically change between these two. – ddunn801 Dec 19 '14 at 17:33
1 Answers
7
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).

GSee
- 48,880
- 13
- 125
- 145
-
1can i ask, how do you know the possible values that can be passed to `indexTZ` ? – Alex Aug 11 '12 at 21:20
-
3Try these two pages for background: http://en.wikipedia.org/wiki/Time_zone and http://en.wikipedia.org/wiki/IANA_time_zone_database – Dirk Eddelbuettel Aug 11 '12 at 21:32
-
1
-
Tip: to suppress the warning message you can do: `options('xts_check_TZ'=FALSE)`. (It becomes essential when you have warnings treated like errors!) – Darren Cook Aug 24 '12 at 00:09
-
@DarrenCook, thanks. I did not know that. My personal preference is to keep all data in the same time zone as `Sys.getenv("TZ")`, so I'd actually want to see those warnings/errors. – GSee Aug 24 '12 at 00:25
-
2@GSee is correct; I would advise against what Darren suggested. Rather make sure your R session has a TZ than to suppress tests. – Dirk Eddelbuettel Aug 24 '12 at 02:06