Reputation: 1
I am trying to get optionChain for several expiration dates by enumerating them:
library(quantmod)
x <- getOptionChain(symbol, Exp=as.Date(c("2013-08-17", "2013-07-20")))
But I get
Error in file(con, "r") : invalid 'description' argument
What is the correct way to do that?
Second, is there a way to get the list of option expiration dates for a stock?
The reason I am asking is that
getOptionChain("NOK", Exp=NULL)
gives an error so I am forced to list the expiration dates (since I want the full chain).
Thanks Ashu
Upvotes: 0
Views: 2211
Reputation: 2986
@Ashu, try:
#your list of expiration dates
exp=c("2013-08-17", "2013-07-20")
x=list()
for(i in 1:length(exp)) x<-c(getOptionChain("NOK",exp[i]),x)
If you have a list of ticker symbols substitute "NOK" with the list and change the line accordingly.
using lapply which is more R-like and efficient:
lapply(exp,function(x) getOptionChain("NOK",x))
Upvotes: 4