[R] Finding the nearest data in intraday data from two zoo objects

Matthew Dowle mdowle at mdowle.plus.com
Wed Nov 24 17:39:18 CET 2010


Try data.table with the roll=TRUE argument.

Set your keys and then write :

    futData[optData,roll=TRUE]

That is fast and as you can see, short. Works on
many millions and even billions of rows in R.

Matthew

http://datatable.r-forge.r-project.org/


"Santosh Srinivas" <santosh.srinivas at gmail.com> wrote in message 
news:4ced3783.2af98e0a.57f0.ffffbb87 at mx.google.com...
> Hello Group,
>
> I have the following options and future data in zoo objects
>
>> head(optData.z)
>                       ExpDt OptTyp Strike TrdPrice TotTrdQty
> 2009-01-01 09:55:03 20090129      1   2900 180.0000        50
> 2009-01-01 09:55:31 20090129      1   2900 188.0000        50
> 2009-01-01 09:55:37 20090129      1   2900 185.0000       500
> 2009-01-01 09:55:39 20090129      1   2900 185.0000       500
> 2009-01-01 09:55:47 20090129      1   2900 185.1125       600
> 2009-01-01 09:55:48 20090129      1   2900 185.2500        50
>
>> head(futData.z)
>                       ExpDt OptTyp Strike TrdPrice TotTrdQty
> 2009-01-01 09:55:09 20090129      2      0 2979.000       900
> 2009-01-01 09:55:11 20090129      2      0 2976.633       600
> 2009-01-01 09:55:12 20090129      2      0 2977.211       900
> 2009-01-01 09:55:14 20090129      2      0 2977.750       800
> 2009-01-01 09:55:15 20090129      2      0 2977.019      4300
> 2009-01-01 09:55:16 20090129      2      0 2977.050       800
>
> I want to get the closest available futures price for every option ... Is
> there any function like the excel equivalent of approximate VLOOKUP of 
> excel
> using date time?
>
> Thank you.
>



More information about the R-help mailing list