Skip to content

Commit

Permalink
Add all Yahoo Finance fields to getOptionChain
Browse files Browse the repository at this point in the history
Add the following fields, which completes the set of all data
currently returned.

  contractSymbol
  currency
  percentChange
  contractSize
  expiration

Convert expiration date to POSIXct to assist estimating theta decay.

Fixes #318.
  • Loading branch information
semiographics committed Jun 19, 2021
1 parent 85aa986 commit 483f7d9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/getOptionChain.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ getOptionChain.yahoo <- function(Symbols, Exp, ...)
# clean up colnames, in case there's weirdness in the JSON
names(x) <- tolower(gsub("[[:space:]]", "", names(x)))
# set cleaned up colnames to current output colnames
d <- with(x, data.frame(Strike=strike,
d <- with(x, data.frame(ContractID= if("contractsymbol" %in% names(x)) {contractsymbol} else {NA},
ConractSize= if("contractsize" %in% names(x)) {contractsize} else {NA},
Currency= if("currency" %in% names(x)) {currency} else {NA},
Expiration= as.POSIXct(expiration,origin="1970-01-01", tz="UTC"),
Strike=strike,
Last=lastprice,
Chg=change,
ChgPct= if("percentchange" %in% names(x)) {percentchange} else {NA},
Bid= if("bid" %in% names(x)) {bid} else {NA},
Ask= if("ask" %in% names(x)) {ask} else {NA},
Vol= if("volume" %in% names(x)) {volume} else {NA},
Expand Down

0 comments on commit 483f7d9

Please sign in to comment.