Skip to content

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

Description

@yxhuang

Tried the Correlation tab with AAPL,SPY — the format the input hint itself suggests (zh-CN locale: "逗号分隔的标的代码,如 BTC-USDT,ETH-USDT,AAPL,SPY", same in ja/ko/ar) — and every request fails with:

Could not fetch price data for at least 2 assets. Fetched: []

Description

compute_correlation_matrix (agent/backtest/correlation.py) passes the user's raw codes straight to the data loaders, but the loaders key US/HK/A-share instruments by the exchange-suffixed symbol (AAPL.US / 0700.HK / 600000.SH). A bare AAPL fails the yahoo loader's _is_supported() check (requires .US/.HK/.NS/.BO), returns an empty dict — and since that's not an exception, the yfinance fallback never fires either. Verified: AAPL.US → 103 rows, bare AAPL → nothing.

Digging further, two more layers make this worse:

  1. infer_market's prefix heuristics misroute many symbols: bare 0700 (Tencent) → a_share, 9988 (Alibaba) → us_equity, 300750 (CATL, ChiNext) → hk_equity, and even suffixed 830799.BJus_equity (no .SH/.SZ/.BJ suffix handling at all).
  2. The fetch loop stops at the first available loader, not the first that returns data — when eastmoney (first in the HK chain) hits a network error, the asset silently vanishes even though yahoo (next in chain) can serve it.
  3. All failures are swallowed by bare except: continue, so the only symptom is Fetched: [] with no clue why.

Steps to Reproduce

  1. Open the Correlation tab (/correlation).
  2. Enter AAPL,SPY (as the hint text suggests) and compute.
  3. Request fails with Could not fetch price data for at least 2 assets. Fetched: [].

Same happens for bare A-share codes (600000,000001) and bare HK codes (0700,9988).

Interface

Web UI Correlation tab / GET /correlation?codes=AAPL,SPY (the API docstring example BTC-USDT,ETH-USDT,SPY fails the same way).

Note: en.json's hint was at some point changed to suffixed A-share examples (000001.SZ,600519.SH,000858.SZ), but zh-CN/ja/ko/ar still show the bare form — and either way, bare tickers arguably should work. Happy to submit a fix (have one working).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions