Skip to content
Prev 2294 / 15274 Next

Aggregating tick by tick timeSeries [NC]

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?

regards,
Anass


|------------------------------                                            
|            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:
order
dev,
*************************************************************************
con...{{dropped:10}}
--
There's a way to do it better - find it.
Thomas A. Edison

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