hsliuping/TradingAgents-CN · error · Exception

Get_YFin_Data: {end_date} is outside of the data range of 20

Error message

Get_YFin_Data: {end_date} is outside of the data range of 2015-01-01 to 2025-03-25

What it means

Raised by get_YFin_data when the requested end_date exceeds 2025-03-25, the upper bound of the bundled offline Yahoo Finance CSV (2015-01-01 to 2025-03-25). The function serves only pre-downloaded local data, so later dates are impossible.

Source

Thrown at tradingagents/dataflows/interface.py:918

    return header + csv_string


def get_YFin_data(
    symbol: Annotated[str, "ticker symbol of the company"],
    start_date: Annotated[str, "Start date in yyyy-mm-dd format"],
    end_date: Annotated[str, "End date in yyyy-mm-dd format"],
) -> str:
    # read in data
    data = pd.read_csv(
        os.path.join(
            DATA_DIR,
            f"market_data/price_data/{symbol}-YFin-data-2015-01-01-2025-03-25.csv",
        )
    )

    if end_date > "2025-03-25":
        raise Exception(
            f"Get_YFin_Data: {end_date} is outside of the data range of 2015-01-01 to 2025-03-25"
        )

    # Extract just the date part for comparison
    data["DateOnly"] = data["Date"].str[:10]

    # Filter data between the start and end dates (inclusive)
    filtered_data = data[
        (data["DateOnly"] >= start_date) & (data["DateOnly"] <= end_date)
    ]

    # Drop the temporary column we created
    filtered_data = filtered_data.drop("DateOnly", axis=1)

    # remove the index from the dataframe
    filtered_data = filtered_data.reset_index(drop=True)

    return filtered_data

View on GitHub (pinned to 74783e8817)

Solutions

  1. Clamp end_date to '2025-03-25' when using offline YFin data
  2. Switch to the online data path (get_YFin_data_online) for current dates
  3. Regenerate/re-download the CSV and update the hardcoded range constant

Example fix

# before
df = get_YFin_data('AAPL', '2025-12-31', '2025-01-01')
# after
df = get_YFin_data('AAPL', '2025-03-25', '2025-01-01')
Defensive patterns

Strategy: validation

Validate before calling

end_date = min(end_date, '2025-03-25')
df = get_YFin_data(symbol, end_date, look_back_days)

Try / catch

try:
    df = get_YFin_data(symbol, end_date, look_back_days)
except Exception as e:
    if 'outside of the data range' in str(e):
        df = get_YFin_data(symbol, '2025-03-25', look_back_days)
    else:
        raise

Prevention

When it happens

Trigger: Calling get_YFin_data(symbol, end_date='2025-06-01') or with today's date after 2025-03-25 while using the offline/cached data mode.

Common situations: Running the project with default offline data as time passes beyond the dataset's horizon; tests using datetime.now() as end date.

Related errors


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