fix: 6 workflow flaws detected via full system test

1. CRITICAL FIX - Reports 500 Internal Server Error:
   Root cause: {{}} in onclick was Jinja2 template expression
   Fix: Changed to single {} in reports_index.html onclick

2. Score history chart always empty:
   Root cause: score_update only emitted inside wfv.passed block
   Fix: Emit score_update after every hypothesis run with {promoted:false}
   Fix: Baseline run also pushes to chart via run_complete handler

3. IS gate too strict - optimizer produces 0 candidates forever:
   Root cause: min_calmar=0.35 but best EA has calmar=0.165
   Fix: Two-tier IS check - passes if composite_score improves vs baseline
   (absolute thresholds still apply as alternative pass condition)

4. Findings emitted twice (double UI display):
   Root cause: baseline analyzed once after run, then re-analyzed in iter 1
   Fix: Cache baseline findings, reuse in iteration 1 without re-emitting

5. Chart labels improved:
   'Baseline' for first point, 'It1·h1' for hypothesis runs
   Calmar normalized -0.5..2.0 -> 0..1 for chart display

6. Best score header only updates on actual promotion (not per-hypothesis)
This commit is contained in:
LEGSTECH Optimizer
2026-04-13 03:45:14 +00:00
parent cf8613eb49
commit b70a6760ae
4 changed files with 67 additions and 17 deletions
+28 -6
View File
@@ -38,16 +38,38 @@ class ValidationGate:
# ── Phase 1: IS Check ─────────────────────────────────────────────────────
def run_is_check(self, metrics: RunMetrics) -> GateResult:
def run_is_check(
self,
metrics: RunMetrics,
baseline_score: float = 0.0,
) -> GateResult:
"""
Hard minimum thresholds. All must pass.
Two-tier IS check:
- MUST: enough trades for statistical confidence
- MUST: composite_score is better than baseline (or meets abs thresholds)
Absolute calmar/PF thresholds are logged as warnings but are NOT blockers
when the hypothesis shows clear improvement over baseline.
"""
min_trades_ok = metrics.total_trades >= self.thresh["min_trades"]
abs_pf_ok = metrics.profit_factor >= self.thresh["min_profit_factor"]
abs_calmar_ok = metrics.calmar_ratio >= self.thresh["min_calmar"]
# Score-based relative pass: hypothesis is better than baseline
score_improve_ok = metrics.composite_score > baseline_score * 1.0 + 0.01
# Gate passes if:
# a) Enough trades AND (abs thresholds met OR clearly better than baseline)
passed = min_trades_ok and (
(abs_pf_ok and abs_calmar_ok) # standard absolute pass
or score_improve_ok # OR better than baseline
)
checks = {
"min_trades": metrics.total_trades >= self.thresh["min_trades"],
"min_pf": metrics.profit_factor >= self.thresh["min_profit_factor"],
"min_calmar": metrics.calmar_ratio >= self.thresh["min_calmar"],
"min_trades": min_trades_ok,
"min_pf": abs_pf_ok,
"min_calmar": abs_calmar_ok,
"score_improve": score_improve_ok,
}
passed = all(checks.values())
reason = None
if not passed:
failed = [k for k, v in checks.items() if not v]