Environment:AI4Finance Foundation FinGPT yfinance
| Knowledge Sources | |
|---|---|
| Domains | Financial_Data, API |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Yahoo Finance data API via the `yfinance` library (>=0.2.49) for downloading historical stock prices, weekly returns, and market data.
Description
This environment provides the `yfinance` library used to download historical stock price data (Adj Close), compute weekly returns, and create bin labels for the Forecaster training pipeline. It also provides real-time price data for the inference app. The library scrapes Yahoo Finance's public API and requires no API key.
Usage
Use this environment for Market Data Acquisition — fetching historical stock prices, computing weekly returns, and generating price movement labels. Required by `prepare_data_for_symbol`, `get_stock_data` (inference), and `construct_prompt`.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Any | HTTP-based |
| Hardware | CPU sufficient | No GPU needed |
| Network | Internet | Required for Yahoo Finance API |
Dependencies
Python Packages
- `yfinance` >= 0.2.49
- `pandas`
- `numpy` < 2
Credentials
No API key required. Yahoo Finance is a free public API.
Quick Install
pip install "yfinance>=0.2.49" pandas "numpy<2"
Code Evidence
Stock data download and weekly resampling from `fingpt/FinGPT_Forecaster/data.py:41-46`:
stock_data = yf.download(stock_symbol, start=start_date, end=end_date)
weekly_data = stock_data['Adj Close'].resample('W').ffill()
weekly_returns = weekly_data.pct_change()[1:]
Inference data fetch with error handling from `fingpt/FinGPT_Forecaster/app.py:85-87`:
stock_data = yf.download(stock_symbol, steps[0], steps[-1])
if len(stock_data) == 0:
raise gr.Error(f"Failed to download stock price data for symbol {stock_symbol} from yfinance!")
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Failed to download stock price data` | Empty data returned | Check ticker symbol; ensure market is open for date range |
| `yfinance download slow / timeout` | Yahoo rate limiting | Add delays between calls; use cached data |
| `IndexError on weekly_data` | Insufficient historical data | Ensure date range has enough trading days for weekly resampling |
Compatibility Notes
- India markets: Use `.NS` (NSE) or `.BO` (BSE) suffix per `market_symbols.py` resolution.
- Crypto: Supported via CRYPTO ticker list in `indices.py`.
- No API key: Unlike Finnhub, yfinance requires no credentials.