[R-SIG-Finance] Index time change when coercing zoo object to xts

Jeff Ryan jeff.a.ryan at gmail.com
Thu Jul 23 16:10:52 CEST 2009


As the previous posters mentioned, without an example to work from we
can't really tell what the problem is.

Please post the versions of all software you are using, along with
reproducible code for us to try.

As Gabor pointed out, 'xts' converts user time classes internally to a
POSIXct representation.  This is done transparently and for internal
efficiency purposes, as well as to offer identical behavior regardless
of user preference.  Somewhere in the conversion it is possible that
we are losing precision from 'chron' to 'POSIXct'.

That said, I can't replicate your issue, so it may be fixed in recent releases.

HTH,
Jeff

On Thu, Jul 23, 2009 at 7:10 AM, Gabor
Grothendieck<ggrothendieck at gmail.com> wrote:
> As another responder mentioned we really need it in a reproducible
> form; however, we can guess that the source of the problem is that
> zoo represents all times in their original class, presumably chron
> in this case, without any modification whereas xts represents all
> times in POSIXct no matter what their original form was so as.xts
> must map them all to POSIXct and in this conversion can introduce
> small differences.
>
> I can't reproduce this (see code below) but if you provide x1 in a
> reproducible form then the above hypothesis can be double checked.
>
>> Lines <- "07/23/09 15:13:00,19815,238
> + 07/23/09 15:14:00,19805,291
> + 07/23/09 15:15:00,19816,298
> + 07/23/09 15:16:00,19820,357
> + 07/23/09 15:17:00,19813,218
> + 07/23/09 15:18:00,19789,203"
>>
>> library(xts)
>> library(chron)
>> z <- read.zoo(textConnection(Lines), sep = ",", FUN = as.chron,
> + format = "%m/%d/%y %H:%M:%S")
>> z
>                       V2  V3
> (07/23/09 15:13:00) 19815 238
> (07/23/09 15:14:00) 19805 291
> (07/23/09 15:15:00) 19816 298
> (07/23/09 15:16:00) 19820 357
> (07/23/09 15:17:00) 19813 218
> (07/23/09 15:18:00) 19789 203
>> as.xts(z)
>                       V2  V3
> (07/23/09 15:13:00) 19815 238
> (07/23/09 15:14:00) 19805 291
> (07/23/09 15:15:00) 19816 298
> (07/23/09 15:16:00) 19820 357
> (07/23/09 15:17:00) 19813 218
> (07/23/09 15:18:00) 19789 203
>
>
> On Thu, Jul 23, 2009 at 3:37 AM, Tseng Ko<ko.tseng at gmail.com> wrote:
>> Dear all,
>>
>>  I tried to trasnform a zoo object to xts.
>>
>>> x1
>>                        C   V
>> (07/23/09 15:13:00) 19815 238
>> (07/23/09 15:14:00) 19805 291
>> (07/23/09 15:15:00) 19816 298
>> (07/23/09 15:16:00) 19820 357
>> (07/23/09 15:17:00) 19813 218
>> (07/23/09 15:18:00) 19789 203
>>
>>> as.xts(x1)
>>                        C   V
>> (07/23/09 15:12:59) 19815 238
>> (07/23/09 15:13:59) 19805 291
>> (07/23/09 15:14:59) 19816 298
>> (07/23/09 15:15:59) 19820 357
>> (07/23/09 15:17:00) 19813 218
>> (07/23/09 15:18:00) 19789 203
>>
>> Some data elements have 1 sec difference. Is it a bug in xts?
>>
>> Thanks.
>>
>> --
>> Ko Tseng
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list