fix(data): normalize symbols on the identity and reflection paths

resolve_instrument_identity and the reflection return lookup queried Yahoo with
the raw ticker, so broker/forex/commodity symbols (XAUUSD, BTCUSD, EURUSD)
failed identity or could mismatch the priced instrument even though the price
path already normalized them. Route both through normalize_symbol (#983, #984).
This commit is contained in:
Yijia-Xiao
2026-06-13 20:39:52 +00:00
parent 2a58c2208f
commit 7c8fe2fe9f
3 changed files with 66 additions and 2 deletions

View File

@@ -70,9 +70,14 @@ def resolve_instrument_identity(ticker: str) -> dict:
recognise the ticker, we return ``{}`` and the caller falls back to
ticker-only context rather than failing before analysis starts. Cached so
the lookup happens at most once per ticker per process.
The symbol is normalized first (e.g. ``XAUUSD`` -> ``GC=F``) so identity
resolves for the same instrument the price path actually fetches (#983).
"""
from tradingagents.dataflows.symbol_utils import normalize_symbol
try:
info = yf.Ticker(ticker.upper()).info or {}
info = yf.Ticker(normalize_symbol(ticker)).info or {}
except Exception as exc: # noqa: BLE001 — fail open, never block the run
logger.debug("Could not resolve instrument identity for %s: %s", ticker, exc)
return {}

View File

@@ -232,12 +232,17 @@ class TradingAgentsGraph:
actual_holding_days)`` or ``(None, None, None)`` if price data is
unavailable (too recent, delisted, or network error).
"""
from tradingagents.dataflows.symbol_utils import normalize_symbol
try:
start = datetime.strptime(trade_date, "%Y-%m-%d")
end = start + timedelta(days=holding_days + 7) # buffer for weekends/holidays
end_str = end.strftime("%Y-%m-%d")
stock = yf.Ticker(ticker).history(start=trade_date, end=end_str)
# Normalize so the realized-return lookup hits the same instrument
# the analysis priced (e.g. XAUUSD -> GC=F) (#984). The benchmark is
# already a canonical Yahoo symbol from ``_resolve_benchmark``.
stock = yf.Ticker(normalize_symbol(ticker)).history(start=trade_date, end=end_str)
bench = yf.Ticker(benchmark).history(start=trade_date, end=end_str)
if len(stock) < 2 or len(bench) < 2: