I am currently running the following code in order to extract from the quantmod
package some financial information.
library(quantmod)
symbols <- c("HOG", "GOOG", "GE")
tickers <- new.env()
lapply(symbols, 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')}))
df <- rbind(BS, IS, CF)
df <- t(df)
Which is a little messy but from here I can clean the data and proceed with some calculations. However I want to know if there is a more efficient way using the tidyquant
package as I would like to run this over many ticker symbols and it is currently breaking when the quantmod
package cannot download/find the financial information for a particular ticker.
I am working with;
library(tidyquant)
library(dplyr)
symbols <- c("HOG", "GOOG", "GE")
stock_financials <- symbols %>%
tq_get(get = "financials")
stock_financials$annual
I can see that the data is a tibble within a tibble but how is it possible to extract the information as before, or how can I more easily access the tibble data for stock_financials$annual
?
Modifying and using
filter(stock_financials, type == "BS") %>% unnest()
From this answer does not seem to work for me.