[R-SIG-Finance] xts and Sys.time() - very stange behaviour

Jeff Ryan jeff.a.ryan at gmail.com
Wed Aug 1 22:00:38 CEST 2012


On Wed, Aug 1, 2012 at 1:57 PM, Brian G. Peterson <brian at braverock.com> wrote:
> On 08/01/2012 01:39 PM, Joshua Ulrich wrote:
>>
>> This is an issue with precision and formatting when you convert to
>> character.
>
> <...>
>
>> I don't know of a solution, other than "don't do that".
>
>
> I found that keeping the POSIXct object, and modifying that directly,
> massively improves both speed and correctness of matching over using the
> character representation with sub-second data.  This of course makes sense,
> as you are matching a number to a number, rather than a number to a string
> converted to a number.

Note that this isn't likely the cause, unless you are concurrently
doing something like as.character(index(x))=="2001-01-01 08:30:01.999"
with an xts object.  That will convert the internal representation of
the _entire_ index from double to "time", whatever class that may be,
and then to character!.

If you use xts subsetting itself, the 'character' turns into a POSIXct
for the value you are trying to match against.  So you only incur
_one_ conversion (instantaneous).  This numeric value is then search
for via binary search (i.e. O(log n) cost - more or less).  For
anything like tick data, binary search is going to be much faster than
a linear scan.

Anyway, all the above still fails you if you catch a floating point
issue.  I've got some ideas (no code) on a better way to do this of
course...

Jeff
>
> Regards,
>
>    - Brian
>
>
> _______________________________________________
> 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



More information about the R-SIG-Finance mailing list