Skip to content

Feat/correlation heatmap#64

Merged
warren618 merged 4 commits intoHKUDS:mainfrom
MB-Ndhlovu:feat/correlation-heatmap
Apr 30, 2026
Merged

Feat/correlation heatmap#64
warren618 merged 4 commits intoHKUDS:mainfrom
MB-Ndhlovu:feat/correlation-heatmap

Conversation

@MB-Ndhlovu
Copy link
Copy Markdown
Contributor

Summary

  • Add a Correlation Matrix page (/correlation) displaying a heatmap of pairwise Pearson/Spearman correlations across multiple assets
  • Introduce a backend GET /correlation endpoint with a reusable compute_correlation_matrix() engine that auto-infers market (crypto, a-share, us_equity, hk_equity) from ticker symbols
  • Add ECharts heatmap component + 9 unit tests covering market inference and matrix symmetry/diagonal correctness

Why

Vibe-Trading supports multi-asset strategies (crypto, A-shares, US/HK equities) but has no way to visually inspect correlation relationships between assets before building a strategy. This feature closes that gap by giving users a first-pass correlation dashboard — a standard starting point for any quant workflow.

Changes

  • agent/backtest/correlation.py — Core engine: compute_correlation_matrix(codes, days, method), infer_market(), CROSS_MARKET_LOADER registry spanning all 4 supported markets
  • agent/api_server.pyGET /correlation endpoint accepting codes, days (7–365), method (pearson|spearman)
  • agent/tests/test_correlation.py — 9 tests: market inference (7 cases) + matrix symmetry + diagonal-is-one
  • frontend/src/pages/Correlation.tsx — New page: ticker input, method selector, loading/error states, ECharts heatmap, export
  • frontend/src/components/charts/CorrelationMatrix.tsx — Reusable heatmap component with dark-mode theming
  • frontend/src/lib/echarts.ts — Registered HeatmapChart + VisualMapComponent
  • frontend/src/lib/i18n.tsx — Added 6 i18n keys (correlation, correlationDesc, assetCodes, lookbackDays, corrMethod, noCorrelationData)
  • frontend/src/router.tsx — Route { path: "/correlation", element: wrap(Correlation) }
  • frontend/src/components/layout/Layout.tsx — Nav entry for /correlation

Test Plan

  • Existing tests pass (pytest --ignore=agent/tests/e2e_backtest --tb=short -q)
  • New tests added (agent/tests/test_correlation.py, 9 passing)
  • Tested manually: open /correlation, enter BTC-USDT,ETH-USDT, click Load → heatmap renders

Checklist

  • No changes to protected areas (src/agent/, src/session/, src/providers/) without prior discussion
  • No hardcoded values (API keys, file paths, magic numbers)
  • Code follows CONTRIBUTING.md guidelines
  • Documentation updated (user-facing page with direct UI)

table.box attribute doesn't exist in this rich version.
table uses default ASCII border instead.
Backend:
- agent/backtest/correlation.py: correlation engine (Pearson/Spearman,
  multi-market loader support, auto market inference from ticker)
- agent/api_server.py: +GET /correlation endpoint
- agent/tests/test_correlation.py: 9 tests (infer_market + core matrix)

Frontend:
- frontend/src/pages/Correlation.tsx: new /correlation page
- frontend/src/components/charts/CorrelationMatrix.tsx: ECharts heatmap
- frontend/src/lib/echarts.ts: register HeatmapChart + VisualMapComponent
- frontend/src/router.tsx: +/correlation route
- frontend/src/components/layout/Layout.tsx: +nav entry
- frontend/src/lib/i18n.tsx: +i18n keys

# Conflicts:
#	frontend/src/components/layout/Layout.tsx
#	frontend/src/router.tsx
Copy link
Copy Markdown
Collaborator

@warren618 warren618 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. The correlation dashboard direction is useful, but this PR is not ready to merge yet. Please address these blockers:

  1. Frontend CI is failing: frontend/src/router.tsx has an extra ); after the Correlation lazy import, causing TS1128: Declaration or statement expected.
  2. CorrelationMatrix label formatting is incorrect for ECharts heatmap data. The label formatter currently treats params.value as a number, but heatmap values are arrays like [xIndex, yIndex, value]; this will break label rendering. Please read the third tuple element.
  3. infer_market() misclassifies HK tickers with leading zeroes such as 0700.HK / 0005.HK as A-share because the A-share numeric prefix checks run before the .HK suffix check. HK suffix handling should happen first, and tests should cover leading-zero HK tickers.
  4. The window argument in _rolling_correlation_matrix() is effectively ignored. The API returns window: days, but the matrix is computed over the full overlapping fetched history instead of the selected trailing window. Please apply the intended trailing window and add a regression test.

After fixing, please rerun the frontend build and the correlation tests. Once CI is green and the above correctness issues are covered, this can be reviewed again.

Copy link
Copy Markdown
Collaborator

@warren618 warren618 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review blockers have been addressed: router build is fixed, heatmap label formatting reads the tuple value, HK leading-zero inference is covered, rolling window is applied and tested, and CI is green.

@warren618 warren618 merged commit 0b95d68 into HKUDS:main Apr 30, 2026
1 check passed
@warren618
Copy link
Copy Markdown
Collaborator

Merged, thanks for the contribution. The follow-up commit addressed the review blockers around router build, heatmap label formatting, HK leading-zero market inference, and rolling-window behavior; CI was green before merge.

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.

2 participants