在Quantmod中检索特定财务报表

时间:2015-06-17 13:43:54

标签: quantmod financial

我目前正在使用quantmod包,希望检索一些财务报表。我有一个问题,指明我想要什么类型的财务报表。默认情况下,它会检索年度BS。

tickers <-new.env()
s <-c(list of tickers...)
lapply(s, getFinancials, env=tickers)
FS <-data.frame(lapply(tickers, viewFinancials)

当我尝试指定FS时,它会向我显示错误消息:“x&#39; x&#39;必须是财务类型,或者因为我使用lapply它不会认为它是一个功能。我喜欢使用lapply,因为它将财务报表放在一个数据框中,并以我喜欢的确切格式,我只是想为年度IS做。

谢谢!

1 个答案:

答案 0 :(得分:1)

此代码有效,不仅包括BS,还包括IS和CF:

<强>输入:

tickers <-new.env()
t <-c("AAL",  "AAME", "AAOI")
lapply(t, getFinancials, env=tickers)
BS <- data.frame(lapply(tickers, function(x) {viewFinancials(x, type= 'BS', period = 'A')}))
IS <- data.frame(lapply(tickers, function(x) {viewFinancials(x, type= 'IS', period = 'A')}))
CF <- data.frame(lapply(tickers, function(x) {viewFinancials(x, type= 'CF', period = 'A')}))

<强>输出:

> tickers <-new.env()
> t <-c("AAL",  "AAME", "AAOI")
> lapply(t, getFinancials, env=tickers)
[[1]]
[1] "AAL.f"

[[2]]
[1] "AAME.f"

[[3]]
[1] "AAOI.f"

> BS <- data.frame(lapply(tickers, function(x) {viewFinancials(x, type= 'BS', period = 'A')}))
Annual Balance Sheet for AAME
Annual Balance Sheet for AAL
Annual Balance Sheet for AAOI
> IS <- data.frame(lapply(tickers, function(x) {viewFinancials(x, type= 'IS', period = 'A')}))
Annual Income Statement for AAME
Annual Income Statement for AAL
Annual Income Statement for AAOI
> CF <- data.frame(lapply(tickers, function(x) {viewFinancials(x, type= 'CF', period = 'A')}))
Annual Cash Flow Statement for AAME
Annual Cash Flow Statement for AAL
Annual Cash Flow Statement for AAOI

?viewFin?viewFinancials会向您显示viewFinancials的可能选项/参数。