library(dplyr) library(tidyr) library(finstr) data(xbrl_data_aapl2013) data(xbrl_data_aapl2014)
Use XBRL package to parse XBRL files. For example:
library(XBRL) # parse XBRL (Apple 10-K report) xbrl_url2014 <- "http://edgar.sec.gov/Archives/edgar/data/320193/000119312514383437/aapl-20140927.xml" xbrl_url2013 <- "http://edgar.sec.gov/Archives/edgar/data/320193/000119312513416534/aapl-20130928.xml" xbrl_data_aapl2014 <- xbrlDoAll(xbrl_url2014) xbrl_data_aapl2013 <- xbrlDoAll(xbrl_url2013)
With xbrl_get_statements
convert XBRL data to statements object.
library(finstr) st2013 <- xbrl_get_statements(xbrl_data_aapl2013) st2014 <- xbrl_get_statements(xbrl_data_aapl2014) # merge all statements st_all <- merge( st2013, st2014 ) # get balance sheets balance_sheet <- st_all$StatementOfFinancialPositionClassified tail(balance_sheet,2)
The only way to visualize a balance sheet is by exposing a limited number of values.
The first step is then to aggregate a balance sheet by selected concepts.
We can use expose
to specify these groups of elements. For example:
bs_simple <- expose( balance_sheet, # Assets `Current Assets` = "AssetsCurrent", `Noncurrent Assets` = other("Assets"), # Liabilites and equity `Current Liabilities` = "LiabilitiesCurrent", `Noncurrent Liabilities` = other(c("Liabilities", "CommitmentsAndContingencies")), `Stockholders Equity` = "StockholdersEquity" )
library(htmlTable) print(bs_simple, html = TRUE, big.mark = ",", dateFormat = "%Y")
Using ggplot2 package we can plot a simplified balance sheet:
library(ggplot2) plot_double_stacked_bar(bs_simple)
Another option is to group by faceting balance sheet side instead of date:
plot_double_stacked_bar(bs_simple, by_date = FALSE)
Using proportional form we reveal the changes in balance sheet structure:
bs_simple_prop <- proportional(bs_simple) plot_double_stacked_bar(bs_simple_prop)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.