theOGognf / finagg

A Python package for aggregating and normalizing historical data from popular and free financial APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

financial statements do not match

jegauth opened this issue · comments

Hello theOGognf! I have a little question for you. When I go on quickfs.net or Seeking Alpha I got these result for the gross profit for AAPL:

image

When I use your code

df = finagg.sec.api.company_facts.get(ticker="AAPL")  # get all data associated with AAPL
df = finagg.sec.api.get_unique_filings(df, form="10-K")  # get all unique annual filings
df = finagg.sec.api.join_filings(df, form="10-K")  # pivot the table for convenience

I got this result

image

Just one example, look at the gross profit in FY 2023, i.e. 1.5283e+11, and look where it is located in the spreadsheet. The same result is located in year 2021. So it is delayed by almost 2 years. Is it normal? There might be an issue somewhere. Can you look at it

@jegauth This is a good issue. I did some digging; this is a bug from my misunderstanding of the usage of the "start", "end", "filed", "fy", "fp", and "frame" columns.

I assumed "fy" corresponded to the fiscal year that a filing was for, but it is in fact the fiscal year that the filing was submitted (the data could be for a prior fiscal year, and, in Apple's case, they seem to resubmit filings each year for filings 2 years prior pretty consistently). It seems "filed", "fp", and "frame" all follow the same convention (and in "frame"'s case, is NaN a good bit of the time).

This makes it a bit tricky, because now I must find a new method to determine which fiscal period/frame a filing is actually for instead of relying on the provided columns. This isn't hard to do, but just requires some extra work to guarantee I'm not including data from other quarters or years, since it seems like not all filings are cleanly separated by quarters/years

Thanks for submitting this issue. I probably won't have a lot of time this weekend to work on a solution, but I will work on this when I get a chance. A conservative estimate for an implemented fix from me is probably ~4wks from now

To be honest, you are not that far from delivering a very good repo!! It saved me a lot of time. Can I pay you something so that you can fix it up sooner? I will also try to fix it up

To be honest, you are not that far from delivering a very good repo!! It saved me a lot of time. Can I pay you something so that you can fix it up sooner? I will also try to fix it up

Haha no, that's alright. You're more than welcome to try to fix it yourself - I'll happily review your PR

You just need to update the finagg.sec.api.get_unique_filings and finagg.sec.api.join_filings methods to use the "start" and "end" columns to separate filings by their correct quarters instead of using the given "fy" and "fp" columns. There should be a filing with a "filed" column that's 30-90days after the "end" date for the first filing of each year/quarter, which should be a good thing to validate against. We probably also want to keep the same indexing convention (using "fy", "fp", and "filed" for indices, but overwriting "fy" and "fp" with the correct year and quarter, respectively)

image

We can see that the error might be located here: df = finagg.sec.api.company_facts.get(ticker="AAPL")

I am working on it

image
Can you see the error?

It seems to be fixed.

Here is my output:
image

Here is the output from Seeking Alpha:
image

Here is the part I fixed:
image

You can add those two lines in sec.api. Hope it helps!

Hey @jegauth ! Thanks again for finding this issue, reporting it, and getting a first-pass solution out for it. This really helped narrow down the issue and made it significantly quicker for me to put out a bugfix

I pushed an update to the main branch. If you can clone it and test it out, it should be more aligned to what we're expecting

Hello @theOGognf! It seems we have the same issue again. Check it out because I have the same issue as before

Hello @theOGognf! It seems we have the same issue again. Check it out because I have the same issue as before

Are you sure? Did you pull and reinstall like:

git pull
pip install .

Yes, I did. I am pretty sure it is not working as expected.

df = finagg.sec.api.company_facts.get(ticker="AAPL")  # get all data associated with AAPL
df = finagg.sec.api.get_unique_filings(df, form="10-K")  # get all unique annual filings
df = finagg.sec.api.join_filings(df, form="10-K")  # pivot the table for convenience

This code does not work as expected.

I can't seem to replicate the issue anymore while on the latest main branch on GitHub. Closing for now. Feel free to reopen an issue if you're unable to get the latest fix for it