[R-SIG-Finance] Problems extracting xts data in my own time zone
Mark V
mvyver at gmail.com
Tue Nov 11 23:08:06 CET 2008
Hi,
In case anyone is reconsidering time zone behavior....
On Wed, Nov 12, 2008 at 8:49 AM, Albert Nigrin <anigrin at gmail.com> wrote:
> Unfortunately, I do need time zones. I work with foreign exchange and
> sometimes
> the data is timestamped as Eastern, and sometimes it is timestamped as GMT.
>
> After thinking about it a bit, my thoughts are that there are two choices
> that make the most sense to me.
> The first, is that the character string could be interpreted in your default
> zone, and
> the second is that the character string could be interpreted in the zone of
> the data.
>
> I think either of those choices are superior to interpreting the string in
> GMT.
In dealing with data from different timezones I eventually came to
convert all data to GMT.
I now also use GMT in all my code (mkt open, close).
This may be considered a corner case by some, but I'd argue that
increasing globalization means such uses cases could become common.
Furthermore, many (most?) users will be in TZ (i.e. have a system TZ)
different to the data TZ (whether it is converted to GMT or not).
Consequently, even if altering the default from GMT, please consider
keeping the data's time zone as the default behavior.
Thanks
Mark
> I understand that xts converts the default time zone to GMT before
> processing any code.
> However, I think that that conversion should happen after the indexes have
> been determined.
>
> That way you wouldn't get different results for z1 and z2 when subset a time
> series x like in the following example:
>
> Sys.setenv(TZ = "")
> x1 = as.POSIXct("2008-11-11 12:00")
> x = xts(1:5, x1 + -2:2)
>
> y = hms(index(x))$hours == 12
> z1 = x[hms(index(x))$hours == 12]
> z2 = x[y]
>
>> print(z1)
>
>> print(z2)
>
> 2008-11-11 12:00:00 3
> 2008-11-11 12:00:01 4
> 2008-11-11 12:00:02 5
>
>
> Albert
>
> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com]
> Sent: Friday, November 07, 2008 11:52 AM
> To: Albert Nigrin
> Cc: r-sig-finance at stat.math.ethz.ch
> Subject: Re: [R-SIG-Finance] Problems extracting xts data in my own time
> zone
>
> Do you really need time zones in the first place? If not you could
> use chron and avoid the entire problem right from the start. See
> R News 4/1.
>
> On Thu, Nov 6, 2008 at 11:07 PM, Albert Nigrin <anigrin at gmail.com> wrote:
>> I'm having problems extracting data using the powerful subsetting features
>> of xts. I am using R 2.8 with the latest version of zoo and xts on Windows
>> XP 64. I live near Washington DC so my local timezone is EDT. My problem
>> is that when I enter a character string to get a subset from an xts time
>> series, the time/date is interpreted to be in GMT rather than Eastern
>> Standard time.
>>
>> This is easily illustrated with an example
>>
>> Sys.getenv("TZ")
>> TZ
>> ""
>>> x = xts(1:3, Sys.time() - 1:3)
>>> x
>> 2008-11-06 22:39:39 2008-11-06 22:39:40 2008-11-06 22:39:41
>> 3 2 1
>>
>>> index(x)
>> [1] "2008-11-06 22:39:39 EST" "2008-11-06 22:39:40 EST" "2008-11-06
> 22:39:41
>> EST"
>>
>>> x["2008-11-06 22:39"]
>>
>>> x["2008-11-07 03:39"]
>>
>> 2008-11-06 22:39:39 3
>> 2008-11-06 22:39:40 2
>> 2008-11-06 22:39:41 1
>>
>> Thus, when I try to extract data using my local time zone, nothing is
>> returned. However when I Use GMT, the proper data is returned. How can I
>> extract data using my local time zone, instead of having to mentally
> convert
>> to GMT?
>>
>> Thanks
>> Albert
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
More information about the R-SIG-Finance
mailing list