[R-SIG-Finance] [R-sig-finance] Aggregating tick by tick timeSeries [NC]

Brian G. Peterson brian at braverock.com
Wed Mar 5 18:15:06 CET 2008


aggregate() from zoo should be able to do what you need once your 
timeSeries is converted to xts/zoo.

anass.mouhsine at sgcib.com wrote:
> Thank you Jeff,
> 
> 
> my aim was to calculate standard statistics + volume weighted prices and
> spreads.
> 
> 
> I will try out the xts package, but I am wondering if it can aggregate
> Multivariate timeSeries (e.g, (spread, volume) or (price,volume)).
> 
> 
> thanks again
> 
> 
> |------------------------------                                            
> |            jeff.a.ryan at gmail                                             
> |            .com                                                          
> |                                                                          
> |            03/05/2008 16:21                                              
> |                                                                          
>                                                                            
>                                                                            
>                                                                         To 
>                                                Anass                       
>                                                MOUHSINE/fr/socgen at socgen   
>                                                                         cc 
>                                                r-sig-finance at stat.math.eth 
>                                                z.ch                        
>                                                                    Subject 
>                                                Re: [R-SIG-Finance]         
>                                                [R-sig-finance] Aggregating 
>                                                tick by tick timeSeries     
>                                                [C1]                        
>                                                                            
>                                                                            
>                                                                            
>                                                                            
>                                                                            
>                                                                            
> 
> 
> 
> 
> Anass,
> 
> If you want the mean/sd/etc for each hour ?aggregate from zoo will do
> the job very well. To get there from timeSeries you can use the new
> 'xts' package:
> 
> myTS [a timeSeries object]
> 
> as.xts(myTS) [ now an 'xts' object - which inherits from zoo]
> 
> --or--
> 
> as.zoo(myTS)
> 
> you can even put it back to a timeSeries with little information loss
> if you use xts via 'reclass' (changing the series outside of xts
> functions currently isn't perfect - but it is good)
> 
> If you want to just aggregate the data into OHLC per time period -
> to.period in xts is fast and flexible:
> 
> to.period(myTS,'minutes',15)
> to.period(myTS,'hours')
> to.monthly(myTS)
> 
> All these work by converting and reconverting to an 'xts' class
> internally - so most any (including timeSeries) class will just work
> with the function.  In addition it is all compiled code - so it works
> well.
> 
> One caveat - you'll need to get the most recent xts from
> http://r-forge.r-project.org/projects/xts - as there was a minor bug
> in the transition of 'to.period' code from quantmod to xts.
> 
> Jeff
> 
> On Wed, Mar 5, 2008 at 8:21 AM,  <anass.mouhsine at sgcib.com> wrote:
>>  Hi guys,
>>
>>
>>  I have a timeSeries object like this one
>>                         V10
>>  2005-04-08 17:31:41 0.01
>>  2005-04-08 17:31:57 0.02
>>  2005-04-08 17:32:00 0.02
>>  2005-04-08 17:32:57 0.02
>>  2005-04-08 17:38:34 0.02
>>  2005-04-08 17:38:49 0.01
>>
>>  and I would like to aggregate the timeSeries in hours or minutes in
> order
>>  to apply whatever function on the aggregated data (e.g mean, standard
> dev,
>>  etc...)
>>  I have seen some aggreagation functions like aggregate in the fSeries
>>  package but it aggregates only monthly or quaterly.
>>  I am sure some of you guys were faced to this kind of issue.
>>
>>  Could anyone give me some hints on how to solve my problem?
>>
>>  thanks in advance
>>
>>  Anass



More information about the R-SIG-Finance mailing list