sylvandb / yahoofinancials

A financial data module used for scraping fundamental and technical stock data from Yahoo Finance. See branch sdb-master.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yahoofinancials

A python module that returns stock, cryptocurrency, forex, mutual fund, commodity futures, ETF, and US Treasury financial data from Yahoo Finance.

image

Current Version: v1.5

Version Released: 01/27/2019

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.

  • As of Version 0.10, Yahoo Financials now returns historical pricing data for commodity futures, cryptocurrencies, ETFs, mutual funds, U.S. Treasuries, currencies, indexes, and stocks.

Installation

  • yahoofinancials runs on Python 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7.
  • The package depends on beautifulsoup4 and pytz to work.
  1. Installation using pip:
  • Linux/Mac:
  • Windows (If python doesn't work for you in cmd, try running the following command with just py):
> python -m pip install yahoofinancials
  1. Installation using github (Mac/Linux):
  1. Demo using the included demo script:
  1. Test using the included unit testing script:

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 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7 and runs on all operating systems. (Windows, Mac, Linux).
  1. 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.
  2. get_stock_price_data(reformat=True)
    • reformat optional value defaulted to true. Enter False for unprocessed raw data from Yahoo Finance.
  3. get_stock_earnings_data(reformat=True)
    • reformat optional value defaulted to true. Enter False for unprocessed raw data from Yahoo Finance.
  4. 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.
  5. get_stock_quote_type_data()
  6. 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.
  7. 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.

Methods Added in V1.5

  • get_daily_dividend_data(start_date, end_date)

Additional Module Methods

  • 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_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_three_month_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()

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

Lists of Tickers Example

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')
daily_mutualfund_prices = yahoo_financials_mutualfunds.get_historical_price_data('2008-09-15', '2018-09-15', 'daily')
daily_treasury_prices = yahoo_financials_treasuries.get_historical_price_data('2008-09-15', '2018-09-15', 'daily')

Examples of Returned JSON Data

  1. Annual Income Statement Data for Apple:
  1. Annual Balance Sheet Data for Apple:
  1. Quarterly Cash Flow Statement Data for Citigroup:
  1. Monthly Historical Stock Price Data for Wells Fargo:
  1. Monthly Historical Price Data for EURUSD:
  1. Monthly Historical Price Data for BTC-USD:
  1. Weekly Historical Price Data for Crude Oil Futures:
  1. Apple Stock Quote Data:
  1. U.S. Treasury Current Pricing Data:
  1. BTC-USD Summary Data:
  1. Apple Key Statistics Data:
  1. Apple and Wells Fargo Daily Dividend Data:

About

A financial data module used for scraping fundamental and technical stock data from Yahoo Finance. See branch sdb-master.

License:MIT License


Languages

Language:Python 100.0%