edgartools icon indicating copy to clipboard operation
edgartools copied to clipboard

Cash flow statement problems

Open 25fin opened this issue 1 year ago • 14 comments

Hi!

Thanks for this wonderful library.

There's only one issue with Cash flow statements - some numbers are incorrectly multiplied by (-1), example: instead of 50, I get -50. I noticed it with many companies; it usually happens in Operating cash flow.

Example with the latest CRSR Cash flow statement: https://www.sec.gov/cgi-bin/viewer?action=view&cik=1743759&accession_number=0000950170-25-027856&xbrl_type=v#

Data on Edgar website:

Other 5,661 4,263 4,867
Changes in operating assets and liabilities:      
Accounts receivable 32,285 (17,686) 55,845
Inventories 18,315 (39,470) 111,288
Prepaid expenses and other assets 5,897 1,902 1,268

Data from the library:

Other | -5661000 | -4263000 | -4867000 | us-gaap_OtherNoncashIncomeExpense

Accounts receivable -32285000 -17686000 -55845000 us-gaap_IncreaseDecreaseInAccountsReceivable
-18315000 -39470000 -111288000 us-gaap_IncreaseDecreaseInInventories
-5897000 -1902000 -1268000 us-gaap_IncreaseDecreaseInPrepaidDeferredExpenseAndOtherAssets

25fin avatar Mar 03 '25 16:03 25fin

Thanks for this.

I am actually in the process of rewriting the XBRL functionality (again), hopefully to complete by this weekend.

I will add this to my test case

dgunning avatar Mar 04 '25 03:03 dgunning

Thank you for such a fast response!

If I may add a suggestion:

Cash flow statements are flat and are easy to test. At least I haven't met a layered CF statement yet.

To check if the numbers are correct, a user needs to locate the following 3 us-gaap:

  • us-gaap_NetCashProvidedByUsedInOperatingActivities
  • us-gaap_NetCashProvidedByUsedInInvestingActivities
  • us-gaap_NetCashProvidedByUsedInFinancingActivities

The next 2 also could be everywhere but I don't like the word "restricted", some companies could potentially work without including restricted cash: us-gaap_EffectOfExchangeRateOnCashCashEquivalentsRestrictedCashAndRestrictedCashEquivalents us-gaap_CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalentsPeriodIncreaseDecreaseIncludingExchangeRateEffect

For example:

Index; gaap

0; ... 1; ... 15; us-gaap_NetCashProvidedByUsedInOperatingActivities

A user needs to check that [0]+[1]+..+[14] = [15]

16;... 21; us-gaap_NetCashProvidedByUsedInInvestingActivities

Check that [16]+[17]+...+[20] = [21]

22; ... 30; us-gaap_NetCashProvidedByUsedInFinancingActivities

Check that [22]+[23]+...+[29] = [30]

31; us-gaap_EffectOfExchangeRateOnCashCashEquivalentsRestrictedCashAndRestrictedCashEquivalents 33; us-gaap_CashCashEquivalentsRestrictedCashAndRestrictedCashEquivalentsPeriodIncreaseDecreaseIncludingExchangeRateEffect

Check that [15]+[21]+[30]+[31] = [33]

As for the whole XBRL functionality, Balance sheet and Income statement work perfectly right now for every company that I've tested.

Maybe the current results from these statements could work as test cases for the new functionality, so that it doesn't break what's working perfectly.

Not many companies even with paid data are able to have the same level of accuracy with Income statement and Balance sheet as your library has. An awesome achievement!

25fin avatar Mar 04 '25 10:03 25fin

These numbers are also negative in the early version of the rewrite which is interesting since the new code is completely new AI generated. So .. we are missing some logic somewhere -5661000 | -4263000 | -4867000

dgunning avatar Mar 04 '25 15:03 dgunning

Hi Dwight,

I faced this problem with company SCCO in which some income statement numbers are represented as negative while some are represented in positive despite it being different in the actual filing. Please find attached the cost of sales numbers for various historical periods. I think this went unnoticed before.

Cost of Sales SCCO.xlsx

mithunthakkar8 avatar Mar 19 '25 12:03 mithunthakkar8

I found the issue .. below is my dialogue with Claude Code


⏺ Based on my comprehensive analysis of the XBRL2 codebase, I can provide you with a detailed assessment regarding how calculation arc weights (particularly negative weights) are handled:

