[R-SIG-Finance] Extract option IDs from option chain

rex rex at nosyntax.net
Wed Sep 8 19:45:33 CEST 2010


Jeff Ryan <jeff.a.ryan at gmail.com> [2010-09-06 20:46]:
>One other comment though --- if you are just looking to get days to
>expiry, you are specifically requesting that in the call to retrieve
>the chains - so all the parsing isn't really needed for that part.

The expiration day is not specified in my call. The call to getOptionChain is:
allOpts <- getOptionChain(stkSym, Exp=optExpire) where optExpire
<- "2010-09". So, parsing the returned option data is required to
get the expiration day unless some other solution is used.

The obscure part of my code is this line:  

> id         <- dimnames(allOpts$puts)[1][[1]]

I only discovered it provided what's needed after a lot of
fiddling with things that didn't work. I now use the much clearer:

id <- rownames(allOpts$puts)

It's obvious in retrospect. :(

The rest is straightforward:

> id1        <- id[1]
> expDate    <- as.Date(paste("20", substr(id1,5,6), "-", substr(id1,7,8), "-", substr(id1,9,10), sep=""))

Jeff, thanks again for your many and continuing contributions to
the R community. I use QuantMod constantly and recently started
exploring your IBrokers package. 

-rex
-- 
Here I am in 53 B.C. and all I want is a dill pickle!!



More information about the R-SIG-Finance mailing list