"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(risk-xray): raise when surviving symbols have zero total weight (#909)
santhreal58d302617133
diff --git a/agent/backtest/risk_xray.py b/agent/backtest/risk_xray.pyindex e9f91bfe4..18189859d 100644--- a/agent/backtest/risk_xray.py+++ b/agent/backtest/risk_xray.py@@ -136,6 +136,8 @@ def compute_risk_xray(# fully invested basket, and say so.kept_weights = {sym: weights[sym] for sym in kept}total = sum(kept_weights.values())+ if total <= 0:+ raise ValueError("surviving symbols have zero total weight")weights = {sym: value / total for sym, value in kept_weights.items()}warnings.append("weights renormalized over symbols that survived the history filter")diff --git a/agent/tests/test_risk_xray.py b/agent/tests/test_risk_xray.pyindex cd809f851..73d63b0cd 100644--- a/agent/tests/test_risk_xray.py+++ b/agent/tests/test_risk_xray.py@@ -197,6 +197,13 @@ def _stub_fetcher(closes_map: dict[str, list[float]]):return fetch+def test_compute_risk_xray_surviving_symbols_zero_weight():+ closes = pd.DataFrame({+ "AAA": [10.0 + i for i in range(10)],+ "BBB": [5.0] + [None] * 9,+ })+ with pytest.raises(ValueError, match="surviving symbols have zero total weight"):+ compute_risk_xray(closes, {"AAA": 0.0, "BBB": 1.0}, min_history=5)def test_tool_happy_path_equal_weights():tool = PortfolioRiskXrayTool(