Skip to content

Historical analyses leak current Reddit and StockTwits data into the sentiment report #1220

Description

@yiran1268

Summary

When trade_date is historical, the Sentiment Analyst correctly requests Yahoo news for the historical window, but still fetches the current StockTwits stream and Reddit's current last week. Those current posts are then placed in a prompt that says they cover the historical start_date..end_date window.

This introduces look-ahead bias and can make backtests use information that did not exist on the requested trading date.

Reproduction

  1. Run the sentiment analyst with a historical date, for example trade_date="2020-01-15".
  2. In sentiment_analyst_node, compare the three fetches:
    • Yahoo news receives start_date="2020-01-08" and end_date="2020-01-15".
    • fetch_stocktwits_messages(ticker, limit=30) receives no date and calls the current symbol-stream endpoint.
    • fetch_reddit_posts(ticker) receives no date, and _search_qs hard-codes t=week (the current week).
  3. The resulting prompt nevertheless says the report covers 2020-01-08 through 2020-01-15 and labels Reddit as “past 7 days”.

Relevant code:

  • tradingagents/agents/analysts/sentiment_analyst.py:62-71
  • tradingagents/agents/analysts/sentiment_analyst.py:131-150
  • tradingagents/dataflows/reddit.py:52-58
  • tradingagents/dataflows/stocktwits.py:26,41-52

Expected behavior

Every observation used for an analysis should have a timestamp at or before trade_date. If the public social APIs cannot provide historical data, historical runs should omit those sources and inject an explicit “historical data unavailable” placeholder rather than substituting current posts.

Actual behavior

Current social posts are included in historical analyses and presented to the LLM as though they came from the requested historical period.

Suggested regression coverage

Add a test using an old trade_date that verifies neither social fetcher can return observations newer than end_date (or verifies that the sources are marked unavailable when historical retrieval is unsupported).

Environment

  • TradingAgents main at 01477f9 (v0.3.1)
  • Python 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions