如何在viewFinancials中概括自动收报机

时间:2017-01-24 02:05:07

标签: r quantmod

我正在尝试将C.f(或IBM.fAPPL.f)保存到通用变量(例如STOCK.F)中,然后重复使用通用命令 viewFinancials(STOCK.F, type = c("BS"), period = freq, subset = NULL)

在下面的代码中,如果我想分析不同的股票," IBM",我必须将所有的股票代码名称," C",更改为" IBM& #34;在代码中。我试图在一开始就找到一种初始化通用变量(例如' Stock')的方法,因此我只能通过将赋值更改为变量来分析不同的股票' Stock' 。

类似的东西:

Stock<-IBM;

viewFinancials(STOCK.F, type = c("BS"), period = freq, subset = NULL)

代码是:

SP <- new.env()
library(quantmod)

tickers = c("C")
start.date = "2000-01-01"
end.date = "2017-01-16"

getSymbols(tickers, env = SP, src = "yahoo", 
    from = as.Date(start.date), to = as.Date(end.date))

stock.data = SP$C

getFinancials(tickers, env = SP, src = "google", auto.assign = TRUE) 

freq = "A" # for annual
viewFin(SP$C.f,type = c('IS'),period = freq,subset = NULL)

1 个答案:

答案 0 :(得分:0)

我猜您正在寻找收益表,对吧。试试下面的脚本。这是大3;损益表,现金流量表和资产负债表。

require(quantmod)
setwd("C:/your_path/Desktop/")
stocks <- c("AXP","BA","CAT","CSCO","CVX","DD","DIS")

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