[R-SIG-Finance] xts NA date for

Jeffrey Ryan jeffrey.ryan at lemnica.com
Fri Sep 23 16:38:51 CEST 2011


Hi Dan,

I think it is a platform issue. Windows has been problematic around
the edges of TZ behavior - forever.  Sys.timezone() and
Sys.getenv("TZ") even behave differently from time to time.  I would
recommend the latter over the former.  And non-windows above all ;-)

That said, I think you are always best being explicit about the TZ you
want when constructing objects in R.  xts isn't the issue here, and I
am not too sure I could design it to compensate for the incoming data
without having some bit of magic.

I'd also use POSIXct more than POSIXlt (the result of strptime here).
It will be faster and likely a bit less confusing as 'ct' objects are
time_t objects in C, whereas 'lt' objects are a wildly (and
brilliantly) modified struct tm object.

Thanks for the report/email though, and if I can think of a better
solution I'll pass along and/or update xts.

Best,
Jeff

On Fri, Sep 23, 2011 at 9:27 AM, Dan Potter <arsanalytica at gmail.com> wrote:
> Thank you Jeff and Josh, that was very helpful.  Other systems I have
> worked with haven't included embedded daylight savings magic. (And I'm
> not sure I like it unless I can compute time differences and durations
> correctly when using it.)
>
> My data (and many datasets I have work with) are UTC stamped in order
> to avoid daylight savings issues and allow a simple way for
> contemporaneous comparison between them.  I assumed the default xts,
> strptime, etc. time zone would be UTC and not my current timezone.
>
> The following is a solution for my problem
>
>> xts(1,strptime("4/5/87 2:00",format="%m/%d/%y %H:%M", tz="UTC"))
>                    [,1]
> 1987-04-05 02:00:00    1
> Warning message:
> timezone of object (UTC) is different than current timezone ().
>
> I wonder why my own calls to strptime with tz unspecified do not
> include a timezone in their results, whereas Jeff's does, e.g.,
>> Sys.timezone()
> [1] "EDT"
>> strptime("4/5/87 2:00",format="%m/%d/%y %H:%M")
> [1] "1987-04-05 02:00:00"
>
> Versus
>
>  On Fri, Sep 23, 2011 at 9:02 AM, Jeffrey Ryan
> <jeffrey.ryan at lemnica.com> wrote:
>  >
>  > > strptime("04/05/87 2:00",format="%m/%d/%y %H:%M")
>  > [1] "1987-04-05 02:00:00 CDT"
>
> Given these issues, it would be nice if the strptime, xts etc. time
> and date print methods would always included the time zone.
>
> Thanks Again,
> Dan
>
> On Fri, Sep 23, 2011 at 9:02 AM, Jeffrey Ryan <jeffrey.ryan at lemnica.com> wrote:
>>
>> > strptime("04/05/87 2:00",format="%m/%d/%y %H:%M")
>> [1] "1987-04-05 02:00:00 CDT"
>>
>> This time doesn't exists. It would be 1:00 or 3:00.
>>
>> http://www.timeanddate.com/worldclock/clockchange.html?n=64&year=1987
>>
>> It is too early for me to figure out the nuances of this logic, i.e.
>> what should it be doing when you pass in a time that doesn't exist in
>> your TZ.  For now though, that is clearly the heart of the issue.
>>
>> Jeff
>>
>> On Fri, Sep 23, 2011 at 7:44 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
>> > Dan,
>> >
>> > This is probably an issue with the start/end of daylight saving time
>> > in your timezone.
>> >
>> > Best,
>> > --
>> > Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
>> >
>> >
>> >
>> > On Fri, Sep 23, 2011 at 7:38 AM, G See <gsee000 at gmail.com> wrote:
>> >> hmmm.
>> >>
>> >> I'm using xts_0.8-3 revision 602 on R-Forge, and it *almost* works for me,
>> >> but the time is off by an hour
>> >>
>> >>> xts(1, order.by=strptime("04/05/87 2:00",format="%m/%d/%y %H:%M"))
>> >>                    [,1]
>> >> 1987-04-05 01:00:00    1
>> >>>
>> >>
>> >> -Garrett
>> >>
>> >> On Fri, Sep 23, 2011 at 7:33 AM, Dan Potter <arsanalytica at gmail.com> wrote:
>> >>
>> >>> Thank you Wolfgang.  On my machine sessionInfo shows I am using xts
>> >>> version 0.8-2 -
>> >>> I think it is the latest one, see
>> >>> http://cran.r-project.org/web/packages/xts/index.html
>> >>> Maybe someone can confirm correct operation in 0.8-2.  Could this be a
>> >>> Revo/base R version issue?
>> >>>
>> >>> > sessionInfo()
>> >>> R version 2.12.2 (2011-02-25)
>> >>> Platform: i386-pc-mingw32/i386 (32-bit)
>> >>>
>> >>> locale:
>> >>> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
>> >>> States.1252    LC_MONETARY=English_United States.1252
>> >>> [4] LC_NUMERIC=C                           LC_TIME=English_United
>> >>> States.1252
>> >>>
>> >>> attached base packages:
>> >>> [1] stats     graphics  grDevices utils     datasets  methods   base
>> >>>
>> >>> other attached packages:
>> >>> [1] dplR_1.4.7       xts_0.8-2        zoo_1.7-2        Revobase_4.3.0
>> >>>  RevoMods_4.3.0   RevoScaleR_1.2-0 lattice_0.19-23
>> >>>
>> >>>
>> >>> On Fri, Sep 23, 2011 at 8:15 AM, Wolfgang Wu <wobwu22 at yahoo.de> wrote:
>> >>> >
>> >>> > Hmmm works fine for me.
>> >>> >
>> >>> > xts(1, order.by = strptime("04/05/87 2:00",format="%m/%d/%y %H:%M"))
>> >>> >
>> >>> > [,1]
>> >>> > 1987-04-05 02:00:00    1
>> >>> >
>> >>> > Maybe an old version of xts? I am using xts version 0.8-0. (you can check
>> >>> that with sessionInfo().)
>> >>> >
>> >>> > Regards,
>> >>> >
>> >>> > Wolfgang Wu
>> >>> >
>> >>> >
>> >>> >
>> >>> >
>> >>> > ----- Ursprüngliche Message -----
>> >>> > Von: Dan Potter <arsanalytica at gmail.com>
>> >>> > An: r-sig-finance at r-project.org
>> >>> > Cc:
>> >>> > Gesendet: 12:51 Freitag, 23.September 2011
>> >>> > Betreff: [R-SIG-Finance] xts NA date for
>> >>> >
>> >>> > Hello All,
>> >>> > I am new to R and having an issue with xts when I try and used it with
>> >>> > certain dates and times in 1987.
>> >>> >
>> >>> > Example
>> >>> >
>> >>> > > # This date and time works
>> >>> > > xts(1, order.by = strptime("04/05/87 12:00",format="%m/%d/%y %H:%M"))
>> >>> > [,1]
>> >>> > 1987-04-05 12:00:00 1
>> >>> >
>> >>> > # This date and time do not work
>> >>> > > xts(1, order.by = strptime("04/05/87 2:00",format="%m/%d/%y %H:%M"))
>> >>> > [,1]
>> >>> > <NA> 1
>> >>> >
>> >>> > I don't think the issue is with strptime since it seems to work fine
>> >>> > on the offending date and time, i.e.
>> >>> > > strptime("04/05/87 02:00",format="%m/%d/%y %H:%M")
>> >>> > [1] "1987-04-05 02:00:00"
>> >>> >
>> >>> > Any suggestion or work arounds would be appreciated.
>> >>> >
>> >>> > Thanks,
>> >>> > Dan
>> >>> >
>> >>> > _______________________________________________
>> >>> > R-SIG-Finance at r-project.org mailing list
>> >>> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> >>> > -- Subscriber-posting only. If you want to post, subscribe first.
>> >>> > -- Also note that this is not the r-help list where general R questions
>> >>> should go.
>> >>> >
>> >>>
>> >>> _______________________________________________
>> >>> R-SIG-Finance at r-project.org mailing list
>> >>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> >>> -- Subscriber-posting only. If you want to post, subscribe first.
>> >>> -- Also note that this is not the r-help list where general R questions
>> >>> should go.
>> >>>
>> >>
>> >>        [[alternative HTML version deleted]]
>> >>
>> >>
>> >> _______________________________________________
>> >> R-SIG-Finance at r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> >> -- Subscriber-posting only. If you want to post, subscribe first.
>> >> -- Also note that this is not the r-help list where general R questions should go.
>> >>
>> >
>> > _______________________________________________
>> > R-SIG-Finance at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> > -- Subscriber-posting only. If you want to post, subscribe first.
>> > -- Also note that this is not the r-help list where general R questions should go.
>> >
>>
>>
>>
>> --
>> Jeffrey Ryan
>> jeffrey.ryan at lemnica.com
>>
>> www.lemnica.com
>> www.esotericR.com
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan at lemnica.com

www.lemnica.com
www.esotericR.com



More information about the R-SIG-Finance mailing list