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

anass.mouhsine at sgcib.com anass.mouhsine at sgcib.com
Fri Mar 21 13:53:39 CET 2008

Hi Jeff,

I used the xts package as you advised.
I have a timeSeries object called test

                                     V10  V7
2005-04-08 10:55:16 0.3202287 448
2005-04-08 10:55:16 0.3945675 552
2005-04-08 10:55:16 0.0000000   0
2005-04-08 10:55:18 0.0000000   0
2005-04-08 10:55:30 0.0000000   0
2005-04-08 10:55:35 0.0000000   0

the first column stand for the spread*volume and the second one for the
traded volume.
I want to calculate the Volume Weighted Spread hourly.




[1] 0.0006517149 0.0011587963 0.0008660431 0.0007342648 0.0010022736
[6] 0.0009949343 0.0009114276 0.0009170628 0.0008334971

Here I have what I want but need to improve the result:
1) I do not know how to get back to a timeSeries object using reclass() and
have a timeDate object as an index.
2) Is it possible to do the same calculation from a timeSeries object of
two columns (spread,volume)  whithout calculating a column spread* volume
and doing two univariate sums.

Could you give some hints on the subject?


|            jeff.a.ryan at gmail                                             
|            .com                                                          
|            03/05/2008 16:21                                              
                                               MOUHSINE/fr/socgen at socgen   
                                               r-sig-finance at stat.math.eth 
                                               Re: [R-SIG-Finance]         
                                               [R-sig-finance] Aggregating 
                                               tick by tick timeSeries     


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]



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:


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

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.


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
>  to apply whatever function on the aggregated data (e.g mean, standard
>  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
>  This message and any attachments (the "message") are
>  _______________________________________________
>  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.

There's a way to do it better - find it.
Thomas A. Edison

This message and any attachments (the "message") are con...{{dropped:10}}

More information about the R-SIG-Finance mailing list