We built a regime-filter backtester this week. The framework takes a trade log and a market time series, labels each trade with the regime that was visible at entry (no look-ahead), splits into Group A (regime-allowed) and Group B (regime-blocked), and computes the full performance comparison. The headline numbers look excellent.
The Honest Mirror
Standard regime-filter evaluation stops at the headline stats. MaxDD down, Sharpe up — ship it. We added one more metric that most practitioners skip: the net expectancy of Group B, the trades the gate blocked.
Look at the chart again. In 2023 H2, the orange line walks flat while the blue line drops −9.7% and then recovers above its prior high. The gate prevented the drawdown — and the recovery. The orange line ends the backtest lower in absolute P&L. Both facts are true simultaneously. The gate is doing exactly what it was designed to do. The question is whether you want that trade.
This is what honest risk distribution management looks like. Not free alpha. Not a filter that only blocks losing trades. A defensible trade-off with a known cost. If Group B expectancy is negative on your real data, the gate is pure upside. If it is positive, you are paying a defensive premium. Know which one you are buying.
Three Non-Negotiable Design Decisions
These are the choices that determine whether the backtest result is credible. Get them wrong and the numbers are meaningless regardless of how good they look.
regime_known_at='prior_close'. Only switch to same_close when you can confirm the entry decision happened after that day's close.What Your Real Data Will Tell You
The demo runs on synthetic data with a clear bull-bear-bull price path — constructed explicitly so both regimes are well-represented. Real data is messier. When you run this on an actual trade log, split the Group B analysis by strategy.
The three equity strategies in QuantKernel have almost certainly different regime sensitivities. EMA_RSI_MACD is trend-following — bear regimes should genuinely hurt it and Group B EV is likely negative (the gate is helping). ORB is intraday — less sensitive to multi-week regime, Group B EV could go either way. PAIRS is market-neutral by design — a directional EMA200 gate should be least damaging and Group B EV is likely positive (the gate is incorrectly penalizing a non-directional strategy). These are hypotheses. The data will tell you.
// Data Sources
SPY/QQQ daily close for strategic regime: pull from Alpaca data API, export as date,close CSV. VIX term structure (F1/F2) for tactical circuit breaker: CBOE or futures source required — Alpaca does not carry this. If the VIX columns are absent, the tactical layer auto-skips and only the strategic filter runs. Recommended first-pass: deploy strategic EMA filter only, confirm it adds value on real data, then wire in the VIX layer.
The framework is ready. --demo mode runs out of the box on synthetic data. Switch to --trades log.csv --market spy.csv for real data. The honest mirror will tell you what the gate is actually doing — not what you hope it is doing.