Audit fixes: mixed-regime bias, live==backtest session parity, parallel replay

Fix 1 — mixed-"trending" regime (ADX strong, EMAs unaligned) was
hard-coded bullish in 5 sites: RSI reinterpretation used the uptrend
playbook (RSI 38-55 -> STRONG_BUY conf 75), BUY-only confidence
bonuses, BUY-only extension penalties, no counter-trend penalty.
Now: extremes-only RSI (as transitioning), no directional bonuses,
symmetric extension penalties. 6yr validation: H1 +67.2->+61.9R
(mixed skew 16B/11S -> 4B/7S), H4 +31.6->+27.5R (the 4 bias BUYs),
M15 +152.6->+154.7R, M5 +207.1->+206.1R with maxDD 28.7->24.3R.
The ~8R aggregate give-back is bull-market subsidy from the bug.

Fix 2 — live session filter now applies the EXACT replay-loop
predicate (session window + blocked hours on the signal bar's CLOSE
time, from the bar timestamp not wall clock). Replaces a wall-clock
filter gated on a "XAU STRATEGY" marker that no code writes, which
made live diverge from every validated book.

Fix 3 — delete dead _check_xau_oversold_bounce and
_generate_xau_trade_setup (unreachable; the latter hardcoded BUY and
skipped the spread/RR gates).

Backtester: parallel bar replay via forked workers (--workers,
default auto = cores-2 capped 12). Per-bar evaluation is pure; the
entry cooldown is applied in an ordered phase-2 pass. Proven
byte-identical to sequential on the same window; ~300 -> 1030-1680
bars/s (6yr M5: ~26min -> 5-8min). --workers 1 = sequential path.

Tests: 179 passed (new mixed-regime RSI regression test).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Harwinder Sekhon
2026-07-11 22:57:37 -04:00
parent f3ba4d56a3
commit 53d8bc4390
5 changed files with 282 additions and 287 deletions
+20
View File
@@ -2025,6 +2025,26 @@ def _():
assert config.xau_strategy.enabled is True
@test("Mixed 'trending' regime: RSI mid-zone is neutral, extremes only")
def _():
from engine import TechnicalEngine, TechnicalAnalysis, IndicatorSignal
from config import TechnicalConfig
eng = TechnicalEngine(TechnicalConfig())
# Pre-fix, mixed "trending" used the uptrend playbook: RSI 45 became
# STRONG_BUY conf 75 in a regime whose EMAs disagree on direction.
for rsi_v, expected in ((45.0, SignalStrength.NEUTRAL),
(75.0, SignalStrength.SELL),
(25.0, SignalStrength.BUY)):
res = TechnicalAnalysis(symbol="XAU/USD", timeframe="1h", timestamp="t")
res.market_regime = "trending"
res.indicators["rsi"] = IndicatorSignal(
name="RSI", value=rsi_v, signal=SignalStrength.NEUTRAL,
confidence=30, description="", weight=1.5)
eng._reinterpret_rsi_for_regime(res)
got = res.indicators["rsi"].signal
assert got == expected, f"RSI {rsi_v} in mixed regime → {got}, want {expected}"
@test("XAU regime filter: blocked regime never yields actionable quality")
def _():
from pair_signals.xauusd import make_config