Skip to content

fix(correlation): resolve bare tickers so the matrix stops failing with "Fetched: []"#472

Merged
warren618 merged 1 commit into
HKUDS:mainfrom
yxhuang:fix/correlation-bare-tickers
Jul 12, 2026
Merged

fix(correlation): resolve bare tickers so the matrix stops failing with "Fetched: []"#472
warren618 merged 1 commit into
HKUDS:mainfrom
yxhuang:fix/correlation-bare-tickers

Conversation

@yxhuang

@yxhuang yxhuang commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the Correlation tab failing with Could not fetch price data for at least 2 assets. Fetched: [] when given bare tickers like AAPL,SPY — the exact format the UI hint suggests. Root cause: user input was passed straight to loaders that key instruments by exchange-suffixed symbols (AAPL.US / 600000.SH), plus two compounding issues in market inference and the fetch loop.

What's in it

Three layered fixes in agent/backtest/correlation.py:

  • infer_market rewritten — explicit suffix is now authoritative (.HK, .SH/.SZ/.BJ, .US), then bare numeric codes classify by digit length (exactly 6 digits = A-share; ≤5 = HK). The old prefix heuristics misrouted bare 0700→SZ, 9988→US, 300750→HK, and even suffixed 830799.BJ→US. Prefix alone can't separate HK from A-share (both use leading 0/3); digit length can.
  • _normalize_symbol (new) — canonicalizes bare tickers to the loader symbol form before fetching (AAPLAAPL.US, 600000600000.SH, 07000700.HK), while crypto pairs and already-suffixed codes pass through untouched. The user's original input is kept as the matrix label.
  • Fetch loop walks the full FALLBACK_CHAINS until a loader actually returns data, instead of stopping at the first available one — a loader can be available yet serve nothing (network error), which silently dropped assets a later loader could serve. Every per-source failure is now logged (logger.warning) instead of swallowed by bare except: continue, so the next person debugging this sees why.

Tests (agent/tests/test_correlation.py, +10 cases): bare/suffixed classification for all markets incl. BJ, symbol normalization, and a chain fall-through regression test (first loader available-but-empty → second loader serves). 22 pass.

Notes

  • 000001-style true ambiguity (Ping An Bank vs SSE Composite index) can't be resolved by inference — bare 6-digit codes default to the stock reading; the index still needs an explicit 000001.SH.
  • Behavior for already-suffixed symbols and crypto pairs is unchanged.
  • Touches only correlation.py + its tests; verified end-to-end: AAPL,SPY → 2×2 matrix (corr 0.4057), 0700,9988,AAPL,SPY → full 4×4 with eastmoney down (falls through to yahoo, failure logged).

Closes #471.

🤖 Generated with Claude Code

…th "Fetched: []"

The /correlation endpoint passed user input straight to the data loaders,
which key US/HK/A-share instruments by exchange-suffixed symbols
(AAPL.US / 0700.HK / 600000.SH). Bare tickers — exactly what the UI hint
suggests (e.g. "BTC-USDT,ETH-USDT,AAPL,SPY") — matched no loader and the
request failed with "Could not fetch price data for at least 2 assets.
Fetched: []".

Three layered fixes:

1. infer_market: classify by explicit suffix first, then bare numeric
   codes by digit length (6 digits = A-share, <=5 = HK). The old prefix
   heuristics misrouted bare HK codes (0700 -> SZ, 9988 -> US), ChiNext
   codes (300750 -> HK), and even suffixed 830799.BJ (-> US).
2. _normalize_symbol (new): canonicalize bare tickers to the loader
   symbol form before fetching, keeping the user's input as the label.
3. Fetch loop: walk the market's full FALLBACK_CHAIN until a loader
   actually returns data instead of stopping at the first *available*
   one, and log every per-source failure instead of the bare
   "except: continue" that made this failure mode undiagnosable.

Tests: +10 cases (bare/suffixed classification, symbol normalization,
chain fall-through); 22 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@warren618 warren618 merged commit 1e38c8f into HKUDS:main Jul 12, 2026
1 check passed
@warren618

Copy link
Copy Markdown
Collaborator

Merged — thanks for the root-cause work. The digit-length classification is the right disambiguator, and the available-but-empty chain fall-through closes a real silent-drop bug. Verified locally: 22 correlation tests green, AAPL,SPY end-to-end.

warren618 added a commit that referenced this pull request Jul 12, 2026
#457 SDM, #474 Requesty provider, #470 Binance USD-M slice 1,
#472 correlation bare tickers, #467 local loader interval, #469 FastMCP compat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Correlation Matrix fails with "Fetched: []" for the exact ticker format its own hint suggests (AAPL,SPY)

2 participants