Error in getOptionChain expiry date for multiple tickers

Viewed 26

I'm running the Getting options chain for multiple tickers but something is wrong with the expiration date for multiple tickers.

Here's a sample code:

library(quantmod)
Symbols <- c("XOM","MSFT","JNJ")
Options.20220429 <- getOptionChain("Symbols", "2022-04-29")

And I'm getting the following error:

    Error in getOptionChain.yahoo(Symbols = "Symbols", Exp = "2022-04-29") : 
  Provided expiry date(s) not found. Available dates are:

However, if I run a single ticker with same expiration date one by one like the one below, everything works fine.

getOptionChain("JNJ", "2022-04-29")
1 Answers

You need to provide the expiry date for each one of your tickers. The following code works:

Options.20220429 <- lapply(Symbols, getOptionChain, Exp = "2022-04-29")

names(Options.20220429) <- Symbols
Related