[R-SIG-Finance] quantmod getOptionChain failing on one character symbol

Jeff Ryan jeff.a.ryan at gmail.com
Mon Aug 2 18:55:28 CEST 2010


Marc,

Next time reports for quantmod should be directed to the maintainer
(me) instead of the list.

Josh helped debug this.  In effect the screen scraping was getting
caught up on short symbol names.

Index: pkg/R/getOptionChain.R
===================================================================
--- pkg/R/getOptionChain.R	(revision 543)
+++ pkg/R/getOptionChain.R	(working copy)
@@ -35,7 +35,7 @@
     return(structure(lapply(allExp, getOptionChain.yahoo,
Symbols=Symbols), .Names=format(as.yearmon(allExp))))
   }

-  where <- cumsum(rle(sapply(gregexpr(Symbols,strsplit(opt, "<tr")[[1]]),
+  where <- cumsum(rle(sapply(gregexpr(paste("s",Symbols,sep="="),strsplit(opt,
"<tr")[[1]]),
                              function(x) if(x[1] > 0) TRUE else
FALSE))[[1]])[c(5:8)]
   CNAMES <- c("Strike","Last","Chg","Bid","Ask","Vol","OI")


Committed at rev 545 on R-forge.

Thanks,
Jeff

On Mon, Aug 2, 2010 at 10:42 AM, Marc Delvaux <mdelvaux at gmail.com> wrote:
> While working on a script comparing options across a large number of
> symbols, I hit a problem where symbols that are one character long
> (specifically I was trying "C", "F" and "T") generate an error for
> getOptionChain().  This was true for both a Linux and Windows system.
> Below is an example for the Windows system, I upgraded quantmod from
> R-forge to get a working getOptionChain() after the change in option
> naming convention.
>
>> Options <- getOptionChain("AAPL")
>> str(Options)
> List of 3
>  $ calls : num [1:41, 1:7] 140 145 150 155 160 165 170 175 180 185 ...
>  ..- attr(*, "dimnames")=List of 2
>  .. ..$ : chr [1:41] "AAPL100821C00140000" "AAPL100821C00145000"
> "AAPL100821C00150000" "AAPL100821C00155000" ...
>  .. ..$ : chr [1:7] "Strike" "Last" "Chg" "Bid" ...
>  $ puts  : num [1:37, 1:7] 140 145 150 155 160 165 170 175 180 185 ...
>  ..- attr(*, "dimnames")=List of 2
>  .. ..$ : chr [1:37] "AAPL100821P00140000" "AAPL100821P00145000"
> "AAPL100821P00150000" "AAPL100821P00155000" ...
>  .. ..$ : chr [1:7] "Strike" "Last" "Chg" "Bid" ...
>  $ symbol: chr "AAPL"
>> Options <- getOptionChain("C")
> Error in calls[, 2] : incorrect number of dimensions
>> Options <- getOptionChain("T")
> Error in getOptionChain.yahoo(Symbols = "T") : subscript out of bounds
>> Options <- getOptionChain("F")
> Error in calls[, 2] : incorrect number of dimensions
>> sessionInfo()
> R version 2.11.1 (2010-05-31)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] quantmod_0.3-14 TTR_0.20-2      Defaults_1.1-1  xts_0.7-4
> zoo_1.7-0
>
> loaded via a namespace (and not attached):
> [1] grid_2.11.1    lattice_0.18-8 tools_2.11.1
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list