[R-SIG-Finance] getting xts endpoints() and apply.daiy() to work with local TZ?
Jeff Ryan
jeff.a.ryan at gmail.com
Wed Jul 8 14:33:16 CEST 2009
Hi Christian,
endpoints was patched about two weeks ago on R-forge for this issue.
You can install from there, or there will be a new CRAN version coming
in the next few weeks (after Rennes).
The fixed version with commit log:
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/R/endpoints.R?rev=417&root=xts&view=markup
To install from R-forge:
install.packages("xts", repos="http://r-forge.r-project.org")
Thanks again for the report and suggestion!
Jeff
On Wed, Jul 8, 2009 at 1:26 AM, Christian Gunning<icos.atropa at gmail.com> wrote:
> I'm looking for the best way to get apply.daily() to use breaks
> according to local TZ. Sorry, i know timezone handling is perennial
> issue. I reviewed R News 4/1, R-sig-fin, ?indexTZ, and
> ?DateTimeClasses and xts R source.
>
> Currently, apply.daily() in a non-GMT timezone computes breaks
> according to GMT (A note about this in apply.daily() or endpoints()
> might preempt user confusion?).
>
> Below, I compute the difference between local time and GMT in seconds,
> and add it into the call to which() in endpoints() to get my desired
> answer. Is endpoints() support of TZ on the map, and is there a better
> way than this to add it (particularly, calculating tmpdiff below)? Is
> this a bad idea altogether?
>
> thanks,
> christian gunning
> university of new mexico
>
> ###
> oldtz = Sys.getenv('TZ')
> Sys.setenv(TZ="GMT+7")
>
> tmpind = as.POSIXct(seq(from=0, to=5*24*60*60-60, by=60*60),
> origin='2000-01-01')
>
> tmpx = xts(1:(5*24), tmpind)
> indexTZ(tmpx) ### correctly reports TZ as "GMT+7"
> tmpind[1] ### format.POSIXlt? reports TZ as "GMT",
> tmpx[endpoints(tmpx, on='days')] ### daybreaks as per GMT
>
>
> ### from endpoints(), added tmpdiff, daybreaks as per local TZ
> tmpdiff = as.integer(as.POSIXct(0, origin='2000-01-01', tz='GMT')) -
> as.integer(as.POSIXct(0, origin='2000-01-01'))
>
> tmpdays = as.integer(c(0,
> which(diff((.index(tmpx)+tmpdiff)%/%86400L%/%k + 1) != 0),
> NROW(tmpx)))
>
> tmpx[tmpdays]
>
> Sys.setenv(TZ=oldtz)
> ###
>
> _______________________________________________
> 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