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

spencerg spencer.graves at prodsyse.com
Thu Jun 11 17:57:44 CEST 2009


      One could also smooth the two series first, then compare the 
smooths.  This could be used to interpolate missing values to provide a 
larger sample size for tradition tools. 


      The "fda" package has a number of tools for doing this kind of 
thing.  Learning about this package will soon get easier with the 
scheduled appearance in July of Ramsay, Hooker and Graves (2009) 
Functional Data Analysis with R and Matlab (Springer).  The "fda" 
package contains script files to reproduce all but one of the 78 figures 
in the book.  The script files are available now, and can be found as 
follows: 


 > system.file('scripts', package='fda')
[1] "C:/Users/sgraves/R/R-2.9.0/library/fda/scripts"
 > dir(system.file('scripts', package='fda'))
<snip> 
[17] "fdarm-ch01.R"            "fdarm-ch02.R"          
[19] "fdarm-ch03.R"            "fdarm-ch04.R"          
[21] "fdarm-ch05.R"            "fdarm-ch06.R"          
[23] "fdarm-ch07.R"            "fdarm-ch08.R"          
[25] "fdarm-ch09.R"            "fdarm-ch10.R"          
[27] "fdarm-ch11.R"            "pda.fd.test.R"  


      Hope this helps. 
      Spencer

Anass Mouhsine wrote:
> Thanks Joshua
>
> A
>
> Joshua Ulrich wrote:
>> On Thu, Jun 11, 2009 at 9:16 AM, anass<anass.mouhsine at gmail.com> wrote:
>>  
>>> Thx guys,
>>>
>>> well the error I got is elswhere and I thought it was due to the 
>>> asynchrone
>>> timeseries.
>>>
>>> let's assume that I got the intraday ratio, what I do is the following
>>>
>>> d<-index(to.daily(ratio))
>>> for (i in 1:length(d)){
>>>  tstart<-paste(d[i], "09:00:00")
>>>  tend<-paste(d[i],"17:00:00")
>>> ts_ratio<-ratio[tstart:tend]
>>>     
>>
>> This line is incorrect.  I don't believe the ":" sequence operator in
>> package:base is defined for character strings (see ?":").  This is
>> what is causing an error.  What you probably intended is this:
>> ts_ratio <- ratio[paste(tstart,tend,sep="::")]
>>
>>  
>>> #
>>> # other operations
>>> #
>>> }
>>>
>>> and I have this error
>>> Error in tstart:tend : argument NA / NaN
>>>
>>> So I assume if it is not due to asynchrone series, it is due to the
>>> subsetting.
>>> Does xts objects accept this kind of subset?
>>>
>>>
>>> On Thu, Jun 11, 2009 at 4:05 PM, Jeff Ryan <jeff.a.ryan at gmail.com> 
>>> wrote:
>>>    
>>>> 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
>>>>       
>>>
>>> -- 
>>>
>>> En toda ocasion, disfruta de la vida
>>>
>>>     
>>
>> Best,
>> Joshua
>> -- 
>> http://www.fosstrading.com
>>
>>
>
> _______________________________________________
> 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.
>



More information about the R-SIG-Finance mailing list