JECSand / yahoofinancials

A powerful financial data module used for pulling data from Yahoo Finance. This module can pull fundamental and technical data for stocks, indexes, currencies, cryptos, ETFs, Mutual Funds, U.S. Treasuries, and commodity futures.
https://pypi.python.org/pypi/yahoofinancials
MIT License
916 stars 220 forks source link

Cash Flow statement : capitalExpenditures get from API is different from the yahoo finance website #68

Open jimmylai-hk opened 4 years ago

jimmylai-hk commented 4 years ago

Hi

I'm using the following code to get capitalExpenditures data from cash flow statement for symbol 'VZ',

Below is the code that I'm using.

from yahoofinancials import YahooFinancials

ticker = 'VZ' yahoo_financials = YahooFinancials(ticker) balance_sheet_data = yahoo_financials.get_financial_stmts('annual', 'balance') income_statement_data = yahoo_financials.get_financial_stmts('annual', 'income') cash_flow_data = yahoo_financials.get_financial_stmts('annual', 'cash')

Below is the cash_flow_data and notice that the capitalExpenditures is -17939000000. However, the data shown in the link https://finance.yahoo.com/quote/VZ/cash-flow?p=VZ for Capital Expenditure is -18,837,000 which is DIFFERENT. ANY clues?

{'cashflowStatementHistory': {'VZ': [{'2019-12-31': {'changeToLiabilities': -2359000000, 'totalCashflowsFromInvestingActivities': -17581000000, 'netBorrowings': -5231000000, 'totalCashFromFinancingActivities': -18164000000, 'changeToOperatingActivities': -2807000000, 'netIncome': 19265000000, 'changeInCash': 1000000, 'totalCashFromOperatingActivities': 35746000000, 'depreciation': 16682000000, 'otherCashflowsFromInvestingActivities': 1257000000, 'dividendsPaid': -10016000000, 'changeToInventory': -76000000, 'changeToAccountReceivables': -1471000000, 'otherCashflowsFromFinancingActivities': -2917000000, 'changeToNetincome': 6512000000, 'capitalExpenditures': -17939000000}},

juanpatriciopdlc commented 4 years ago

When you check on the source code of the yahoo Finance, page, you can see there are two different variables:

"annualCapitalExpenditure":[{"dataId":26005,"asOfDate":"2016-12-31","periodType":"12M","currencyCode":"USD","reportedValue":{"raw":-17593000000,"fmt":"-17.59B"}},{"dataId":26005,"asOfDate":"2017-12-31","periodType":"12M","currencyCode":"USD","reportedValue":{"raw":-17830000000,"fmt":"-17.83B"}},{"dataId":26005,"asOfDate":"2018-12-31","periodType":"12M","currencyCode":"USD","reportedValue":{"raw":-18087000000,"fmt":"-18.09B"}},{"dataId":26005,"asOfDate":"2019-12-31","periodType":"12M","currencyCode":"USD","reportedValue":{"raw":-18837000000,"fmt":"-18.84B"}}]

"capitalExpenditures":{"raw":-17939000000,"fmt":"-17.94B","longFmt":"-17,939,000,000"}}

It seems that the API is feeding from the later (capitalExpenditures), which is not shown on the page, instead of the "annualCapitalExpenditure" variable.

I am also having some kidn of problem regarding this aspect but I don't know how can I set the variables I want the YahooFinancials API to scrape from the source code. Any idea how to solve this?

juanpatriciopdlc commented 4 years ago

I have gone deeper in the code, and it seems that the code scrapes the information from the following dictionary:

Line 162 stores = data["context"]["dispatcher"]["stores"]["QuoteSummaryStore"]

While the information you are looking for is the subdictionary

-context/dispatcher/stores/QuoteTimeSeriesStore

I think I wil add both dictionaries in the same return so I can get both information (QuoteSummaryStore and QuoteTimeSeriesStore), that are complementory. If I manage it to work I wil llet you know