hsliuping/TradingAgents-CN · error · Exception

Stockstats fail: Yahoo Finance data not fetched yet!

Error message

Stockstats fail: Yahoo Finance data not fetched yet!

What it means

Raised by get_stock_stats in stockstats.py when the local Yahoo Finance CSV for the symbol is not on disk in offline mode — the FileNotFoundError from reading {symbol}-YFin-data-2015-01-01-2025-03-25.csv is re-raised as a generic Exception with this message.

Source

Thrown at tradingagents/dataflows/technical/stockstats.py:45

        online: Annotated[
            bool,
            "whether to use online tools to fetch data or offline tools. If True, will use online tools.",
        ] = False,
    ):
        df = None
        data = None

        if not online:
            try:
                data = pd.read_csv(
                    os.path.join(
                        data_dir,
                        f"{symbol}-YFin-data-2015-01-01-2025-03-25.csv",
                    )
                )
                df = wrap(data)
            except FileNotFoundError:
                raise Exception("Stockstats fail: Yahoo Finance data not fetched yet!")
        else:
            # Get today's date as YYYY-mm-dd to add to cache
            today_date = pd.Timestamp.today()
            curr_date = pd.to_datetime(curr_date)

            end_date = today_date
            start_date = today_date - pd.DateOffset(years=15)
            start_date = start_date.strftime("%Y-%m-%d")
            end_date = end_date.strftime("%Y-%m-%d")

            # Get config and ensure cache directory exists
            config = get_config()
            os.makedirs(config["data_cache_dir"], exist_ok=True)

            data_file = os.path.join(
                config["data_cache_dir"],
                f"{symbol}-YFin-data-{start_date}-{end_date}.csv",
            )

View on GitHub (pinned to 74783e8817)

Solutions

  1. Run the YFin data download/fetch step for the symbol first so the CSV exists
  2. Or call the online variant (pass online/curr_date path that fetches from yfinance)
  3. Check DATA_DIR points at the directory containing market_data/price_data/

Example fix

# before
df = get_stock_stats('MSFT', '2025-01-01')  # offline, no CSV
# after
from tradingagents.dataflows.yfin_utils import YFinanceUtils
YFinanceUtils.download_data_one('MSFT')  # populate CSV first
df = get_stock_stats('MSFT', '2025-01-01')
Defensive patterns

Strategy: validation

Validate before calling

import os, tradingagents.dataflows.technical.stockstats as ss
csv_path = os.path.join(ss.DATA_DIR, 'market_data/price_data', f'{symbol}-YFin-data-2015-01-01-2025-03-25.csv')
if not os.path.exists(csv_path):
    raise SystemExit(f'YFin data missing for {symbol}; download it first')
df = get_stock_stats(symbol, curr_date)

Try / catch

try:
    df = get_stock_stats(symbol, curr_date)
except Exception as e:
    if 'data not fetched yet' in str(e):
        download_yfin_csv(symbol)  # then retry
        df = get_stock_stats(symbol, curr_date)
    else:
        raise

Prevention

When it happens

Trigger: Offline mode (not online=True) calling get_stock_stats for a symbol whose YFin CSV hasn't been downloaded into DATA_DIR/market_data/price_data/, so the open() raises FileNotFoundError.

Common situations: First use of a new symbol without running the data download step, wrong DATA_DIR, or offline usage after clearing the cache directory.

Related errors


AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28). Data as JSON: /api/errors/5a66dcc470f90185. Report an issue: GitHub.