"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix: Keep correlation density unknown when constant or missing series make asset pairs unmeasurable.
Rudy Celekli7fcc22bb5012
diff --git a/README.md b/README.mdindex b359b3ac8..92c0db9fa 100644--- a/README.md+++ b/README.md@@ -368,7 +368,7 @@ It is designed for research, simulation, and backtesting — and, when you choos| **Put research into IM channels** | Run the same session runtime through WebSocket, Telegram, Slack, Discord, Matrix, WhatsApp, Signal, QQ/NapCat, WeChat/WeCom, Feishu/Lark, DingTalk, Teams, email, and Mochat with CLI, REST, and Web UI controls. || **Ship usable artifacts** | Reports, TradingView Pine Script, TDX, MetaTrader 5, MCP tools, and later research sessions. || **Bench a pre-built alpha zoo** | One-line IC + alive/reversed/dead categorisation across 462 alphas (Qlib 158 + Kakushadze 101 + GTJA 191 + academic + PIT-safe fundamental) on your universe. |-| **Spot correlation regimes** | An edge-density + hysteresis timeline on the `/correlation` surface showing when markets fuse into one bloc — descriptive risk context, not a signal. |+| **Spot correlation regimes** | An edge-density + hysteresis timeline on the `/correlation` surface showing when markets fuse into one bloc — descriptive risk context, not a signal. Undefined pair correlations keep edge density unknown, so constant-price histories cannot claim a measured zero density. |---diff --git a/agent/backtest/regime.py b/agent/backtest/regime.pyindex 6e77ed640..cf07aae5a 100644--- a/agent/backtest/regime.py+++ b/agent/backtest/regime.py@@ -49,7 +49,11 @@ def compute_edge_density(density = pd.Series(np.nan, index=returns.index)for i in range(corr_window, len(returns) + 1):corr = returns.iloc[i - corr_window:i].corr().abs().to_numpy()- density.iloc[i - 1] = float((corr[upper_mask] >= edge_threshold).sum()) / n_pairs+ pair_corr = corr[upper_mask]+ # Undefined pairs (e.g. a constant asset) are missing evidence, not+ # non-edges. Keep density unknown until the whole basket is measurable.+ if np.isfinite(pair_corr).all():+ density.iloc[i - 1] = float((pair_corr >= edge_threshold).sum()) / n_pairsreturn densitydiff --git a/agent/tests/test_regime_undefined_correlation_regressions.py b/agent/tests/test_regime_undefined_correlation_regressions.pynew file mode 100644index 000000000..00b4dc92d--- /dev/null+++ b/agent/tests/test_regime_undefined_correlation_regressions.py@@ -0,0 +1,23 @@+import numpy as np+import pandas as pd+from backtest.regime import compute_edge_density, detect_regimes+++def test_constant_asset_does_not_claim_zero_correlation_density():+ returns = pd.DataFrame({"flat": [0.01] * 4, "variable": [1.0, 2.0, 1.0, 3.0]})+ density = compute_edge_density(returns, corr_window=3)+ assert density.isna().all()+++def test_incomplete_pair_matrix_is_unknown_not_a_smaller_density():+ returns = pd.DataFrame(+ {"flat": [0.01] * 4, "a": [1.0, 2.0, 1.0, 3.0], "b": [1.0, 2.0, 1.0, 3.0]}+ )+ assert compute_edge_density(returns, corr_window=3).isna().all()+++def test_valid_low_density_still_exits_and_unknown_density_keeps_state():+ returns = pd.DataFrame({"a": [1.0, 2.0, 1.0], "b": [1.0, 2.0, 1.0]})+ assert compute_edge_density(returns, corr_window=3).iloc[-1] == 1.0+ actual = detect_regimes(pd.Series([1.0, np.nan, 0.0]), smooth_window=1)+ assert actual["fused"].tolist() == [1, 1, 0]