Skip to content

Commit 04b8d20

Browse files
Pigbibicodex
andcommitted
feat: support accepted baseline drift stores
Co-Authored-By: Codex <noreply@openai.com>
1 parent 17278db commit 04b8d20

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/quant_platform_kit/strategy_lifecycle/cli.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ def _run_drift(args: argparse.Namespace) -> int:
3939
"quant_platform_kit.strategy_lifecycle.drift_detector",
4040
"run_drift_detection",
4141
)
42-
results = run_drift_detection(domain=args.domain, strategy_profile=args.strategy)
42+
baseline_store = None
43+
if getattr(args, "baseline_local_root", None):
44+
from pathlib import Path
45+
from quant_platform_kit.strategy_lifecycle.performance_store import PerformanceStore
46+
47+
baseline_store = PerformanceStore(local_root=Path(args.baseline_local_root))
48+
results = run_drift_detection(
49+
domain=args.domain,
50+
strategy_profile=args.strategy,
51+
baseline_store=baseline_store,
52+
)
4353
critical_count = sum(1 for item in results if getattr(getattr(item, "status", None), "value", None) == "critical")
4454
review_count = sum(1 for item in results if getattr(getattr(item, "status", None), "value", None) == "review")
4555
_print(f"[drift] {len(results)} strategies checked, {critical_count} critical, {review_count} review")
@@ -233,6 +243,7 @@ def build_parser() -> argparse.ArgumentParser:
233243
drift.add_argument("--strategy", default=None)
234244
drift.add_argument("--no-alerts", action="store_true")
235245
drift.add_argument("--dry-run-alerts", action="store_true")
246+
drift.add_argument("--baseline-local-root", default=None)
236247
drift.set_defaults(func=_run_drift)
237248

238249
optimize = subparsers.add_parser("optimize", help="Run parameter optimization for one strategy.")

src/quant_platform_kit/strategy_lifecycle/drift_detector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ def run_drift_detection(
134134
policy: DriftPolicy | None = None,
135135
fail_on_empty: bool = True,
136136
store: PerformanceStore | None = None,
137+
baseline_store: PerformanceStore | None = None,
137138
) -> list[DriftResult]:
138-
"""Run drift detection for all strategies in a domain."""
139+
"""Run drift detection, optionally reading accepted baselines from another store."""
139140
store = store or PerformanceStore.from_env()
141+
baseline_store = baseline_store or store
140142
policy = policy or DriftPolicy.load_default()
141143

142144
from quant_platform_kit.strategy_lifecycle.return_collector import ReturnCollector
@@ -158,7 +160,7 @@ def run_drift_detection(
158160
if snapshot is None:
159161
missing_snapshots += 1
160162
continue
161-
backtest = store.load_latest_backtest(domain, profile)
163+
backtest = baseline_store.load_latest_backtest(domain, profile)
162164
previous = store.load_latest_drift(domain, profile)
163165
result = detect_drift(snapshot, backtest=backtest, policy=policy,
164166
previous_status=previous.status if previous else None)

0 commit comments

Comments
 (0)