# set cleaned up colnames to current output colnames
cnames <- c(contractsymbol = "ContractID",
contractsize = "ConractSize",
currency = "Currency",
On line 22 the renamed contract size column is missing a "t".
getOptionChain.yahoo <- function(Symbols, Exp, ..., session=NULL)
{
omit <- list(...)$omit # defined the omit argument here
NewToOld <- function(x, tz = NULL, omit = NULL) {
if(is.null(x) || length(x) < 1)
return(NULL)
# ...
# convert trade time to exchange timezone
d$LastTradeTime <- .POSIXct(d$LastTradeTime, tz=tz)
# Omit specified columns if 'omit' is provided
if(!is.null(omit)) {
d <- d[ , !(names(d) %in% omit), drop=FALSE]
}
return(d)
}
if (is.null(session)) {
session <- .yahooSession()
}
if (!session$can.crumb) {
stop("Unable to obtain yahoo crumb. If this is being called from a GDPR country, Yahoo requires GDPR consent, which cannot be scripted")
}
# ...
if(is.null(Exp)) {
# Return all expiries if Exp = NULL
out <- lapply(all.expiries, function(e) {
getOptionChain.yahoo(Symbols, e, .expiry.known=TRUE, session=session, omit=omit) # added omit here
})
# Expiry format was "%b %Y", but that's not unique with weeklies. Change
# format to "%b.%d.%Y" ("%Y-%m-%d wouldn't be good, since names should
# start with a letter or dot--naming things is hard).
return(setNames(out, format(all.expiries.posix, "%b.%d.%Y")))
} else {
# Ensure data exist for user-provided expiry date(s)
if(inherits(Exp, "Date"))
valid.expiries <- as.Date(all.expiries.posix) %in% Exp
else if(inherits(Exp, "POSIXt"))
valid.expiries <- all.expiries.posix %in% Exp
else if(is.character(Exp)) {
expiry.range <- range(unlist(lapply(Exp, .parseISO8601, tz="UTC")))
valid.expiries <- all.expiries.posix >= expiry.range[1] &
all.expiries.posix <= expiry.range[2]
}
if(all(!valid.expiries))
stop("Provided expiry date(s) not found. Available dates are: ",
paste(as.Date(all.expiries.posix), collapse=", "))
expiry.subset <- all.expiries[valid.expiries]
if(length(expiry.subset) == 1)
return(getOptionChain.yahoo(Symbols, expiry.subset, .expiry.known=TRUE, session=session, omit=omit)) # added omit
else {
out <- lapply(expiry.subset, function(e) {
getOptionChain.yahoo(Symbols, e, .expiry.known=TRUE, session=session, omit=omit) # added omit
})
# See comment above regarding the output names
return(setNames(out, format(all.expiries.posix[valid.expiries], "%b.%d.%Y")))
}
}
}
This didn't reduce the time it took to retrieve the data, and I am guessing it's because yahoo sends all the columns and my argument only removes them after the fact. Is there a way to request only a subset of the data from yahoo?
getOptionChain.Rfile:On line 22 the renamed contract size column is missing a "t".
Exp=NULLargument. My attempt was to add anomit = c()argument togetOptionChain()that would let you specify a list of columns you don't need when you grab the option chain:This didn't reduce the time it took to retrieve the data, and I am guessing it's because yahoo sends all the columns and my argument only removes them after the fact. Is there a way to request only a subset of the data from yahoo?