Skip to content

Conversation

@thedrunkfishh
Copy link

@thedrunkfishh thedrunkfishh commented Dec 8, 2025

Summary

This PR implements concurrent batch processing for retrieving financial statements (financials, balance_sheet, cash_flow, earnings) in the Tickers class.

Currently, fetching these attributes for a list of tickers happens serially, which is a bottleneck for users analyzing multiple stocks. This change uses concurrent.futures.ThreadPoolExecutor to parallelize these requests.

Changes

  • Updated Tickers class (tickers.py):
    • Added _download_attribute helper method.
    • Added public batch methods:
      • download_financials(threads=None)
      • download_balance_sheet(threads=None)
      • download_cash_flow(threads=None)
      • download_earnings(threads=None)
      • download_info(threads=None)

Usage

import yfinance as yf

symbols = "AAPL MSFT GOOG AMZN META"
tickers = yf.Tickers(symbols)

# previously (serial, slower):
# data = {s: yf.Ticker(s).financials for s in symbols.split()}

# now (concurrent, faster):
financials = tickers.download_financials()
# returns dict: {'AAPL': pd.DataFrame, 'MSFT': pd.DataFrame, ...}

balance_sheets = tickers.download_balance_sheet()

Performance Benchmark

  1. Benchmarked with 10 popular tickers (AAPL, MSFT, GOOG, AMZN, META, TSLA, NVDA, JPM, V, WMT).

Results:

  • Serial Fetching: ~1.81 seconds
  • Batch Fetching: ~0.08 seconds
  • Speedup: ~22.88x
  1. Benchmarked with an isolated, cold-cache environment.

Results:

  • Serial Fetching (Cold): ~3.01 seconds
  • Batch Fetching (Cold): ~0.54 seconds
  • Speedup: ~5.56x

(Note: Speedups can be significantly higher in warm-cache scenarios)

@thedrunkfishh thedrunkfishh force-pushed the feature/batch-financials-processing branch from 4669a02 to 581b5e8 Compare December 8, 2025 07:07
@thedrunkfishh thedrunkfishh changed the title Improvement: Concurrent Batch Processing for Financials (>20x Speedup) Improvement: Concurrent Batch Processing for Financials Dec 8, 2025
@ValueRaider
Copy link
Collaborator

Do you really need to frequently bulk-fetch financials? Try https://pypi.org/project/yfinance-cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants