ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.81k stars 2.44k forks source link

quarterly_income_stmt is instable in 0.2.6 #1345

Closed RudyNL closed 1 year ago

RudyNL commented 1 year ago

I am trying to download the quarterly income statement. For some stocks I am getting the correct result and for some stocks the data is missing. You can test it by:

>>> import yfinance as yf
>>> yf.Ticker('AALB.AS').quarterly_income_stmt
Empty DataFrame
Columns: []
Index: []

The result is correct for: AAPL, ADS.DE, BION.SW, BN, CLMB, LIN, OCI.AS, WAF.DE and no result is obtained for: AALB.AS, BHP.L, CFR.SW, III.L, SLHN.SW, STLA.PA In all cases the information is available on the Yahoo site.

I can not check if it is a Yahoo problem or a yfinance software problem

0zd3m1r commented 1 year ago

yes it is not stable and i'm getting empty data any ticker (AAPL, MSFT etc.) now.

has been fixed in v0.2.7

RudyNL commented 1 year ago

Its a software problem. The problem is still occurring in version 0.2.9. You can obtain the missing data by using the legacy software instead. Don't use:

>>> msft.quarterly_income_stmt
>>> msft.quarterly_cashflow

But use instead:

>>> msft.get_income_stmt(legacy=True, freq='quarterly')
>>> msft.get_cash_flow(legacy=True, freq='quarterly')

Notice that the key strings are slightly different. Out of 881 stocks, only 705 are giving the correct result. By changing the code the correct result is obtained for 879 stocks. As a result we can conclude that the legacy software is performing significantly better.

ValueRaider commented 1 year ago

"AALB.AS" - Yahoo doesn't display quarterly financials hence the default methods returning empty. You can easily confirm this by visiting finance.yahoo.com. legacy works because Yahoo has hidden data that yfinance can extract.

But issues with the major US tickers like "AAPL" are different and shouldn't be happening. Are you running in a loop of many tickers? Spam can trigger data problems.

RudyNL commented 1 year ago

All data of "AALB.AS" can be found on the Yahoo site. Its rather unstable. At some times of the day of many mainly European stocks the financial data are (partly) missing. I just checked the site, for "AALB.AS" all three sets Income Statement, Balance Sheet and Cash Flow are available in Annual and Yearly mode.

ValueRaider commented 1 year ago

@RudyNL I specified quarterly.

RudyNL commented 1 year ago

@ValueRaider I mean Quarterly

ValueRaider commented 1 year ago

@RudyNL You wrote "Annual and Yearly mode". Can you upload a screenshot of Yahoo displaying complete quarterly financials?

RudyNL commented 1 year ago

Screenshot at 2023-01-28 16-28-12

ValueRaider commented 1 year ago

TTM = trailing twelve months. Not quarterly although it does appear in that table. If TTM is what you wanted please update title.

TTM is easy to implement, just need to add "trailing" timescale in yfinance alongside "annual" and "quarterly" (a developer will understand this). I'll leave for someone else to do.

RudyNL commented 1 year ago

What might this be?

>>> yf.Ticker('AALB.AS').get_income_stmt(legacy=True, freq='quarterly')
                                  2022-06-30 2022-03-31 2021-12-31 2021-09-30
ResearchDevelopment                     None       None       None       None
EffectOfAccountingCharges               None       None       None       None
IncomeBeforeTax                    108000000  108000000  148300000  148300000
MinorityInterest                    43400000   43400000   40000000   40000000
NetIncome                           80050000   80050000  107050000  107050000
SellingGeneralAdministrative       224000000  224000000  202900000  202900000
GrossProfit                        507000000  507000000  453600000  453600000
Ebit                               112000000  112000000   77500000   77500000
OperatingIncome                    112000000  112000000   77500000   77500000
OtherOperatingExpenses             124550000  124550000  122450000  122450000
InterestExpense                     -4000000   -4000000   -3400000   -3400000
ExtraordinaryItems                      None       None       None       None
NonRecurring                            None       None       None       None
OtherItems                              None       None       None       None
IncomeTaxExpense                    26150000   26150000   39450000   39450000
TotalRevenue                       807350000  807350000  734150000  734150000
TotalOperatingExpenses             695350000  695350000  656650000  656650000
CostOfRevenue                      300350000  300350000  280550000  280550000
TotalOtherIncomeExpenseNet          -4000000   -4000000   70800000   70800000
DiscontinuedOperations                  None       None       None       None
NetIncomeFromContinuingOps          81850000   81850000  108850000  108850000
NetIncomeApplicableToCommonShares   80050000   80050000  107050000  107050000

