Convert Figma logo to code with AI

yahoo-finance logoyahoo-finance

Python module to get stock data from Yahoo! Finance

1,331
352
1,331
87

Top Related Projects

Extract data from a wide range of Internet sources into a pandas DataFrame.

13,247

Download market data from Yahoo! Finance's API

Python module to get stock data from Yahoo! Finance

Python Backtesting library for trading strategies

2,127

Common financial technical indicators implemented in Pandas.

Python wrapper for TA-Lib (http://ta-lib.org/).

Quick Overview

Yahoo Finance is a Python library that provides a convenient way to access financial data from Yahoo Finance. It allows users to retrieve stock quotes, historical data, options data, and other financial information programmatically. The library simplifies the process of fetching and analyzing financial data for various applications and research purposes.

Pros

  • Easy to use and well-documented API
  • Provides access to a wide range of financial data
  • Supports both real-time and historical data retrieval
  • Free to use and open-source

Cons

  • Relies on Yahoo Finance's data, which may have occasional inaccuracies
  • Limited to the data available on Yahoo Finance
  • May be subject to rate limiting or changes in Yahoo's API

Code Examples

  1. Fetching current stock price:
from yahoo_finance import Share
apple = Share('AAPL')
print(apple.get_price())
  1. Retrieving historical data:
from yahoo_finance import Share
google = Share('GOOGL')
historical_data = google.get_historical('2022-01-01', '2022-12-31')
print(historical_data)
  1. Getting company information:
from yahoo_finance import Share
tesla = Share('TSLA')
print(tesla.get_info())

Getting Started

To get started with Yahoo Finance, follow these steps:

  1. Install the library using pip:
pip install yahoo-finance
  1. Import the library and create a Share object:
from yahoo_finance import Share
stock = Share('SYMBOL')
  1. Use the various methods to retrieve data:
price = stock.get_price()
volume = stock.get_volume()
earnings = stock.get_earnings_per_share()

That's it! You can now start exploring and analyzing financial data using the Yahoo Finance library.

Competitor Comparisons

Extract data from a wide range of Internet sources into a pandas DataFrame.

Pros of pandas-datareader

  • Supports multiple data sources beyond Yahoo Finance
  • Integrates seamlessly with pandas DataFrame structures
  • Actively maintained with regular updates

Cons of pandas-datareader

  • Can be slower for large data requests
  • Occasionally experiences issues with data accuracy
  • Requires additional dependencies (pandas)

Code Comparison

pandas-datareader:

import pandas_datareader as pdr
data = pdr.get_data_yahoo("AAPL", start="2020-01-01", end="2021-01-01")

yahoo-finance:

from yahoo_finance import Share
yahoo = Share('AAPL')
data = yahoo.get_historical('2020-01-01', '2021-01-01')

Both libraries provide methods to fetch historical stock data, but pandas-datareader offers a more straightforward approach that directly returns a pandas DataFrame. The yahoo-finance library requires an additional step to convert the data into a usable format.

pandas-datareader is generally preferred for its versatility and integration with the pandas ecosystem, while yahoo-finance might be simpler for basic Yahoo Finance data retrieval. However, the choice between the two depends on specific project requirements and personal preferences.

13,247

Download market data from Yahoo! Finance's API

Pros of yfinance

  • More actively maintained with frequent updates
  • Supports multi-threading for faster data retrieval
  • Offers additional features like options data and cryptocurrency support

Cons of yfinance

  • May have occasional stability issues due to rapid development
  • Documentation can be less comprehensive compared to yahoo-finance

Code Comparison

yahoo-finance:

from yahoo_finance import Share
yahoo = Share('YHOO')
print(yahoo.get_price())

yfinance:

import yfinance as yf
ticker = yf.Ticker('YHOO')
print(ticker.info['regularMarketPrice'])

Key Differences

  • yfinance uses a more modern API structure
  • yahoo-finance relies on an older, deprecated Yahoo Finance API
  • yfinance offers more flexibility in data retrieval and manipulation

Performance

yfinance generally outperforms yahoo-finance in terms of speed and data availability, especially for large datasets or multiple tickers.

Community and Support

yfinance has a larger and more active community, resulting in quicker bug fixes and feature additions. However, yahoo-finance may offer more stability for legacy projects.

Conclusion

While both libraries serve similar purposes, yfinance is generally considered the more modern and feature-rich option, making it the preferred choice for most new projects requiring Yahoo Finance data.

Python module to get stock data from Yahoo! Finance

Pros of yahoo-finance

  • More actively maintained with frequent updates
  • Larger community and user base
  • Better documentation and examples

Cons of yahoo-finance

  • Slower performance for large data requests
  • Limited historical data availability
  • More complex API structure

Code Comparison

yahoo-finance:

import yfinance as yf

msft = yf.Ticker("MSFT")
hist = msft.history(period="1mo")
print(hist)

yahoo-finance>:

from yahoo_finance import Share

yahoo = Share('YHOO')
print(yahoo.get_historical('2014-04-25', '2014-04-29'))

Summary

Both libraries provide access to Yahoo Finance data, but yahoo-finance offers more frequent updates and better documentation. However, it may have slower performance for large requests. yahoo-finance> has a simpler API structure but is less actively maintained. The choice between the two depends on specific project requirements and the need for up-to-date features versus simplicity.

Python Backtesting library for trading strategies

Pros of backtrader

  • Comprehensive backtesting framework with support for multiple data feeds and strategies
  • Extensive documentation and active community support
  • Built-in plotting capabilities for visualizing trading results

Cons of backtrader

  • Steeper learning curve due to its more complex architecture
  • May be overkill for simple financial data retrieval tasks
  • Slower performance compared to lightweight libraries

Code Comparison

backtrader:

import backtrader as bt

class MyStrategy(bt.Strategy):
    def next(self):
        if self.data.close[0] > self.data.close[-1]:
            self.buy()

yahoo-finance:

import yfinance as yf

ticker = yf.Ticker("AAPL")
history = ticker.history(period="1mo")

Summary

backtrader is a comprehensive backtesting framework suitable for complex trading strategies and analysis. It offers more features but requires a deeper understanding of its architecture. yahoo-finance, on the other hand, is a simpler library focused on retrieving financial data from Yahoo Finance. It's easier to use for basic data retrieval tasks but lacks advanced backtesting capabilities.

Choose backtrader for in-depth strategy testing and analysis, or yahoo-finance for quick and easy access to financial data without the need for extensive backtesting functionality.

2,127

Common financial technical indicators implemented in Pandas.

Pros of finta

  • Focuses on financial technical analysis indicators
  • Provides a wide range of technical indicators and oscillators
  • Lightweight and easy to integrate into existing projects

Cons of finta

  • Limited to technical analysis, doesn't provide fundamental data
  • Less comprehensive market data compared to yahoo-finance
  • Smaller community and fewer updates

Code Comparison

finta:

from finta import TA

high = [10, 12, 15, 14, 13]
low = [8, 9, 11, 9, 10]
close = [9, 11, 14, 11, 12]

rsi = TA.RSI({"close": close})

yahoo-finance:

import yfinance as yf

ticker = yf.Ticker("AAPL")
history = ticker.history(period="1mo")
close_prices = history['Close']

# RSI calculation would require additional implementation

Summary

finta is specialized for technical analysis indicators, offering a wide range of pre-implemented functions. It's lightweight and easy to use for specific technical analysis tasks. yahoo-finance, on the other hand, provides broader market data and fundamental information but requires additional implementation for technical indicators. The choice between the two depends on the specific needs of the project, with finta being more suitable for focused technical analysis and yahoo-finance for comprehensive market data retrieval.

Python wrapper for TA-Lib (http://ta-lib.org/).

Pros of ta-lib-python

  • Extensive library of technical analysis functions
  • Optimized C implementations for performance
  • Well-established and widely used in the finance industry

Cons of ta-lib-python

  • Requires separate installation of TA-Lib C library
  • Steeper learning curve due to more complex API
  • Limited to technical analysis, no data retrieval capabilities

Code Comparison

yahoo-finance:

import yfinance as yf

ticker = yf.Ticker("AAPL")
hist = ticker.history(period="1mo")
print(hist['Close'])

ta-lib-python:

import numpy as np
import talib

close_prices = np.random.random(100)
sma = talib.SMA(close_prices, timeperiod=20)
print(sma)

Summary

yahoo-finance focuses on retrieving financial data from Yahoo Finance, while ta-lib-python specializes in technical analysis calculations. yahoo-finance is easier to set up and use for basic data retrieval, but ta-lib-python offers a comprehensive set of technical indicators and functions for more advanced analysis. The choice between the two depends on the specific requirements of your project and the depth of technical analysis needed.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

============= yhoo-finance

Python module to get stock data from Yahoo! Finance

.. image:: https://travis-ci.org/lukaszbanasiak/yahoo-finance.svg?branch=master :target: https://travis-ci.org/lukaszbanasiak/yahoo-finance

Legal disclaimer

Yahoo!, Y!Finance, and Yahoo! finance are registered trademarks of Yahoo, Inc.

yhoo-finance is not affiliated, endorsed, or vetted by Yahoo, Inc. It's an open-source tool that uses Yahoo's publicly available APIs, and is intended for research and educational purposes.

You should refer to Yahoo!'s terms of use (https://policies.yahoo.com/us/en/yahoo/terms/product-atos/apiforydn/index.htm, https://legal.yahoo.com/us/en/yahoo/terms/otos/index.html, https://policies.yahoo.com/us/en/yahoo/terms/index.htm) for details on your rights to use the actual data downloaded. Remember - the Yahoo! finance API is intended for personal use only.

Know issues

Yahoo! Finance backend is http://datatables.org/. If this service is down or has network problems you will receive errors from group YQL*, eg. YQLQueryError.

You can monitor this service via https://www.datatables.org/healthchecker/

More details https://github.com/lukaszbanasiak/yahoo-finance/issues/44

Install

From PyPI with pip:

.. code:: bash

$ pip install yahoo-finance

From development repo (requires git)

.. code:: bash

$ git clone git://github.com/lukaszbanasiak/yhoo-finance.git
$ cd yahoo-finance
$ python setup.py install

Usage examples

Get shares data ^^^^^^^^^^^^^^^

Example: Yahoo! Inc. (YHOO)

.. code:: python

>>> from yahoo_finance import Share
>>> yahoo = Share('YHOO')
>>> print yahoo.get_open()
'36.60'
>>> print yahoo.get_price()
'36.84'
>>> print yahoo.get_trade_datetime()
'2014-02-05 20:50:00 UTC+0000'

Refresh data from market

.. code:: python

>>> yahoo.refresh()
>>> print yahoo.get_price()
'36.87'
>>> print yahoo.get_trade_datetime()
'2014-02-05 21:00:00 UTC+0000'

Historical data

.. code:: python

>>> print yahoo.get_historical('2014-04-25', '2014-04-29')
[{u'Volume': u'28720000', u'Symbol': u'YHOO', u'Adj_Close': u'35.83', u'High': u'35.89', u'Low': u'34.12', u'Date': u'2014-04-29', u'Close': u'35.83', u'Open': u'34.37'}, {u'Volume': u'30422000', u'Symbol': u'YHOO', u'Adj_Close': u'33.99', u'High': u'35.00', u'Low': u'33.65', u'Date': u'2014-04-28', u'Close': u'33.99', u'Open': u'34.67'}, {u'Volume': u'19391100', u'Symbol': u'YHOO', u'Adj_Close': u'34.48', u'High': u'35.10', u'Low': u'34.29', u'Date': u'2014-04-25', u'Close': u'34.48', u'Open': u'35.03'}]

More readable output :)

.. code:: python

>>> from pprint import pprint
>>> pprint(yahoo.get_historical('2014-04-25', '2014-04-29'))
[{u'Adj_Close': u'35.83',
  u'Close': u'35.83',
  u'Date': u'2014-04-29',
  u'High': u'35.89',
  u'Low': u'34.12',
  u'Open': u'34.37',
  u'Symbol': u'YHOO',
  u'Volume': u'28720000'},
 {u'Adj_Close': u'33.99',
  u'Close': u'33.99',
  u'Date': u'2014-04-28',
  u'High': u'35.00',
  u'Low': u'33.65',
  u'Open': u'34.67',
  u'Symbol': u'YHOO',
  u'Volume': u'30422000'},
 {u'Adj_Close': u'34.48',
  u'Close': u'34.48',
  u'Date': u'2014-04-25',
  u'High': u'35.10',
  u'Low': u'34.29',
  u'Open': u'35.03',
  u'Symbol': u'YHOO',
  u'Volume': u'19391100'}]

Available methods

  • get_price()
  • get_change()
  • get_percent_change()
  • get_volume()
  • get_prev_close()
  • get_open()
  • get_avg_daily_volume()
  • get_stock_exchange()
  • get_market_cap()
  • get_book_value()
  • get_ebitda()
  • get_dividend_share()
  • get_dividend_yield()
  • get_earnings_share()
  • get_days_high()
  • get_days_low()
  • get_year_high()
  • get_year_low()
  • get_50day_moving_avg()
  • get_200day_moving_avg()
  • get_price_earnings_ratio()
  • get_price_earnings_growth_ratio()
  • get_price_sales()
  • get_price_book()
  • get_short_ratio()
  • get_trade_datetime()
  • get_historical(start_date, end_date)
  • get_name()
  • refresh()
  • get_percent_change_from_year_high()
  • get_percent_change_from_year_low()
  • get_change_from_year_low()
  • get_change_from_year_high()
  • get_percent_change_from_200_day_moving_average()
  • get_change_from_200_day_moving_average()
  • get_percent_change_from_50_day_moving_average()
  • get_change_from_50_day_moving_average()
  • get_EPS_estimate_next_quarter()
  • get_EPS_estimate_next_year()
  • get_ex_dividend_date()
  • get_EPS_estimate_current_year()
  • get_price_EPS_estimate_next_year()
  • get_price_EPS_estimate_current_year()
  • get_one_yr_target_price()
  • get_change_percent_change()
  • get_dividend_pay_date()
  • get_currency()
  • get_last_trade_with_time()
  • get_days_range()
  • get_year_range()

Get currency data ^^^^^^^^^^^^^^^^^

Example: EUR/PLN (EURPLN=X)

.. code:: python

>>> from yahoo_finance import Currency
>>> eur_pln = Currency('EURPLN')
>>> print eur_pln.get_bid()
'4.2007'
>>> print eur_pln.get_ask()
'4.2091'
>>> print eur_pln.get_rate()
'4.2049'
>>> print eur_pln.get_trade_datetime()
'2014-03-05 11:23:00 UTC+0000'

Refresh data from market

.. code:: python

>>> eur_pln.refresh()
>>> print eur_pln.get_rate()
'4.2052'
>>> print eur_pln.get_trade_datetime()
'2014-03-05 11:27:00 UTC+0000'

Avalible methods

  • get_bid()
  • get_ask()
  • get_rate()
  • get_trade_datetime()
  • refresh()

Requirements

See requirements.txt

NPM DownloadsLast 30 Days