Retrieving Specific Financial Statements in Quantmod

405 views Asked by At

I am currently working in the quantmod package and wish to retrieve some financial statements. I am having an issue specifying what type of financial statement I want. By default it retrieves the Annual BS.

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

When I do attempt to specify the FS, it gives me the error message of either saying 'x' must be type of financials or since I"m using lapply it won't recognize it as a function. I do like using lapply for this because it puts the financial statements in a data frame and in the exact format that I like, I just want to do it for the Annual IS.

Thank you!

1

There are 1 answers

0
dragon On

This code works and not only includes the BS, but the IS and CF as well:

Input:

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

Output:

> 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 or ?viewFinancials would have shown you the possible options/arguments for viewFinancials.