Market Data & Web Scraping Beginner

Bulk Download Historical OHLCV Stock Data for 50+ Tickers in Python (yfinance)

Download multi-year daily or intraday OHLCV candle data for dozens of NSE, NYSE, or Crypto tickers simultaneously using Python yfinance and export to CSV.

#yfinance#pandas

Problem Statement

Downloading tickers one by one hits rate limits and takes minutes. This script uses multi-threaded batch downloading in `yfinance` and reshapes the output into clean per-ticker CSVs.

Formula / Core Logic

Uses yf.download(tickers, group_by='ticker', threads=True) for concurrent HTTP fetching.

Installation

pip install yfinance pandas
fetch-historical-stock-data-yahoo-finance-python.py
import yfinance as yf
import os

def bulk_download_ohlcv(tickers, period='2y', interval='1d', out_dir='market_data'):
    os.makedirs(out_dir, exist_ok=True)
    data = yf.download(tickers, period=period, interval=interval, group_by='ticker', threads=True, progress=False)
    for ticker in tickers:
        df = data[ticker].dropna(how='all')
        df.to_csv(f'{out_dir}/{ticker}.csv')
        print(f'Saved {ticker}: {len(df)} candles')

if __name__ == '__main__':
    bulk_download_ohlcv(['AAPL', 'MSFT', 'NVDA', '^NSEI'])

Get the Complete 100+ Python Quant & Automation Bundle

Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).

Buy Full Bundle on Gumroad ($19) →

Frequently Asked Questions

Q: What is the maximum lookback period for 5-minute intraday data on Yahoo Finance?

Yahoo Finance restricts 5-minute interval downloads to the most recent 60 days, and 1-minute data to 7 days.