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

david hilton shanabrook davidshanabrook at icloud.com
Thu Apr 9 16:44:26 CEST 2015

Short explanation:
How can I tell when  getOptionChain was updated?

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")

More information about the R-SIG-Finance mailing list