"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(sdm): exclude non-finite observations from decay metrics
JasonWu8b261fd24812
diff --git a/README.md b/README.mdindex 3fcb72acb..ca3547953 100644--- a/README.md+++ b/README.md@@ -1945,7 +1945,7 @@ Vibe-Trading is part of the **[HKUDS](https://github.com/HKUDS)** agent ecosyste| **Options Lab** | Vol surface, Greeks dashboard, payoff/scenario explorer | Analytic payoff/scenario tool **Shipped**; surface/dashboard Planned || **Portfolio Studio** | Risk x-ray, constraints, turnover-aware optimizer, rebalance notes | Turnover-aware optimizer **Shipped 0.1.11**; rest Planned || **Alpha Zoo** | 462 pre-built alphas (Qlib 158 + Kakushadze 101 + GTJA 191 + academic + fundamental) with one-line bench, agent integration, and Web UI | **Shipped 0.1.8**, extended through 0.1.12 |-| **Strategy Development Manager** | Register papers / broker research as factors & strategies with a persistent store + automated IC/Sharpe decay lifecycle | **Shipped 0.1.11** |+| **Strategy Development Manager** | Register papers / broker research as factors & strategies with a persistent store + automated IC/Sharpe decay lifecycle; each evaluated metric requires at least three finite observations | **Shipped 0.1.11** || **Correlation Regime** | Edge-density + hysteresis regime timeline layered on `/correlation` — spot when markets fuse into one bloc | **Shipped 0.1.12** || **Research Delivery** | Scheduled briefs and live research sessions through Slack / Telegram / email-style IM channels | Scheduler + IM Runtime Shipped || **Community** | Shareable skills, presets, and strategy cards | Exploring |diff --git a/agent/src/strategy_store/metrics.py b/agent/src/strategy_store/metrics.pyindex 462811f54..ee765abbc 100644--- a/agent/src/strategy_store/metrics.py+++ b/agent/src/strategy_store/metrics.py@@ -7,6 +7,7 @@ bench-history list.from __future__ import annotations+from math import isfinitefrom typing import Any_DECAY_INPUT_KEYS = ("ic_ratio", "rolling_ir", "ic_positive_ratio", "rolling_sharpe")@@ -35,7 +36,8 @@ def compute_decay_metrics(Returns:Dict with keys: ``baseline_ic_mean``, ``rolling_ic_mean``, ``ic_ratio``,``rolling_ir``, ``ic_positive_ratio``, ``rolling_sharpe``, ``baseline_sharpe``.- Values are ``None`` when insufficient data (< 3 non-None entries).+ Values are ``None`` when insufficient data (< 3 finite entries).+ NaN and infinities are treated as missing observations, like ``None``."""result: dict[str, float | None] = {"baseline_ic_mean": None,@@ -49,8 +51,14 @@ def compute_decay_metrics(chronological = list(reversed(bench_history))- ic_values = [r.ic_mean for r in chronological if r.ic_mean is not None]- sharpe_values = [r.sharpe for r in chronological if r.sharpe is not None]+ ic_values = [+ r.ic_mean+ for r in chronological+ if r.ic_mean is not None and isfinite(r.ic_mean)+ ]+ sharpe_values = [+ r.sharpe for r in chronological if r.sharpe is not None and isfinite(r.sharpe)+ ]has_ic = len(ic_values) >= 3has_sharpe = len(sharpe_values) >= 3diff --git a/agent/tests/test_sdm_finite_metrics.py b/agent/tests/test_sdm_finite_metrics.pynew file mode 100644index 000000000..f1ce1fcad--- /dev/null+++ b/agent/tests/test_sdm_finite_metrics.py@@ -0,0 +1,85 @@+"""Non-finite bench observations must not drive SDM health transitions."""++import json+import math++import pytest++from src.strategy_store.metrics import compute_decay_metrics+from src.strategy_store.models import (+ Artifact,+ ArtifactStatus,+ ArtifactType,+ BenchResult,+)+from src.strategy_store.sqlite_store import SqliteStrategyStore+from src.strategy_store.store import InMemoryStrategyStore+from src.tools.sdm_decay_scan_tool import SdmDecayScanTool+from src.tools.sdm_status_tool import SdmStatusTool++[email protected]("field", ["ic_mean", "sharpe"])[email protected]("invalid", [math.nan, math.inf, -math.inf])+def test_nonfinite_observations_do_not_satisfy_minimum_history(field, invalid):+ history = [BenchResult(**{field: value}) for value in [0.1, invalid, 0.2]]++ assert all(value is None for value in compute_decay_metrics(history).values())++[email protected]("field", ["ic_mean", "sharpe"])+def test_nonfinite_observations_match_missing_observations(field):+ values = [0.01, math.nan, 0.04, math.inf, 0.02, -math.inf, 0.03]+ history = [BenchResult(**{field: value}) for value in values]+ missing = [+ BenchResult(**{field: value if math.isfinite(value) else None})+ for value in values+ ]++ assert compute_decay_metrics(history) == compute_decay_metrics(missing)+++def test_missing_ic_does_not_discard_finite_sharpe():+ metrics = compute_decay_metrics(+ [BenchResult(ic_mean=math.nan, sharpe=0.0) for _ in range(3)]+ )++ assert metrics["ic_positive_ratio"] is None+ assert metrics["rolling_sharpe"] == 0.0++[email protected]("backend", ["memory", "sqlite"])[email protected]("field", ["ic_mean", "sharpe"])[email protected]("invalid", [math.nan, math.inf, -math.inf])+def test_tools_report_insufficient_data_without_changing_monitoring_state(+ tmp_path, monkeypatch, backend, field, invalid+):+ store = (+ InMemoryStrategyStore()+ if backend == "memory"+ else SqliteStrategyStore(db_path=tmp_path / "sdm.db")+ )+ monkeypatch.setattr("src.tools.sdm_decay_scan_tool._get_store", lambda: store)+ monkeypatch.setattr("src.tools.sdm_status_tool._get_store", lambda: store)+ artifact_id = store.register_artifact(+ Artifact(+ id="",+ name="nonfinite-bench",+ type=ArtifactType.STRATEGY if field == "sharpe" else ArtifactType.FACTOR,+ universe="test",+ status=ArtifactStatus.MONITORING,+ )+ )+ for _ in range(3):+ store.record_bench(BenchResult(artifact_id=artifact_id, **{field: invalid}))++ status = json.loads(+ SdmStatusTool().execute(action="decay_check", artifact_id=artifact_id)+ )+ scan = json.loads(SdmDecayScanTool().execute())++ assert status["status"] == scan["status"] == "ok"+ assert status["signal"] == "insufficient_data"+ assert scan["summary"]["insufficient_data"] == 1+ assert scan["transitions_applied"] == 0+ assert store.get_artifact(artifact_id).status == ArtifactStatus.MONITORING+ assert list(store.get_decay_history(artifact_id)) == []