joshuaulrich / joshuaulrich/quantmod
A typo and an attempt at a quality of life change
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 906
- Forks
- 233
- PR merge metrics
- No merged PRs in 30d
Description
- I found a typo in the
getOptionChain.Rfile:
# 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".
- I tried and failed to speed up the time it takes to download whole options chains when you use the
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:
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with getOptionChain.R and the getOptionChain.yahoo entry point; inspect how Yahoo's options-chain response is requested and parsed, and determine whether Yahoo supports requesting only selected columns. Correct the ContractSize typo, then establish whether the omission request can reduce retrieval time or should be documented as post-download filtering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- api, data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100