Santosh Srinivas
2010-Nov-24 16:04 UTC
[R] Finding the nearest data in intraday data from two zoo objects
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.
Matthew Dowle
2010-Nov-24 16:39 UTC
[R] Finding the nearest data in intraday data from two zoo objects
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. >
Gabor Grothendieck
2010-Nov-24 18:49 UTC
[R] Finding the nearest data in intraday data from two zoo objects
On Wed, Nov 24, 2010 at 11:04 AM, Santosh Srinivas <santosh.srinivas at gmail.com> wrote:> 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? >See this: https://stat.ethz.ch/pipermail/r-sig-finance/2010q2/006077.html -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com