通过quantmod下载批量财务数据

时间:2016-03-06 13:51:48

标签: r bulk quantmod financial balance

R包有quantmod。此外,还要求提供财务数据。

getFinancials('GE')

GE是一个自动收报机。

我想知道,我如何下载一堆资产负债表(我有一个矢量,比方说,2000个代码),然后将其导出到单独文件中的任何SQL数据库。

嗯,基本上我需要它用于其他分析软件,但找到资产负债表的综合数据库似乎是一项任务。我看到的唯一选择是通过quantmod来实现。

基本下载和视图看起来像:

library(quantmod)
getFinancials('GE')
viewFinancials(GE.f)

1 个答案:

答案 0 :(得分:0)

你可以这样做。

require(quantmod)
setwd("C:/Users/your_path_here/downloads")
stocks <- c("AXP","BA","CAT","CSCO","CVX","DD","DIS","GE","GS","HD","IBM","INTC","JNJ","JPM","KO","MCD","MMM","MRK","MSFT","NKE","PFE","PG","T","TRV","UNH","UTX","V","VZ","WMT","XOM")

# equityList <- read.csv("EquityList.csv", header = FALSE, stringsAsFactors = FALSE)
# names(equityList) <- c ("Ticker")

for (i in 1 : length(stocks)) {   
        temp<-getFinancials(stocks[i],src="google",auto.assign=FALSE)
        write.csv(temp$IS$A,paste(stocks[i],"_Income_Statement(Annual).csv",sep=""))
        write.csv(temp$BS$A,paste(stocks[i],"_Balance_Sheet(Annual).csv",sep=""))
        write.csv(temp$CF$A,paste(stocks[i],"_Cash_Flow(Annual).csv",sep=""))
        write.csv(temp$IS$A,paste(stocks[i],"_Income_Statement(Quarterly).csv",sep=""))
        write.csv(temp$BS$A,paste(stocks[i],"_Balance_Sheet(Quaterly).csv",sep=""))
        write.csv(temp$CF$A,paste(stocks[i],"_Cash_Flow(Quaterly).csv",sep=""))
}