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

balance_sheet ignoring 'trailing=True' (while cash_flow and income_statement do take it into account). #150

Open
galashour opened this issue Feb 20, 2023 · 7 comments · May be fixed by #161
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@galashour
Copy link

Describe the bug
I assume this is a bug rather than a feature request.

It seems that while when adding 'trailing=True' for cash_flow and income_statement at the TTM row, for balance_sheet it pretty much seems to ignore it (and the alternative is to have 2 calls, the second one being balance_sheet with frequency='q' in order to calculate manually the TTM line.
Not sure if this is a bug (ignoring the 'trailing=True') or a feature request, but I think it would be good (if not too hard) to make it consistent with the other reports and 'save' the need for the manual calculation after issuing a second call for the quarterly data.

yq = Ticker(ticker)
yq_cashflow = yq.cash_flow(trailing=True)
yq_income = yq.income_statement(trailing=True)
yq_balance = yq.balance_sheet(trailing=True)

Desktop (please complete the following information):
I used Windws11, Python 3.8, yahooquery.version = 2.2.15

@dpguthrie
Copy link
Owner

Thanks for raising this. This is a bug in the sense that trailing shouldn't be accepted as an argument for balance_sheet - there's no meaning for a trailing twelve month (TTM) number for a balance sheet as it's simply a point-in-time reference. Take a look at YF for some examples:

image

@dpguthrie
Copy link
Owner

The fix (I think) should be something like this:

def balance_sheet(self, frequency='a'):
    return self._financials('balance_sheet', frequency)

@dpguthrie dpguthrie added bug Something isn't working good first issue Good for newcomers labels Feb 20, 2023
@galashour
Copy link
Author

galashour commented Feb 20, 2023

Absolutely agree.
In fact I indeed verified in my code that I was just extracting the relevant value from the last quarter and append it to the data I get from the annual balance sheet (to visualize longerterm trend but including the most recent value in case the last annual one is 'older' than the recent quarter).

Thanks !

@kushalnl7
Copy link

Hi, I am interested to do this. Can I try this?

@galashour
Copy link
Author

galashour commented Feb 21, 2023

Hi, I am interested to do this. Can I try this?

Please clarify the question (was not sure who the question is aimed at, and what you want to try).

If the question was for me, and you wanted to look at the trend of a specific 'aspect/attribute', you can do it already like the below which will create a dict for the specific attribute and later you can visualize as applicable.

    yq = Ticker(ticker)
    
    yq_balance = yq.balance_sheet()
    yq_balance.reset_index(level=[0], inplace=True)
    yq_balance_q = yq.balance_sheet(frequency='q')
    yq_balance_q.reset_index(level=[0], inplace=True)
    
    # total_liabilities trend data
    data_field = 'TotalLiabilitiesNetMinorityInterest'
    yq_data_df = yq_balance[['asOfDate', data_field]]
    yq_data_df.rename(columns={'asOfDate': 'date', data_field: 'yq_data'}, inplace=True)
    yq_data_df['date'] = yq_data_df['date'].dt.strftime('%Y-%m-%d')
    yq_data_df.set_index('date', inplace=True)
    last_date = yq_data_df.index[-1]
    trend_data = yq_data_df.to_dict()['yq_data']

For attributes that are not in the balance_sheet, it is even slightly easier, since you don't need the quarterly report and you can just add the 'trailing=True' as parameter for the annual report to get also the data for the most recent 12 months.

The original thread here was just to raise the question whether 'trailing=True' should be reported as a warning, or instead be allowed, resulting with a row from the most recent quarter added (i.e., mrq instead of TTM, in the case mrq is not included in the last raw of the annual report).

@dpguthrie
Copy link
Owner

dpguthrie commented Feb 21, 2023

@kushalnl7 It's all yours! And, just to be clear, the fix is really just removing the trailing argument from the method as it doesn't actually do anything.

@galashour
Copy link
Author

btw, not sure if to open a different issue (not a real issue for me, but could be helpful to others):

when doing
pip install yahooquery

It still stays on 2.2.15

In order to update to 2.3.0, I did the following:
pip install yahooquery --upgrade --no-cache-dir

Maybe it would be good to edit the 'installation' section in
https://yahooquery.dpguthrie.com/

@kushalnl7 kushalnl7 linked a pull request Mar 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants