Giter VIP home page Giter VIP logo

Comments (7)

bergant avatar bergant commented on May 25, 2024

There is no special support (yet) in finstr. But, when the id of the XBRL concept is known, it is possible to extract it from the XBRL directly. The sec.gov page (interactive data) exposes the concept id when clicked on the description in the table.

To extract the value from XBRL, join the element (concept) to the fact (value) and context (period, dimensions). Here is an example for the dei_EntityCommonStockSharesOutstanding in 10-K:

# Apple 10-K report:
doc_url <- "https://www.sec.gov/Archives/edgar/data/320193/000162828016020309/aapl-20160924.xml"

# download and parse XBRL
library(XBRL)
old_o <- options(stringsAsFactors = FALSE)
xbrl_data <- xbrlDoAll(doc_url)
options(old_o)

library(dplyr)

xbrl_data$element %>% 
  filter(elementId == "dei_EntityCommonStockSharesOutstanding") %>% 
  left_join(xbrl_data$fact, by = "elementId") %>% 
  left_join(xbrl_data$context, by = "contextId") %>% 
  mutate(value = as.numeric(fact) * 10 ^ as.numeric(decimals)) %>% 
  select(elementId, value, unitId, endDate)

#                                elementId   value unitId    endDate
# 1 dei_EntityCommonStockSharesOutstanding 5332313 shares 2016-10-14

from finstr.

dmaupin12 avatar dmaupin12 commented on May 25, 2024

excellent, thanks for the help.

from finstr.

Satya2IB avatar Satya2IB commented on May 25, 2024

Thanks bergant for this excellent package working smoothly with SEC filings!

I am particularly looking for debt as reported in the balance sheet and debt breakup as given in the Notes to Financial Statement. The id of the XBRL concept is known: us-gaap_LongTermDebtNoncurrent

I ran into some error while running the query:

install.packages("devtools")
devtools::install_github("bergant/finstr")

Library(XBRL)
xbrl_url17 <- https://www.sec.gov/Archives/edgar/data/320193/000032019317000009/aapl-20170701.xml

old.o <- options(stringsAsFactors = FALSE)
xbrl_data17 <- xbrlDoAll(xbrl_url17)
options(old.o)

library(dplyr)

xbrl_data17$element %>% filter(elemntId =="us-gaap_LongTermDebtNoncurrent") %>% left_join(xbrl_data17$fact, by = "elementId") %>% left_join(xbrl_data17$context, by = "contextId") %>% mutate(value = as.numeric(fact) * 10 ^ as.numeric(decimals)) %>% select(elementId, value, unitId, endDate)
Error in filter(elemntId == "us-gaap_LongTermDebtNoncurrent") : object 'elemntId' not found

Can you pls help on this? How can I get this debt number as well as debt breakup as pasted from the footnotes

image

Kind regards,

from finstr.

bergant avatar bergant commented on May 25, 2024

First check the missing e in elemntId (in the filter command...)

from finstr.

Satya2IB avatar Satya2IB commented on May 25, 2024

Thanks for pointing this. Still, I am not very much sure why I am getting an error : "Error in filter_impl(.data, quo) :
Result must have length 20798, not 166384"

Pls see my code below

install.packages("devtools")
devtools::install_github("bergant/finstr")

# Parsing AAPL 10Q ended July 2017 from SEC with XBRL package
library(XBRL)
xbrl_url17q <- "https://www.sec.gov/Archives/edgar/data/320193/000032019317000009/aapl-20170701.xml"

old.o <- options(stringsAsFactors = FALSE)
xbrl_data17 <- xbrlDoAll(xbrl_url17q)
options(old.o)

# after identifying the relevant element ID for long term debt: "us-gaap_LongTermDebtNoncurrent"

xbrl_data17$element %>%
filter(xbrl_data17$element == "us-gaap_LongTermDebtNoncurrent") %>%
left_join(xbrl_data17$fact, by = "elementID") %>%
left_join(xbrl_data17$context, by = "contextID") %>%
mutate(value = as.numeric (fact) * 10 ^ as.numeric(decimals)) %>%
select( elementID, value, unitID, endDate)

This still shows me the error:
Error in filter_impl(.data, quo) :
Result must have length 20798, not 166384

Best,

from finstr.

bergant avatar bergant commented on May 25, 2024

The following code

xbrl_data17$element %>%
  filter(elementId == "us-gaap_LongTermDebtNoncurrent") %>%
  left_join(xbrl_data17$fact, by = "elementId") %>%
  left_join(xbrl_data17$context, by = "contextId") %>%
  mutate(value = as.numeric (fact) * 10 ^ as.numeric(decimals)) %>%
  select( elementId, value, unitId, endDate)

will return only values for the us-gaap_LongTermDebtNoncurrent element:

#>                        elementId value unitId    endDate
#> 1 us-gaap_LongTermDebtNoncurrent 75427    usd 2016-09-24
#> 2 us-gaap_LongTermDebtNoncurrent 89864    usd 2017-07-01

For debt summary table you should find all elements from "http://www.apple.com/role/DebtSummaryOfTermDebtDetails" role,
find their hierarchy and add facts and contexts.

Maybe we can start like this (this will not create a final table):

relations <- 
  finstr::xbrl_get_relations(xbrl_data17, role_id = "http://www.apple.com/role/DebtSummaryOfTermDebtDetails", lbase = "presentation")

elements <-
  data.frame( 
    elementId = with(relations, unique(c(fromElementId, toElementId))),
    stringsAsFactors = FALSE
  )  %>%
  dplyr::left_join(xbrl_data17$element, by = c("elementId")) %>%
  dplyr::left_join(relations, by = c("elementId" = "toElementId")) %>%
  dplyr::left_join(xbrl_data17$label, by = c("elementId")) %>%
  dplyr::filter(labelRole == "http://www.xbrl.org/2003/role/label") %>% 
  dplyr::transmute(elementId, parentId = fromElementId, order, type, balance, labelString)

elements_h <- finstr::get_elements_h(elements)

elements_h %>% 
  filter(type != "nonnum:domainItemType") %>% 
  left_join(xbrl_data17$fact, by = "elementId") %>% 
  left_join(xbrl_data17$context, by = "contextId") %>%
  select(id, elementId, order, labelString, fact, unitId, startDate, endDate, type, contextId) %>% 
  arrange(id)

# ...

from finstr.

joeymizrahi avatar joeymizrahi commented on May 25, 2024

Hi,
I want to extract the Balance Sheet,Cash flow and income statement tables from 10-k and 10-q filings.
can this package help me?

from finstr.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.