2017-10-21 103 views
0

我下載了一個腳本從谷歌下載歷史數據,但是它只下載了一年的數據,但是我想下載所有的數據,但是腳本的數據起始日期爲R下載谷歌財務數據

# 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)} 

只下載2016至17年的數據,但任何人都可以告訴我爲什麼嗎? 謝謝。

+0

這個腳本是荒謬的。你確定你正確地粘貼了整個事情嗎? – danh

回答