yahoo<-function(sym,current = TRUE, a=0,b=1,c=2000,d,e,f,g="d")
{
if(current){
f<-as.numeric(substr(as.character(Sys.time()),start = 1,stop = 4))
d<-as.numeric(substr(as.character(Sys.time()),start = 6,stop = 7))-1
e<-as.numeric(substr(as.character(Sys.time()),start = 9,stop = 10))
}
require(data.table)
tryCatch(
suppressWarnings(
fread(paste0("http://ichart.yahoo.com/table.csv",
"?s=",sym,
"&a=",a,
"&b=",b,
"&c=",c,
"&d=",d,
"&e=",e,
"&f=",f,
"&g=",g,
"&ignore=.csv"),sep=",")),
error = function(e) NULL
)
}
当我运行Google&lt; -yahoo(“GOOG”)时,这是我收到的消息:
尝试网址“http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=8&e=13&f=2017&g=d&ignore=.csv” 内容类型'text / html; charset = utf-8'长度未知 下载了1078字节
那么如何更改该功能使其有效?
答案 0 :(得分:0)
此代码不起作用,因为the Yahoo Finance web service which you're trying to access was discontinued in May 2017。您需要找到此数据的其他来源。