The next page is the Quarterly Balance Sheet

Screenshot at 2023-01-28 18-34-42 And the information can be retrieved

>>> yf.Ticker('AALB.AS').get_balance_sheet(legacy=True, freq='quarterly')
                                           2022-06-30    2022-03-31    2021-12-31    2021-09-30
IntangibleAssets                         1.497900e+09  1.497900e+09  4.960000e+08  4.960000e+08
CapitalSurplus                           2.008000e+08  2.008000e+08  2.008000e+08  2.008000e+08
TotalLiab                                2.078000e+09  2.078000e+09  1.471600e+09  1.471600e+09
TotalStockholderEquity                   2.171600e+09  2.171600e+09  2.143700e+09  2.143700e+09
MinorityInterest                         4.340000e+07  4.340000e+07  4.000000e+07  4.000000e+07
OtherCurrentLiab                         4.590000e+08  4.590000e+08  1.964000e+08  1.964000e+08
TotalAssets                              4.293000e+09  4.293000e+09  3.655300e+09  3.655300e+09
CommonStock                              2.760000e+07  2.760000e+07  2.760000e+07  2.760000e+07
OtherCurrentAssets                       8.500000e+07  8.500000e+07  3.030000e+07  3.030000e+07
RetainedEarnings                         1.916500e+09  1.916500e+09  1.945300e+09  1.945300e+09
OtherLiab                                2.259000e+08  2.259000e+08  1.968000e+08  1.968000e+08
GainsLossesNotAffectingRetainedEarnings  2.670000e+07  2.670000e+07 -3.000000e+07 -3.000000e+07
OtherAssets                              2.420000e+07  2.420000e+07  2.670000e+07  2.670000e+07
Cash                                     2.549000e+08  2.549000e+08  7.200000e+07  7.200000e+07
TotalCurrentLiabilities                  1.196700e+09  1.196700e+09  9.461000e+08  9.461000e+08
DeferredLongTermAssetCharges             1.740000e+07  1.740000e+07  1.940000e+07  1.940000e+07
ShortLongTermDebt                        7.520000e+07  7.520000e+07  1.007000e+08  1.007000e+08
OtherStockholderEquity                   2.670000e+07  2.670000e+07 -3.000000e+07 -3.000000e+07
PropertyPlantEquipment                   1.109000e+09  1.109000e+09  1.055900e+09  1.055900e+09
TotalCurrentAssets                       1.661900e+09  1.661900e+09  1.195400e+09  1.195400e+09
NetTangibleAssets                        6.737000e+08  6.737000e+08  7.664000e+08  7.664000e+08
NetReceivables                           4.657000e+08  4.657000e+08  3.824000e+08  3.824000e+08
LongTermDebt                             5.108000e+08  5.108000e+08  1.789000e+08  1.789000e+08
Inventory                                8.563000e+08  8.563000e+08  6.884000e+08  6.884000e+08
AccountsPayable                          4.864000e+08  4.864000e+08  3.416000e+08  3.416000e+08
GoodWill                                          NaN           NaN  8.813000e+08  8.813000e+08

So the information is available and there are quarterly columns. I am not understanding the differences between the information from the website and the information obtained in Python. There are differences in the number of columns presented. At this moment I do have a work around using legacy=True.

ValueRaider commented 1 year ago

What might this be?

The hidden data that I already explained here

The next page is the Quarterly Balance Sheet ... And the information can be retrieved

yf.Ticker('AALB.AS').quarterly_balance_sheet

I am not understanding the differences between the information from the website and the information obtained in Python

Nor do we.

ValueRaider commented 1 year ago

Further discussion pointless because the "legacy" financials (aka "hidden") not retrievable anymore.