Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(sdm): stop treating overlapping IC windows as an unchanged ratio

Lanre Shittuecaa431a2a11
diff --git a/agent/src/strategy_store/metrics.py b/agent/src/strategy_store/metrics.py
index 01d94ffee..ec2fba6c2 100644
--- a/agent/src/strategy_store/metrics.py
+++ b/agent/src/strategy_store/metrics.py
@@ -73,11 +73,17 @@ def compute_decay_metrics(
result["baseline_ic_mean"] = round(baseline_mean, 6)
result["rolling_ic_mean"] = round(rolling_mean, 6)
+ # baseline_ics and rolling_ics are the oldest/newest 5 entries, so
+ # with fewer than 10 they share observations -- at 3-9 entries
+ # they're the same window read twice, making ic_ratio exactly 1.0
+ # regardless of how much the IC actually moved. Require the two
+ # windows to be disjoint before trusting their ratio.
+ #
# 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:
+ if baseline_mean > 0 and len(ic_values) >= len(baseline_ics) + len(rolling_ics):
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.py
index 16df74be5..f6612dc62 100644
--- a/agent/tests/test_sdm_finite_metrics.py
+++ b/agent/tests/test_sdm_finite_metrics.py
@@ -69,6 +69,30 @@ def test_ic_ratio_still_computed_for_a_positive_baseline():
assert metrics["ic_ratio"] == pytest.approx(0.5)
[email protected]("n", [3, 4, 5, 6, 9])
+def test_ic_ratio_is_none_when_baseline_and_rolling_windows_overlap(n):
+ """With fewer than 10 entries, the oldest-5 and newest-5 windows share
+ observations -- at 3-9 entries they're the same data read twice, which
+ made ic_ratio exactly 1.0 no matter how much the IC actually moved. A
+ strategy whose IC just collapsed from 0.08 to 0.001 must not come back
+ reading as unchanged."""
+ history_newest_first = [BenchResult(ic_mean=0.001)] + [
+ BenchResult(ic_mean=0.08) for _ in range(n - 1)
+ ]
+
+ metrics = compute_decay_metrics(history_newest_first)
+
+ assert metrics["ic_ratio"] is None
+
+
+def test_ic_ratio_computed_once_windows_stop_overlapping():
+ history_newest_first = [BenchResult(ic_mean=v) for v in [0.001] + [0.08] * 9]
+
+ metrics = compute_decay_metrics(history_newest_first)
+
+ assert metrics["ic_ratio"] is not None
+
+
@pytest.mark.parametrize("backend", ["memory", "sqlite"])
@pytest.mark.parametrize("field", ["ic_mean", "sharpe"])
@pytest.mark.parametrize("invalid", [math.nan, math.inf, -math.inf])