R 下载谷歌财务数据
我从google下载了一个脚本来下载历史数据,但是,它只下载了一年的数据,但是我想下载所有的数据,但是脚本有数据的开始日期R 下载谷歌财务数据,r,datatable,google-finance,R,Datatable,Google Finance,我从google下载了一个脚本来下载历史数据,但是,它只下载了一年的数据,但是我想下载所有的数据,但是脚本有数据的开始日期 # Make sure data.table is installed if(!'data.table' %in% installed.packages()[,1]) install.packages('data.table') # Function to fetch google stock data google <- function(sym, curren
# Make sure data.table is installed
if(!'data.table' %in% installed.packages()[,1])
install.packages('data.table')
# Function to fetch google stock data
google <- function(sym, current = TRUE, sy = 2005, sm = 1, sd = 1, ey,
em, ed)
{
if(current){
system_time <- as.character(Sys.time())
ey <- as.numeric(substr(system_time, start = 1, stop = 4))
em <- as.numeric(substr(system_time, start = 6, stop = 7))
ed <- as.numeric(substr(system_time, start = 9, stop = 10))
}
require(data.table)
google_out = tryCatch(
suppressWarnings(
fread(paste0("http://www.google.com/finance/historical",
"?q=", sym,
"&startdate=", paste(sm, sd, sy, sep = "+"),
"&enddate=", paste(em, ed, ey, sep = "+"),
"&output=csv"), sep = ",")),
error = function(e) NULL)
if(!is.null(google_out)){
names(google_out)[1] = "Date"
}
return(google_out)}
#确保安装了data.table
如果(!”数据表“%in%installed.packages()[,1]”)
install.packages('data.table'))
#函数获取谷歌股票数据
谷歌我想你的答案就在这里:
“Google Finance API停止接收此URL的请求。截至撰写本文时,它只返回一年的每日数据”
这个剧本是荒谬的。你确定你正确粘贴了整个东西吗?