야후의 데이터를 기반으로하는 해결책을 찾을 수 없었습니다. 저는 여전히 재고 데이터를 위해 QuantMod와 Yahoo를 사용하고 있으며 현재 옵션 체인 데이터를 위해 Google을 사용하고 있습니다. 여기에 작업 솔루션에서 첫 번째 시도이다 :
library(rjson)
getOptionChain <- function (symbol) {
# symbol = "WMT"
url <- "https://www.google.com/finance/option_chain?q="
# url <- paste(url, symbol, "&expd=15&expm=01&expy=2016&output=json", sep="")
url <- paste(url, symbol, "&output=json", sep="")
google.options.json <- readLines(url, warn = FALSE)
options.json <- google.options.json
options.json <- gsub("[{]", "{\"", options.json)
options.json <- gsub("[:]", "\":", options.json)
options.json <- gsub("[,] ", "$$$", options.json)
options.json <- gsub("[,]", ",\"", options.json)
options.json <- gsub("[,]\"[{]", ",{", options.json)
options.json <- gsub("[$][$][$]", ", ", options.json)
options.list <- fromJSON(options.json)
#get the options chain without an expiry date and then determine longest option
last.expiration <- length(options.list[["expirations"]])
month <- sprintf("%02d", options.list[["expirations"]][[last.expiration]]$m)
day <- sprintf("%02d", options.list[["expirations"]][[last.expiration]]$d)
year <- options.list[["expirations"]][[last.expiration]]$y
#now request option chain for the longest expiry
url <- "https://www.google.com/finance/option_chain?q="
url <- paste(url, symbol, "&expd=", day, "&expm=", month, "&expy=", year, "&output=json", sep="")
google.options.json <- readLines(url, warn = FALSE)
options.json <- google.options.json
options.json <- gsub("[{]", "{\"", options.json)
options.json <- gsub("[:]", "\":", options.json)
options.json <- gsub("[,] ", "$$$", options.json)
options.json <- gsub("[,]", ",\"", options.json)
options.json <- gsub("[,]\"[{]", ",{", options.json)
options.json <- gsub("[$][$][$]", ", ", options.json)
options.list <- fromJSON(options.json)
options <- ldply (options.list[["calls"]], data.frame)
options <- rename(options, c("s" = "contract.name",
"p" = "price",
"b" = "bid",
"a" = "ask",
"c" = "change",
"cp" = "change.percentage",
"oi" = "open.interest",
"vol" = "volume"))
options <- options[c("contract.name",
"strike",
"price",
"change",
"change.percentage",
"bid",
"ask",
"volume",
"open.interest")]
options$expiry <- paste(options.list[["expiry"]]$m, options.list[["expiry"]]$d, options.list[["expiry"]]$y, sep = "/")
last.expiration <- length(options.list[["expirations"]])
options$longest.available.expiry <- paste(options.list[["expirations"]][[last.expiration]]$m,
options.list[["expirations"]][[last.expiration]]$d,
options.list[["expirations"]][[last.expiration]]$y, sep = "/")
options$underlying.price <- options.list[["underlying_price"]]
return(options)
}
이 될 것으로 보인다는 아닌 [드문 문제] (http://r.789695.n4.nabble.com/quantmod-getOptionChain-errors-td4645782.html) 결정적인 문제가 없습니다. – hrbrmstr
그리고'quantmod' 만이 문제가되는 것은 아닙니다. (http://stackoverflow.com/questions/26539963/how-can-i-download-option-data-given-the-new-format-introduced- 오늘 -10-23-14). 야후는 HTML 형식을 변경 한 것으로 보이며 스크래퍼를 깨뜨리고있다. – hrbrmstr
Google은 실용적인 대안을 제공합니다. 아래 답변을 참조하십시오. – jclouse