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.
Install / Use
/learn @JECSand/YahoofinancialsREADME
=============== yahoofinancials
A python module that returns stock, cryptocurrency, forex, mutual fund, commodity futures, ETF, and US Treasury financial data from Yahoo Finance.
.. image:: https://github.com/JECSand/yahoofinancials/actions/workflows/test.yml/badge.svg?branch=master :target: https://github.com/JECSand/yahoofinancials/actions/workflows/test.yml
.. image:: https://static.pepy.tech/badge/yahoofinancials :target: https://pepy.tech/project/yahoofinancials
.. image:: https://static.pepy.tech/badge/yahoofinancials/month :target: https://pepy.tech/project/yahoofinancials
.. image:: https://static.pepy.tech/badge/yahoofinancials/week :target: https://pepy.tech/project/yahoofinancials
Current Version: v1.20
Version Released: 12/17/2023
Report any bugs by opening an issue here: https://github.com/JECSand/yahoofinancials/issues
Overview
A powerful financial data module used for pulling both fundamental and technical data from Yahoo Finance.
-
New analytic methods in v1.20:
- get_insights()
- returns data for:
- 'instrumentInfo'
- 'companySnapshot'
- 'recommendation'
- 'sigDevs'
- 'secReports'
- returns data for:
- get_recommendations()
- get_insights()
-
Example:
.. code-block:: python
print(YahooFinancials('C').get_recommendations())
- Example Output:
.. code-block:: javascript
{
"C": [
{
"recommendedSymbols": [
{
"score": 0.239602,
"symbol": "BAC"
},
{
"score": 0.225134,
"symbol": "JPM"
},
{
"score": 0.167669,
"symbol": "WFC"
},
{
"score": 0.145864,
"symbol": "GS"
},
{
"score": 0.134071,
"symbol": "F"
}
],
"symbol": "C"
}
]
}
-
As of Version 1.20, YahooFinancials supports a new optional parameter called flat_format.
- When
YahooFinancials(flat_format=True), financial statement data will return in a dict instead of a list. The keys of the dict will be the reporting dates. - Default is False, to ensure backwards compatibility.
- When
-
As of Version 1.9, YahooFinancials supports optional parameters for asynchronous execution, proxies, and international requests.
.. code-block:: python
from yahoofinancials import YahooFinancials
tickers = ['AAPL', 'GOOG', 'C']
yahoo_financials = YahooFinancials(tickers, concurrent=True, max_workers=8, country="US")
balance_sheet_data_qt = yahoo_financials.get_financial_stmts('quarterly', 'balance')
print(balance_sheet_data_qt)
proxy_addresses = [ "mysuperproxy.com:5000", "mysuperproxy.com:5001"]
yahoo_financials = YahooFinancials(tickers, concurrent=True, proxies=proxy_addresses)
balance_sheet_data_qt = yahoo_financials.get_financial_stmts('quarterly', 'balance')
print(balance_sheet_data_qt)
Installation
- yahoofinancials runs on Python 3.7, 3.8, 3.9, 3.10, 3.11, and 3.12
- Installation using pip:
- Linux/Mac:
.. code-block:: bash
$ pip install yahoofinancials
- Windows (If python doesn't work for you in cmd, try running the following command with just py):
.. code-block::
> python -m pip install yahoofinancials
2. Installation using github (Mac/Linux):
.. code-block:: bash
$ git clone https://github.com/JECSand/yahoofinancials.git
$ cd yahoofinancials
$ python setup.py install
3. Demo using the included demo script:
.. code-block:: bash
$ cd yahoofinancials
$ python demo.py -h
$ python demo.py
$ python demo.py WFC C BAC
4. Test using the included unit testing script:
.. code-block:: bash
$ cd yahoofinancials
$ python test/test_yahoofinancials.py
Module Methods
- The financial data from all methods is returned as JSON.
- You can run multiple symbols at once using an inputted array or run an individual symbol using an inputted string.
- YahooFinancials works with Python 3.7, 3.8, 3.9, 3.10, 3.11 and 3.12 and runs on all operating systems. (Windows, Mac, Linux).
Featured Methods ^^^^^^^^^^^^^^^^
-
get_financial_stmts(frequency, statement_type, reformat=True)
- frequency can be either 'annual' or 'quarterly'.
- statement_type can be 'income', 'balance', 'cash' or a list of several.
- reformat optional value defaulted to true. Enter False for unprocessed raw data from Yahoo Finance.
-
get_stock_price_data(reformat=True)
-
get_stock_earnings_data()
- reformat optional value defaulted to true. Enter False for unprocessed raw data from Yahoo Finance.
-
get_summary_data(reformat=True)
- Returns financial summary data for cryptocurrencies, stocks, currencies, ETFs, mutual funds, U.S. Treasuries, commodity futures, and indexes.
- reformat optional value defaulted to true. Enter False for unprocessed raw data from Yahoo Finance.
-
get_stock_quote_type_data()
-
get_historical_price_data(start_date, end_date, time_interval)
- This method will pull historical pricing data for stocks, currencies, ETFs, mutual funds, U.S. Treasuries, cryptocurrencies, commodities, and indexes.
- start_date should be entered in the 'YYYY-MM-DD' format and is the first day that data will be pulled for.
- end_date should be entered in the 'YYYY-MM-DD' format and is the last day that data will be pulled for.
- time_interval can be either 'daily', 'weekly', or 'monthly'. This variable determines the time period interval for your pull.
- Data response includes relevant pricing event data such as dividends and stock splits.
-
get_num_shares_outstanding(price_type='current')
- price_type can also be set to 'average' to calculate the shares outstanding with the daily average price.
Additional Module Methods ^^^^^^^^^^^^^^^^^^^^^^^^^
- get_daily_dividend_data(start_date, end_date)
- get_stock_profile_data()
- get_financial_data()
- get_interest_expense()
- get_operating_income()
- get_total_operating_expense()
- get_total_revenue()
- get_cost_of_revenue()
- get_income_before_tax()
- get_income_tax_expense()
- get_esg_score_data()
- get_gross_profit()
- get_net_income_from_continuing_ops()
- get_research_and_development()
- get_current_price()
- get_current_change()
- get_current_percent_change()
- get_current_volume()
- get_prev_close_price()
- get_open_price()
- get_ten_day_avg_daily_volume()
- get_stock_exchange()
- get_market_cap()
- get_daily_low()
- get_daily_high()
- get_currency()
- get_yearly_high()
- get_yearly_low()
- get_dividend_yield()
- get_annual_avg_div_yield()
- get_five_yr_avg_div_yield()
- get_dividend_rate()
- get_annual_avg_div_rate()
- get_50day_moving_avg()
- get_200day_moving_avg()
- get_beta()
- get_payout_ratio()
- get_pe_ratio()
- get_price_to_sales()
- get_exdividend_date()
- get_book_value()
- get_ebit()
- get_net_income()
- get_earnings_per_share()
- get_key_statistics_data()
- get_stock_profile_data()
- get_financial_data()
Usage Examples
- The class constructor can take either a single ticker or a list of tickers as it's parameter.
- This makes it easy to initiate multiple classes for different groupings of financial assets.
- Quarterly statement data returns the last 4 periods of data, while annual returns the last 3.
Single Ticker Example ^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
from yahoofinancials import YahooFinancials
ticker = 'AAPL'
yahoo_financials = YahooFinancials(ticker)
balance_sheet_data_qt = yahoo_financials.get_financial_stmts('quarterly', 'balance')
income_statement_data_qt = yahoo_financials.get_financial_stmts('quarterly', 'income')
all_statement_data_qt = yahoo_financials.get_financial_stmts('quarterly', ['income', 'cash', 'balance'])
apple_earnings_data = yahoo_financials.get_stock_earnings_data()
apple_net_income = yahoo_financials.get_net_income()
historical_stock_prices = yahoo_financials.get_historical_price_data('2008-09-15', '2018-09-15', 'weekly')
Lists of Tickers Example ^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
from yahoofinancials import YahooFinancials
tech_stocks = ['AAPL', 'MSFT', 'INTC']
bank_stocks = ['WFC', 'BAC', 'C']
commodity_futures = ['GC=F', 'SI=F', 'CL=F']
cryptocurrencies = ['BTC-USD', 'ETH-USD', 'XRP-USD']
currencies = ['EURUSD=X', 'JPY=X', 'GBPUSD=X']
mutual_funds = ['PRLAX', 'QASGX', 'HISFX']
us_treasuries = ['^TNX', '^IRX', '^TYX']
yahoo_financials_tech = YahooFinancials(tech_stocks)
yahoo_financials_banks = YahooFinancials(bank_stocks)
yahoo_financials_commodities = YahooFinancials(commodity_futures)
yahoo_financials_cryptocurrencies = YahooFinancials(cryptocurrencies)
yahoo_financials_currencies = YahooFinancials(currencies)
yahoo_financials_mutualfunds = YahooFinancials(mutual_funds)
yahoo_financials_treasuries = YahooFinancials(us_treasuries)
tech_cash_flow_data_an = yahoo_financials_tech.get_financial_stmts('annual', 'cash')
bank_cash_flow_data_an = yahoo_financials_banks.get_financial_stmts('annual', 'cash')
banks_net_ebit = yahoo_financials_banks.get_ebit()
tech_stock_price_data = yahoo_financials_tech.get_stock_price_data()
daily_bank_stock_prices = yahoo_financials_banks.get_historical_price_data('2008-09-15', '2018-09-15', 'daily')
daily_commodity_prices = yahoo_financials_commodities.get_historical_price_data('2008-09-15', '2018-09-15', 'daily')
daily_crypto_prices = yahoo_financials_cryptocurrencies.get_historical_price_data('2008-09-15', '2018-09-15', 'daily')
daily_currency_prices = yahoo_financials_currencies.get_historical_price_data('2008-09-15', '2018-09-15', 'daily')
dail
Related Skills
valuecell
9.8kValueCell is a community-driven, multi-agent platform for financial applications.
REFERENCE
An intelligent middleware layer between crypto wallets and traditional payment systems.
cashu-skill
A Cashu wallet skill for AI agents
canadian-finance-planner-skill
6A Claude skill that turns Claude into your personal financial planner — built specifically for Canadians. Interviews, budgets, action plans, interactive dashboards, and ongoing coaching.
