Actively developed

yfinance guide

yfinance is the first data library most Python traders install.

Last reviewed

Quick answer

yfinance is a popular open-source Python library that downloads data from Yahoo Finance: historical prices (yf.download), dividends and splits, options chains, financial statements and more, as pandas DataFrames. It uses unofficial endpoints, so it can break or be rate-limited when Yahoo changes things; production systems usually pair it with a paid source.

yfinance at a glance

Category
Broker, exchange & data libraries
Language
Python
License
Apache-2.0
Does
Market data
Markets
Stocks, ETFs, Indices, Forex, Crypto, Futures, Options, Fundamentals
Best for
Free research data for stocks, ETFs, indices, FX and crypto.
In AlgoGP
Use the exported strategy object from your own code

Pick it if

Free research data for stocks, ETFs, indices, FX and crypto.

Watch out for

Unofficial: rate limits and breakages happen.

yfinance strengths and limitations

Strengths

  • Free, no key.
  • Broad coverage including fundamentals and options.
  • Simple pandas output.

Limitations

  • Unofficial: rate limits and breakages happen.
  • Not licensed for commercial redistribution.

yfinance example

pip install yfinance
Install
import yfinance as yf
data = yf.download(["SPY", "QQQ"], start="2020-01-01", auto_adjust=True)
print(data["Close"].tail())
Daily bars for two tickers.

Use yfinance with AlgoGP

AlgoGP does not add yfinance to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from yfinance yourself.

  1. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from yfinance

    Feed yfinance’s bars to StrategyBridge, place the returned orders with yfinance, and report fills back with sync().

yfinance connects to Yahoo Finance. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.

yfinance: frequently asked questions

Why is yfinance rate limited?

Yahoo throttles unofficial access; cache data, slow requests, or use a keyed API.

Does AlgoGP need yfinance?

No; exported projects read Yahoo’s chart endpoint with the standard library, and in-app backtests use AlgoGP’s own data.

yfinance alternatives

Independent guide. AlgoGP is not affiliated with yfinance. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy