vcerqueira / yfinance

Yahoo! Finance market data downloader (+faster Pandas Datareader)

Home Page:https://aroussi.com/post/python-yahoo-finance

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yahoo! Finance market data downloader

Python version

PyPi version

PyPi status

PyPi downloads

Travis-CI build status

CodeFactor

Star this repo

Follow me on twitter

Ever since Yahoo! finance decommissioned their historical data API, many programs that relied on it to stop working.

yfinance aimes to solve this problem by offering a reliable, threaded, and Pythonic way to download historical market data from Yahoo! finance.

NOTE

The library was originally named fix-yahoo-finance, but I've since renamed it to yfinance as I no longer consider it a mere "fix". For reasons of backward-compatibility, fix-yahoo-finance now import and uses yfinance, but you should install and use yfinance directly.

Changelog »


==> Check out this Blog post for a detailed tutorial with code examples.


Quick Start

The Ticker module

The Ticker module, which allows you to access ticker data in a more Pythonic way:

Note: yahoo finance datetimes are received as UTC.

If you want to use a proxy server for downloading data, use:

To use a custom requests session (for example to cache calls to the API or customize the User-agent header), pass a session= argument to the Ticker constructor.

To initialize multiple Ticker objects, use

Fetching data for multiple tickers

I've also added some options to make life easier :)

Managing Multi-Level Columns

The following answer on Stack Overflow is for How to deal with multi-level column names downloaded with yfinance?

  • yfinance returns a pandas.DataFrame with multi-level column names, with a level for the ticker and a level for the stock price data
    • The answer discusses:
      • How to correctly read the the multi-level columns after saving the dataframe to a csv with pandas.DataFrame.to_csv
      • How to download single or multiple tickers into a single dataframe with single level column names and a ticker column

pandas_datareader override

If your code uses pandas_datareader and you want to download data faster, you can "hijack" pandas_datareader.data.get_data_yahoo() method to use yfinance while making sure the returned data is in the same format as pandas_datareader's get_data_yahoo().

Installation

Install yfinance using pip:

Install yfinance using conda:

Requirements

Optional (if you want to use pandas_datareader)

yfinance is distributed under the Apache Software License. See the LICENSE.txt file in the release for details.

P.S.

Please drop me an note with any feedback you have.

Ran Aroussi

About

Yahoo! Finance market data downloader (+faster Pandas Datareader)

https://aroussi.com/post/python-yahoo-finance

License:Apache License 2.0


Languages

Language:Python 100.0%