I see that getOptionChain has calls, puts and sym available, but I do not
see Trade Date or Underlying Settlement Price. Is that correct?

 

I'm trying to add Trade Date and Underlying Settlement Price to the calls
from getOptionChain. I add the Settlement Price correctly but I am unable to
add the Trade Date. No error is produced but the Trade Date, which is the
last column, populates with NA and a column heading of coredata(x). First
few rows of file are first and code is second. Thanks in advance. 

 

Index Strike      Last  Chg   Bid   Ask   Vol   OI    SPY.Close
coredata(x)

1     25    117.58      0     124.82      125.07      2     10    150.25
NA

2     45    102.54      0     104.82      105.07      11    11    150.25
NA

 

library(quantmod)

 

##

## Get Option Chain from Yahoo

##

 

sym<-"SPY"

nsym<-nchar(sym)

nsym

from_date="2013-1-1"

Stock<-getSymbols.yahoo(sym, from = from_date, src = "yahoo", verbose=TRUE,
auto.assign=FALSE) Close<-Stock[nrow(Stock)] Trade_Date<-Close[,0]
Underlying_Close<-Close[,4] Trade_Date Underlying_Close optExpire <-
"2013-03"

Options<-getOptionChain(sym, Exp=optExpire)

##print(Options$calls)

file_name<-paste0(sym,optExpire,".csv",sep="")

write.zoo(Options$calls, file = file_name, append = FALSE, quote = TRUE, sep
= ",", col.names = TRUE)

 

file_name<-paste0(sym,"_",optExpire,".csv",sep="")

Options_Stock<-na.locf(merge(Options$calls,Underlying_Close, retside=c(TRUE,
TRUE))) Options_Stock<-na.locf(merge(Options_Stock, Trade_Date,
retside=c(TRUE, TRUE)))

 

write.zoo(Options_Stock, file = file_name, append = FALSE, quote = TRUE, sep
= ",", col.names = TRUE)

quit()

 

 


	[[alternative HTML version deleted]]

