[R-SIG-Finance] How to compare two asynchroneous xts time series?

Jeff Ryan jeff.a.ryan at gmail.com
Thu Jun 11 16:05:50 CEST 2009


Anass,

xts and zoo automatically align series via "merge" when performing Ops
methods (+/-*...etc)

This is what you want in most cases.

See ?merge.xts, ?xts, ?merge.zoo and ?Ops.zoo

HTH
Jeff

On Thu, Jun 11, 2009 at 9:00 AM, Joshua Ulrich<josh.m.ulrich at gmail.com> wrote:
> Hi Anass,
>
> Can you provide an example of what you're trying to do and what error
> you are receiving?  I'm able to run the code below without error.
>
>> require(xts)
>>
>> Lines <-
> + "2008-06-02 09:00:00,5007.0
> + 2008-06-02 09:01:00,5010.0
> + 2008-06-02 09:02:00,5014.0
> + 2008-06-02 09:03:00,5012.5
> + 2008-06-02 09:04:00,5013.5
> + 2008-06-02 09:05:00,5009.5
> + 2008-06-02 09:06:00,5007.0
> + 2008-06-02 09:07:00,5006.5
> + 2008-06-02 09:08:00,5008.5
> + 2008-06-02 09:09:00,5004.5"
>>
>> one <- read.zoo(textConnection(Lines),sep=',',FUN=as.POSIXct)
>> one <- as.xts(one)
>>
>> Lines <-
> + "2008-06-02 09:01:00,7115.0
> + 2008-06-02 09:03:00,7117.0
> + 2008-06-02 09:05:00,7111.0
> + 2008-06-02 09:07:00,7107.0
> + 2008-06-02 09:09:00,7102.5"
>>
>> two <- read.zoo(textConnection(Lines),sep=',',FUN=as.POSIXct)
>> two <- as.xts(two)
>>
>> one/two
>                           e1
> 2008-06-02 09:01:00 0.7041462
> 2008-06-02 09:03:00 0.7042996
> 2008-06-02 09:05:00 0.7044719
> 2008-06-02 09:07:00 0.7044463
> 2008-06-02 09:09:00 0.7046111
>> two/one
>                          e1
> 2008-06-02 09:01:00 1.420160
> 2008-06-02 09:03:00 1.419850
> 2008-06-02 09:05:00 1.419503
> 2008-06-02 09:07:00 1.419555
> 2008-06-02 09:09:00 1.419223
>>
>
> Best,
> Joshua
> --
> http://www.fosstrading.com
>
>
>
> On Thu, Jun 11, 2009 at 6:11 AM, Anass Mouhsine<anass.mouhsine at gmail.com> wrote:
>> Hi all,
>>
>> Suppose I have two xts time series with asynchroneous time index.
>> I would like for example to calculate a ratio of those two series, but I
>> don't know how to get an intersection of the two indices in order to avoid
>> errors.
>>
>> an example of the data is the following
>>
>> series1
>>
>> 2008-06-02 09:00:00 5007.0
>> 2008-06-02 09:01:00 5010.0
>> 2008-06-02 09:02:00 5014.0
>> 2008-06-02 09:03:00 5012.5
>> 2008-06-02 09:04:00 5013.5
>> 2008-06-02 09:05:00 5009.5
>> 2008-06-02 09:06:00 5007.0
>> 2008-06-02 09:07:00 5006.5
>> 2008-06-02 09:08:00 5008.5
>> 2008-06-02 09:09:00 5004.5
>>
>> Series2
>>
>> 2008-06-02 09:01:00 7115.0
>> 2008-06-02 09:03:00 7117.0
>> 2008-06-02 09:05:00 7111.0
>> 2008-06-02 09:07:00 7107.0
>> 2008-06-02 09:09:00 7102.5
>>
>> Any idea?
>>
>> Thanks in advance
>>
>> _______________________________________________
>> 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