"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(sdm): fix IC ratio sign flip for a negative baseline
Lanre Shittu30d79f233dfd
diff --git a/agent/src/strategy_store/metrics.py b/agent/src/strategy_store/metrics.pyindex ee765abbc..01d94ffee 100644--- a/agent/src/strategy_store/metrics.py+++ b/agent/src/strategy_store/metrics.py@@ -73,7 +73,11 @@ def compute_decay_metrics(result["baseline_ic_mean"] = round(baseline_mean, 6)result["rolling_ic_mean"] = round(rolling_mean, 6)- if baseline_mean != 0:+ # baseline_mean > 0, not != 0: with a negative baseline, dividing+ # two negatives gives a positive ratio, so a rolling IC that got+ # much MORE negative (real decay) produces a large ic_ratio that+ # the healthy/warning/decayed thresholds read as improvement.+ if baseline_mean > 0:result["ic_ratio"] = round(rolling_mean / baseline_mean, 4)if len(rolling_ics) > 1:diff --git a/agent/tests/test_sdm_finite_metrics.py b/agent/tests/test_sdm_finite_metrics.pyindex f1ce1fcad..16df74be5 100644--- a/agent/tests/test_sdm_finite_metrics.py+++ b/agent/tests/test_sdm_finite_metrics.py@@ -47,6 +47,28 @@ def test_missing_ic_does_not_discard_finite_sharpe():assert metrics["rolling_sharpe"] == 0.0+def test_ic_ratio_is_none_for_a_negative_baseline():+ """Dividing two negative IC means gives a positive ratio, so a rolling+ IC that got MUCH more negative than an already-negative baseline (real+ decay) would otherwise produce a large positive ic_ratio that reads as+ healthy improvement instead of decay."""+ history_newest_first = [BenchResult(ic_mean=v) for v in [-0.05] * 5 + [-0.001] * 5]++ metrics = compute_decay_metrics(history_newest_first)++ assert metrics["baseline_ic_mean"] == pytest.approx(-0.001)+ assert metrics["rolling_ic_mean"] == pytest.approx(-0.05)+ assert metrics["ic_ratio"] is None+++def test_ic_ratio_still_computed_for_a_positive_baseline():+ history_newest_first = [BenchResult(ic_mean=v) for v in [0.02] * 5 + [0.04] * 5]++ metrics = compute_decay_metrics(history_newest_first)++ assert metrics["ic_ratio"] == pytest.approx(0.5)++@pytest.mark.parametrize("backend", ["memory", "sqlite"])@pytest.mark.parametrize("field", ["ic_mean", "sharpe"])@pytest.mark.parametrize("invalid", [math.nan, math.inf, -math.inf])