Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced the detail of the annual financial statements and added ability to check the "Analysis" url. #776

Merged
merged 15 commits into from
Oct 17, 2022

Conversation

git-shogg
Copy link
Contributor

Hi ranaroussi,

First and foremost, thanks for developing such an awesome tool! Given that I use this a fair bit for my own discounted cash flow analyses I figured I may as well contribute some of the enhancements that I believe will add a lot of value to end users.

There are two main changes that I have made which are accompanied by a bunch of smaller changes.

  1. Currently the annual financial data does not always reflect what is shown in Yahoo Finance (for example if you look at the income statement of AAPL on yahoo finance you'll notice that there is an "interest income" line item that is not reflected in the the current resultant dataframe from yfinance 0.1.60) . This is because Yahoo Finance uses the "FinancialTemplateStore" to structure their annual financial statement data. I have updated the annual financial statements to use this template store as a guide to build them dynamically in the correct order with the correct level that the line item falls under (e.g. Total Revenue is made up of Operating Revenue and Excise Taxes, hence Total Revenue is level 0 while Operating Revenue and Excise Taxes are both level 1). This will be extremely useful to end users who can now build more accurate financial models. Unfortunately I have been unable to replicate this for quarterly statements as they do not seem to use any template store, so this has been left more or less the same with some minor naming changes.
  2. I have also added some functionality to pull data from the "Analysis" url. Added features include: analyst trend details (buy, sell, hold), share price targets forecast by analysts along with count of analysts, forecast revenue estimates and forecast eps estimates.

I hope that these changes can flow through to yfinance as I am really keen to see these in there.

Cheers,
Hoggie

@asafravid
Copy link
Collaborator

Looks like a good improvement, is it most-updated in your fork? I'd like to examine it

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jul 29, 2022

I've figured out how to get accurate quarterly data. The secret is this url e.g.

https://query2.finance.yahoo.com/ws/fundamentals-timeseries/v1/finance/timeseries/JPM?symbol=JPM&type=quarterlyBasicEPS&period1=493590046&period2=1659095385

Problem is I don't have time to polish into a full nice feature, so I'm hoping someone can take my prototype code and finish it: https://github.com/yfinance-fork-team/yfinance-x/blob/a41aba54e8a5d0c56b928af39baffb1a221a2210/yfinance/base.py#L518-L568

Can also use url to get years of 'shares outstanding' data.

@ValueRaider
Copy link
Collaborator

@git-shogg I've got good news and bad news.

Good news - fixing the quarterlys will be super easy.

Bad news - your annual tables are still missing some rows.

If you grab branch fix/financials-data and turn on _DEV at top of base.py, it will print out what is missing. It uses that alternative url I mentioned above - has more rows, but cannot be used to created TTM or MultiIndex.

@asafravid
Copy link
Collaborator

@ValueRaider Kudos for the debug methodology (using _DEV)

@git-shogg
Copy link
Contributor Author

@ValueRaider, thanks for putting together that _DEV test. I've identified the root cause of the missing data but haven't yet remediated. Would it be possible to directly commit to the fix branch?

@ValueRaider
Copy link
Collaborator

Unless you plan on reviewing/contributing other bugs/features* then it's easiest for everyone to stick to the fork->PR model.

  • But if you do want to contribute more to project then access can be granted eventually. Do you have evidence of prior OSS collaborative experience? If not then can still grant limited access but first need to move yfinance into an 'organisation', will take time (only Ran can do).

@git-shogg
Copy link
Contributor Author

git-shogg commented Oct 15, 2022

Hi team, I have updated my PR to include the fix on the missing annual table line items (commit [6c4da51]). Note that the annual income statement will still be flagged as an issue (by the _DEV test developed by @ValueRaider). This because the script is looking for "EBITDA" but the camel case function is converting to "Ebitda". Keen to get this merged to main! Let me know how you go!

@ValueRaider
Copy link
Collaborator

ValueRaider commented Oct 15, 2022

Can you refactor code in base.py, there's a lot of duplication.

And fix the quarterlies? I showed how to get the data, you just need to copy in the MultiIndex.

Is having a MultiIndex actually useful? I don't use financials much so honestly don't know.

Those branch conflicts need to be resolved before merging.

@git-shogg
Copy link
Contributor Author

Hi team, I had some spare time today so I have:

  1. Refactored the code.
  2. Fixed the quarterlies (with the help of the function called out by @ValueRaider, thanks for that!).

The above fixes can be found in commit d65391b.

In response to your question regarding the multi-index. This multi-index is super useful for parsing data into discounted cash flow analyses which are used heavily in the finance industry for valuing companies. Without the multi-index there would be onus on the yfinance users to completely understand the make-up of each and every possible parent -> child relationship of the income statement, balance sheet and cash flow statement (e.g. Current Assets include Cash and Cash Equivalents). With the multi-indexing this can be simplified for our end users as they can use this index to automatically identify parent -> child relationships in any of the financial statements.

@ValueRaider
Copy link
Collaborator

With the refactor I was hoping you'd move the bulk of logic into a function, or at least a loop, and loop over 'cashflow', 'balance sheet', 'income'. To minimise size of _get_fundamentals(). Also you have a big block of commented code at bottom.

You can remove the _DEV code, that was just for you.

@git-shogg
Copy link
Contributor Author

Hi @ValueRaider I have made the recommended changes in the latest commit (3b18114c).

@ValueRaider ValueRaider merged commit 68b8671 into ranaroussi:fix/financials-data Oct 17, 2022
@ValueRaider
Copy link
Collaborator

@git-shogg I've merged into the dev branch. Will test it for a few days before sending out release. Helps if you can test too, just use it instead of PIP.

Once release goes out probably many users will get confused by MultiIndex, can you keep eye on Issues to help them?

@git-shogg
Copy link
Contributor Author

Sure, happy to do some more testing and will keep an eye on issues. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants