[R-SIG-Finance] Problems extracting xts data in my own time zone

Jeff Ryan jeff.a.ryan at gmail.com
Fri Nov 7 17:27:18 CET 2008


Albert,

TZ management in general is a problem.  With R and the variety of OSs
supported it is even trickier.

Different OSs implement different mechanisms to handle time-zones.  So
one machine will do one thing, while another may do something
different.

Even different OS updates will have unpredictable effects.

Bottom line is that handling TZs internally is at best very difficult,
and at worst impossible (IMO, though I am far (far) from a TZ expert).

Diethelm and Yohan's timeDate class from Rmetrics is about as perfect
a solution as I think you can get.  But even that can be difficult to
work with.  Additionally they have implemented a solution around
FinCenters, forgoing the standard time-zone structure.  Do take a look
at what you can do with that, it is impressive.

Given the above, xts only handles times internally as GMT.  This not
the ideal solution, nor is it the final one, but for the moment I
think it is the best solution given the state of affairs.

So the reliable solution is to use GMT and adjust from there.

> Sys.setenv(TZ='GMT')
> x = xts(1:3, Sys.time() - 1:3)
> x
                    [,1]
2008-11-07 16:17:45    3
2008-11-07 16:17:46    2
2008-11-07 16:17:47    1
> x = xts(1:3, (Sys.time() - 1:3) - (5*3600)) # current offset from GMT for EDT
> x
                    [,1]
2008-11-07 11:18:13    3
2008-11-07 11:18:14    2
2008-11-07 11:18:15    1
> x['2008-11-07 11:18:13']
                    [,1]
2008-11-07 11:18:13    3

The released version of xts allows you to index by timeDate, but given
the conversion to POSIXct internally to manage subsetting (and in
xts-dev for efficiency reasons), the reliability of that approach may
not be 100%.

Any comments/thoughts/advice from the list on how to best venture down
this path for xts, or for general use would be appreciated.

Jeff

On Thu, Nov 6, 2008 at 10: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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list