55
66import argparse
77import copy
8- import json
98import hashlib
9+ import json
10+ import re
1011from datetime import date
1112from pathlib import Path
1213from typing import Any
@@ -52,6 +53,26 @@ def _baseline_param_set_id(profile: str, params: dict[str, Any]) -> str:
5253 return f"{ profile } _baseline_{ fingerprint } "
5354
5455
56+ def _current_qpk_pin () -> str :
57+ text = (Path (__file__ ).resolve ().parents [1 ] / "qsl.toml" ).read_text (encoding = "utf-8" )
58+ match = re .search (r"QuantPlatformKit\.git@([0-9a-f]{40})" , text )
59+ return match .group (1 ) if match else "unknown"
60+
61+
62+ def _baseline_identity_params (
63+ params : dict [str , Any ],
64+ * ,
65+ synthetic_days : int ,
66+ baseline_result : Any ,
67+ ) -> dict [str , Any ]:
68+ identity = copy .deepcopy (params )
69+ identity ["_baseline_start_date" ] = baseline_result .start_date .isoformat () if baseline_result .start_date else None
70+ identity ["_baseline_end_date" ] = baseline_result .end_date .isoformat () if baseline_result .end_date else None
71+ identity ["_qpk_pin" ] = _current_qpk_pin ()
72+ identity ["_synthetic_days" ] = synthetic_days
73+ return identity
74+
75+
5576def _build_runner (* , profile : str , synthetic_days : int , panel : Any = None , market_history : Any = None ):
5677 return build_backtest_runner (
5778 profile ,
@@ -77,37 +98,38 @@ def run_walk_forward(
7798 raise ValueError (f"unsupported profile={ profile !r} ; supported={ sorted (SUPPORTED_PROFILES )} " )
7899
79100 params = dict (PROFILE_DEFAULTS .get (profile , {"min_history_days" : DEFAULT_MIN_HISTORY_DAYS }))
80- store = PerformanceStore (local_root = store_root or Path ( "/tmp/crypto_wf_store" ) )
101+ store = PerformanceStore (local_root = store_root ) if store_root is not None else PerformanceStore . from_env ( )
81102 orchestrator = BacktestOrchestrator (store = store )
82103
83104 baseline_params = copy .deepcopy (params )
84- baseline_store_params = copy .deepcopy (baseline_params )
85- baseline_runner = _build_runner (
105+ runner = _build_runner (
86106 profile = profile ,
87107 panel = panel ,
88108 market_history = market_history ,
89109 synthetic_days = synthetic_days ,
90110 )
91- baseline_raw = baseline_runner .run (
111+ orchestrator .register_runner ("crypto" , runner )
112+ baseline_probe = orchestrator .run (
92113 profile ,
93- baseline_params ,
114+ domain = "crypto" ,
115+ params = copy .deepcopy (baseline_params ),
116+ param_set_id = "__discarded__" ,
94117 start_date = None ,
95118 end_date = None ,
96119 )
97- baseline = orchestrator .persist_result (
98- baseline_raw ,
99- strategy_profile = profile ,
120+ baseline_store_params = _baseline_identity_params (
121+ baseline_params ,
122+ synthetic_days = synthetic_days ,
123+ baseline_result = baseline_probe ,
124+ )
125+ baseline = orchestrator .run (
126+ profile ,
100127 domain = "crypto" ,
101128 params = baseline_store_params ,
102129 param_set_id = _baseline_param_set_id (profile , baseline_store_params ),
130+ start_date = None ,
131+ end_date = None ,
103132 )
104- runner = _build_runner (
105- profile = profile ,
106- panel = panel ,
107- market_history = market_history ,
108- synthetic_days = synthetic_days ,
109- )
110- orchestrator .register_runner ("crypto" , runner )
111133 wf_params = copy .deepcopy (params )
112134 wf_results = orchestrator .walk_forward (
113135 profile ,
0 commit comments