[R-SIG-Finance] quantmod, getOptionChain update time/date

James Toll james at jtoll.com
Thu Apr 9 22:52:31 CEST 2015

> On Apr 9, 2015, at 9:44 AM, david hilton shanabrook <davidshanabrook at icloud.com> wrote:
> Short explanation:
> How can I tell when  getOptionChain was updated?

If you look at the code for getOptionChain (https://github.com/joshuaulrich/quantmod/blob/develop/R/getOptionChain.R) you will see that the data is retrieved from Yahoo’s web page.  In the case of your example that would be:


Yahoo does not appear to provide any information on that page as to when the option data was last updated, although there does appear to be information regarding when the stock quote was updated.  If Yahoo doesn’t provide that information, the function obviously can’t as well.

If you’re really in need of higher quality data, you’re likely better off purchasing data.

As a side note, the getSymbols function provides information about when the data was last retrieved from Yahoo.  While a different issue, I wonder if it would be worth incorporating that into the list returned by the getOptionChain function as well.


> library(quantmod)
> chain <- getOptionChain("AAPL”)
> More detailed and wordy:
> This code will return the option chain for Apple with the open interest.  open interest is updated on finance.yahoo sometimes after market close, but it can be as late as the next day??  
> I want to be able to determine the data/time of when it was updated.  This is important because otherwise I have no idea if I am working with the previous day close or two days previous.
> My solution was to sum all of the open interest, write this to a file.  Next time I run the code read that file and compare to the current sum to see if it has changed.  Messy, and unclear if it is working.  Also I use “AAPL" to check and assume this applies to all data from getOptionChain
> wasUpdatedToday <- function() {
> 	storedDay <- read.csv("storedDay.txt")
> 	txt <- paste("Open interest updated:", storedDay$x)
> 	chain <- getOptionChain("AAPL")
> 	currentOI <- sum(chain$puts$OI,chain$calls$OI)
> 	storedOI <- read.csv("storedOI.txt")
> 		if (currentOI != storedOI$x){
> 			write.csv(currentOI, "storedOI.txt")
> 			write.csv(format.Date(Sys.time(),"%b %d"),"storedDay.txt")
> 			txt <- paste("Open interest from", storedDay$x,"updated today")
> 		}
> 	return(txt)
> 	}
> _______________________________________________
> R-SIG-Finance at r-project.org 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.

More information about the R-SIG-Finance mailing list