Current Implementation Status

  1. Calculation Arc Weight Extraction: The code correctly extracts weight values from calculation arcs in parser.py, including the negative values like -1.00 in your example for IncreaseDecreaseInInventories.
  2. Data Model Storage: These weights are stored in the CalculationNode objects with a weight property (default 1.0). Each calculation node represents an element involved in calculations.
  3. Missing Value Sign Adjustment: Despite extracting and storing this information, the code does not currently apply these weights to adjust fact values. There is no mechanism that flips the sign of values based on negative weights.

XBRL Specification Considerations

According to the XBRL specification:

  1. Calculation arcs with negative weights (-1.0) indicate that the child element should contribute negatively to its parent in calculations.
  2. For elements like IncreaseDecreaseInInventories, the negative weight indicates that increases in inventory (which reduce cash) should be subtracted when calculating a parent total.
  3. The raw fact values in XBRL should reflect their business meaning rather than presentation format. The calculation linkbase provides information on how these values should be combined.

Considerations for Implementation

  1. Contextual Application: The calculation weights should apply in the context of a specific role/statement, as the same concept might be used differently in different statements.
  2. Balance Types: Consider interaction with balance types (debit/credit). An element with a "debit" balance type that appears in a "credit" context might already have its sign flipped.
  3. Consistency: Ensure consistent handling across all interfaces (display, dataframes, calculations).
  4. Edge Cases: Handle edge cases like elements that appear in multiple calculation trees with different weights.

I recommend incorporating the calculation weights into your fact processing logic to ensure XBRL values are represented according to the specification, which would allow proper statement calculation validation and accurate presentation

dgunning avatar Mar 19 '25 16:03 dgunning

Dwight, Thank you for your response. Can you please explain in simple words about the text you pasted from claude above.

mithunthakkar8 avatar Mar 19 '25 17:03 mithunthakkar8

The value for Inventories in the XBRL instance xml is -1815 but the weight in the XBRL calculation xml is -1.0.

The code was not multiplying by -1.0.

This now fixed and being tested.

dgunning avatar Mar 19 '25 18:03 dgunning

This addressed in 3.13.5 which has just been released.

CRSR Cashflow

Image

See Google Colab notebook

Cash Flow Statements

dgunning avatar Mar 19 '25 19:03 dgunning

but then Dwight, my question is regarding the income statement. I saw positive and negative signs to be incorrectly present in income statement. Check attached Cost of sales data which has some negatives and some positives in various periods for the ticker 'SCCO'. In the attached file, the first column is for period of report.

Cost of Sales SCCO.xlsx

mithunthakkar8 avatar Mar 20 '25 02:03 mithunthakkar8

This addressed in 3.13.5 which has just been released.

CRSR Cashflow

Image

See Google Colab notebook

Cash Flow Statements

Interesting. I updated the library. Checked that it's the latest version: Image

But the problem is still there:

Image

25fin avatar Mar 20 '25 13:03 25fin

@25fin That looks like the old xbrl, not xbrl2. Can you show me the code?

dgunning avatar Mar 20 '25 18:03 dgunning

@dgunning

It shows in both ways:

tenk = Company("CRSR").get_filings(form="10-K").latest(1).obj()

financials = tenk.financials

financials.get_cash_flow_statement()

c = Company("CRSR")

filing = c.get_filings(form="10-K")

def find_partial_match(arr, search_string): try: return next(i for i, s in enumerate(arr) if search_string in s) except StopIteration: return -1 # Return -1 if no match is found

tenq = filing[0].xbrl()

statement = 'CashFlow' statement_list = tenq.list_statement_definitions()

ind = find_partial_match(statement_list, statement) if ind == -1: ind = find_partial_match(statement_list, statement.upper())

arr = tenq.get_statement(statement_list[ind])

arr.get_dataframe()

25fin avatar Mar 20 '25 18:03 25fin

I understand. That code which is broken is unchanged.

I am working on a rewrite which once stable will be used as the main api. Here is what that code looks like

c = Company("CRSR")
filing = c.latest("10-K")
xbrl = XBRL.from_filing(filing)

statement = xbrl.statements.cash_flow_statement()
statement

https://github.com/dgunning/edgartools/blob/main/notebooks/XBRL2-Cashflow-Statements.ipynb

dgunning avatar Mar 20 '25 19:03 dgunning

This is fixed in Release 4.0.0

dgunning avatar May 18 '25 19:05 dgunning