[R-SIG-Finance] Extract option IDs from option chain
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Sep 7 06:26:44 CEST 2010
On Mon, Sep 6, 2010 at 11:29 PM, Marc Delvaux <mdelvaux at gmail.com> wrote:
> Just a final word of caution if you automate this procedure across a large
> number of stocks. From time to time, you will find option symbols that
> deviate from the standard format, i.e. where there are more than 6
> characters between the stock ticker and the option type symbol. Code
If we can assume that its garbage followed by 6 good digits followed
by P then just replace \d+ with \d{6} in the strapply solution like
this:
> x <- c("BHI1101016P00017000", "BHI1101016P00018000", "BHI1101016P00019000",
+ "BHI101016P00020000", "BHI1101016P00020000", "BHI1101016P00021000",
+ "BHI1101016P00022000", "BHI101016P00022500", "BHI1101016P00023000",
+ "BHI1101016P00024000", "BHI101016P00025000", "BHI1101016P00025000",
+ "BHI1101016P00026000", "BHI101016P00030000", "BHI101016P00034000",
+ "BHI101016P00035000", "BHI101016P00036000", "BHI101016P00037000",
+ "BHI101016P00038000", "BHI101016P00039000", "BHI101016P00040000",
+ "BHI101016P00041000", "BHI101016P00042000", "BHI101016P00043000",
+ "BHI101016P00044000", "BHI101016P00045000", "BHI101016P00046000",
+ "BHI101016P00047000", "BHI101016P00048000", "BHI101016P00049000",
+ "BHI101016P00050000", "BHI101016P00055000", "BHI101016P00060000",
+ "BHI101016P00065000")
>
> strapply(x, "(\\d{6})P", ~ as.Date(x, "%y%m%d"), simplify = c)
[1] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
[6] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
[11] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
[16] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
[21] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
[26] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
[31] "2010-10-16" "2010-10-16" "2010-10-16" "2010-10-16"
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-SIG-Finance
mailing list