[R-SIG-Finance] Interpolating/comparing two irregular time/price sequences?

Rory Winston rory.winston at gmail.com
Wed Nov 7 19:31:16 CET 2007


Hi all

I have two data frames, that both look like the following:

> head(series1)
     timestamp     mid   spread
1 1.194438e+12 2.10011 0.000260
2 1.194438e+12 2.10010 0.000290
...

These two time sequences are sampled on price ticks, so the interval
between ticks is stochastic and irregular. The time sequences are also
of different lengths, i.e. one may have 8 hours worth of data, the
other may have 4. My issue is that I want to compare these two series
for similarity - they should be producing almost exactly the same
data, although potentially at slightly different timestamps (hence the
sampling irregularity). I can subset the data so that they span
roughly the same time intervals, but the number of ticks in each
series will be different. Basically what I am trying to achieve is
some sort of constant interpolation based on a time index - so that if
series A starts at 08:01, contains 10,000 ticks, and ends at 16:05,
and series B starts at 08:00, contains 7,000 ticks, and ends at 16:06,
I would like to be able to index from series A into series B at say,
each timestamp in A. Using a simple example, for the following series
A and B:

A:
time   tick
16:01 2.05
16:02 2.06


B:
time tick
16:00 2.04
16:02 2.06

I would like to be able to index from A into B at each tick from A, so
I would get an output series that was the value of B at each time A
ticked:

C
time tick
16:01 2.04 <--- constant interpolation from value of B @ 16:00
16:02 2.06

Has anyone done anything like this before? I'm looking at the zoo
package to see if it can help me, but I havent quite figured out how
to do this kind of thing yet. Is this even a good way to checking
whether series B is very similar to series A at the discrete tick
intervals? Any better methods?(I guess another way might be to align
the two subsetted series exactly and just take differences).

Thanks
Rory



More information about the R-SIG-Finance mailing list