Skip to content

View original

BtcCmInverseFourHourRegimeGatedReversionLS

Hypotheses

BTC COIN-M Inverse Perp Regime-Gated Mean-Reversion, Long-Short (Single-Leg BTCUSD_PERP.BINANCE_CM, 4H Bars, Fade Z-Score Extremes ONLY in Low-Trend/Ranging Regimes — Exploits COIN-M's 0.06% RT Fee, the Lowest-Cost Futures Venue, to Make a Moderate MR Edge Fee-Viable Where USD-M Cannot, 2-Parameter)

Hypotheses

A LONG-SHORT, SINGLE-LEG mean-reversion on the BTC coin-margined inverse perpetual (BTCUSD_PERP.BINANCE_CM, 4H bars). Its thesis is EXECUTION-COST, not a new signal: identical z-score mean-reversion is fee-marginal on BINANCE USD-M (0.10% RT → needs >0.15%/trade) but comfortably viable on COIN-M (0.06% RT → needs only >0.10%/trade). COIN-M is the factory's most under-represented venue that still has clean single-name data (3.1% vs 5% target), and L20 explicitly permits SINGLE-LEG CM on BTC OHLCV (the data_unavailable deaths were MULTI-asset CM funding baskets on thin alts — this is the flagship BTCUSD_PERP contract with multi-year daily/4H history on Binance Vision, which the on-demand collector pulls for BINANCE_CM). It deliberately avoids every graveyard: NOT funding-signal (L13), NOT a rank-rotate basket (L12), NOT liquidation-feed (L3), NOT options (L23), NOT Hyperliquid (L11), NOT cross-venue carry (L1), and NOT the 15m intraday-reversion timeout class (the sibling CM 15m death was sub-hourly bars — this uses 4H, coarser and reliably catalogued). The distinguishing filter vs the fee_edge MR graveyard: mean-reversion fires ONLY in low-trend/ranging regimes (where MR actually has positive expectancy) and stands aside in trends (where MR gets run over) — exactly the confounder that killed the naive single-bar-overreaction and pivot-reversion attempts. Only 2 optimizable parameters (entry_z, regime_threshold) to keep optimizer best-of-N inflation below the true edge. Fills the COIN-M venue gap AND adds long-short/market-facing diversity to an 85%-long-only book.

Hypotheses

QA classified this as a risk-management/sizing code defect — a second consecutive full liquidation (liquidated=true, -100%, return_skew -5.27, kurtosis 127.6) despite a claimed 0.30x gross cap and 2.5% stop — and that diagnosis is correct: those numbers make -100% arithmetically impossible IF the cap and stop actually bind, so at least one did not. Instead of re-asserting the claim, I made the bound hold four independent ways, any one of which caps a single trade far below the account. (1) The previous iteration delegated ALL stop-loss duty to the venue bracket leg and deliberately left should_exit with no price stop; if that leg was never created, never rested or was cancelled, the position had no stop at all. should_exit now has a hard 5% bar-close disaster stop — strictly WIDER than the 2.5% venue stop, so it is a different level and cannot double-exit the bracket; it is purely a backstop for a missing leg. (2) contracts_for_notional's answer is now clamped against a locally computed floor(usd_notional / $100) using the documented BTCUSD_PERP contract size, so the position cannot exceed the intended notional whatever multiplier the helper used. (3) The linear fallback qty = usd_notional/price is REMOVED on BINANCE_CM (it returns 0 instead) — submitting coin units against a USD-denominated inverse contract is exactly the L14/L66 mis-sizing failure; the linear path is retained only for the non-inverse mock instrument so Layer 2 keeps passing. (4) max_gross_frac 0.30 -> 0.10 and risk_pct 0.0075 -> 0.004, with notional computed off min(current, INITIAL) equity so exposure never compounds — at a 10% gross cap and 1x leverage, a position losing its entire value costs ~10% of the account. I also fixed QA's churn finding: the strategy disarms on entry and only re-arms once |z| returns inside the exit band while flat, so one stretch produces one fade instead of the next bar immediately re-fading the same still-stretched condition (345 trades at PF 0.85 was a steady bleed eroding the COIN-M fee advantage the thesis rests on). The signal, ADX regime gate, fade polarity and warmup are untouched, so the earlier passing layers stay green; QA's static-analyzer flag on self._closes.append() is confirmed a false positive (deque with maxlen=z_period, O(1) per bar).

Hypotheses

Negative expectancy on a reliable 230-trade sample: avg_trade_return_pct = -0.058% (below ZERO, not just below the ~0.10% COIN-M floor the thesis depends on), PF 0.95, total_return -7.06%, Sharpe -0.37, IR -0.84. The strategy's sole premise is that COIN-M's low 0.06% RT fee makes a moderate MR edge fee-viable, but there is no positive gross edge for the fee advantage to rescue — the regime gate is negative in all three vol terciles. This is a fee/edge abandonment, not a code fix: optimizing entry_z/regime_threshold cannot manufacture positive expectancy the near-frictionless-fee version already failed to reveal (L55/L22/L27). abandon_class=negative_expectancy.

Implementation

Long-short single-leg mean reversion on the BTC coin-margined inverse perpetual (BTCUSD_PERP.BINANCE_CM, 4H bars). The signal is the close's z-score against a 20-bar rolling mean and population stdev, computed every bar in natural sigma units. Fades are taken ONLY while Wilder ADX(14) <= regime_threshold (ranging); in a trend the strategy stands fully aside. SHORT at z >= entry_z, LONG at z <= -entry_z, at most one fade per stretch (the strategy disarms on entry and only re-arms once |z| decays back inside the exit band while flat). Every entry is a venue-managed bracket (2.5% stop / 3.5% take-profit, OUO-linked, firing intra-bar) backed by a wider 5% code-level disaster stop, plus a mean-reversion signal exit and an 18-bar time cap. Sizing risks 0.4% of equity against the bracket stop, hard-capped at 10% of (de-compounded) equity gross notional, floored to whole $100 inverse contracts with an independent contract-count clamp; no linear fallback on the CM venue.

Verification Results

Verification failed (Layer 4 — QA review) [class=code_defect]: - [edge_concern] Cannot be assessed yet: the mean-reversion mechanism's viability is unknowable while the account liquidates. Aggregate PF 0.85 / avg_trade_return_pct -0.186% include the -100% tail, so they neither confirm nor clear the fade. Re-evaluate the edge ONLY after a sandbox run with liquidated=false and losses actually bounded by the stop. - FULL ACCOUNT LIQUIDATION AGAIN. The sandbox reports liquidated=true, total_return -100.0, max_drawdown 100.0 (liquidation 2025-10-06) with metrics_reliable=TRUE and return_skew -5.27 / kurtosis 127.6 (one dominant catastrophic trade). This is the SECOND consecutive wipeout and directly falsifies the iteration's central claim that the 2.5% venue bracket stop + 0.30x gross cap + 0.75% per-trade risk make a -100% outcome 'structurally impossible.' A position capped at 0.30x equity gross at 1x leverage with a 2.5% stop should lose at most ~0.75% of equity per trade; a -100% result means the protective legs did NOT bound the catastrophic trade. The claimed risk controls are not actually bounding loss — a risk-management/sizing code defect, not an edge/parameterization issue. A strategy that can destroy the account is a hard block. - Re-entry churn: 345 trades / ~1845 days, win_rate 0.50, PF 0.85 — a steady bleed independent of the liquidation tail. After a venue bracket stop closes a position, _sync_position_state() clears _in_pos and the next bar can immediately re-fade the same still-stretched, still-ranging condition. Erodes the COIN-M fee advantage the thesis rests on. - Static analyzer flagged unbounded growth on self._closes.append(). False positive: _closes is a deque(maxlen=z_period).

Verification Results

No functional fix needed; rename to a non-framework helper name if the override is not intended to feed the base warmup path.

Verification Results

min_bars_required() shadows a framework method (static-analysis warning). Impact is benign here because calculate_signal enforces its own warmup guards internally (z only computed once len(_closes) >= z_period; _ranging only true once _adx_seed_n >= adx_period), so warmup is correctly gated regardless of whether the base uses this override.

Verification Results

None required; the backstop is a reasonable belt-and-suspenders and the sizing caps (max_gross_frac 0.10, de-compounded base equity) independently bound single-trade loss.

Verification Results

The code-level disaster stop (5%) and the venue bracket stop (2.5% SL / 3.5% TP) are correctly at DIFFERENT levels, so this is NOT a double-exit (check 17b satisfied). This is a defensible backstop for the missing-bracket-leg failure mode that liquidated prior iterations; sandbox now shows liquidated=false with max_drawdown 9.83%, consistent with the four-mechanism cap holding. Flagged only as informational — the disaster stop depends on the venue actually resting the bracket legs, which the QA cannot verify from code alone.

Verification Results

Unoptimized sandbox (entry_z=2.0, regime_threshold=22) is net-negative: total_return -7.06%, Sharpe -0.37, PF 0.94, and avg_trade_return_pct -0.067% over 230 trades — i.e. the per-trade return is BELOW zero, not merely below the ~0.10% COIN-M viability floor the whole thesis rests on. The regime gate did not visibly help (all three vol terciles negative: calm -1.75%, normal -5.30%, stressed -0.94%) and benchmark IR is -0.84. This is a smoke test on a single default parameter draw over a truncated window, so it does not settle edge — but the mechanism's central claim (that COIN-M's low fee makes a moderate MR edge viable) is not yet demonstrated by any positive per-trade number. Analyst should check, after optimization, whether entry_z/regime_threshold produce a positive avg_trade_return_pct that clears the ~0.06% RT cost with margin; if the optimizer cannot find one, this is a fee/edge abandonment, not a code fix.

Backtest Review

Faithfully implemented: single-leg BTCUSD_PERP.BINANCE_CM, 4H bars, correct inverse-contract sizing, regime-gated fade with the right (contrarian) sign, 230 trades over 2109 days is a reliable/measurable sample (metrics_reliable=true).

Backtest Review

No sizing/liquidation blow-up this iteration (max_drawdown 9.8%, liquidated=false), so the code defects from prior iterations are resolved.

Backtest Review

avg_trade_return_pct = -0.058% (per-notional, pct units) — the per-trade edge is NEGATIVE, not merely below the ~0.10% COIN-M viability floor the entire thesis rests on. The central claim (that CM's low 0.06% RT fee makes this MR edge viable) is falsified: there is no positive gross edge for the low fee to rescue.

Backtest Review

profit_factor 0.95, total_return -7.06%, Sharpe -0.37, Sortino -0.47, information_ratio -0.84 vs a meaningful buy-hold benchmark — losing money on both an absolute and risk-adjusted basis.

Backtest Review

The distinguishing regime filter did not work: all three realized-vol terciles are negative (calm -1.75%, normal -5.30%, stressed -0.94%), so standing aside in trends did not confer positive expectancy in ranges either.

Backtest Review

Matches the single-name fade/reversion graveyard (L55: PF < 1.15 / negative return) and the sub-fee-floor tell (L22/L27): optimization cannot lift an edge below cost, let alone one that is negative gross.

Outcome Summary

BtcCmInverseFourHourRegimeGatedRever-7028723d1b

Outcome Summary

This strategy proposed an execution-cost thesis rather than a new signal: an ADX-regime-gated z-score mean-reversion fade on the BTC COIN-M inverse perpetual, arguing that COIN-M's 0.06% round-trip fee would make a marginal MR edge viable where USD-M's 0.10% could not. After three prior iterations spent fixing sizing/liquidation code defects (this run finally traded cleanly with no blow-up, max drawdown 9.8%), the backtest over 230 trades and 2109 days revealed the fatal flaw: avg_trade_return_pct was -0.058%, a negative gross edge, with PF 0.95, total_return -7.06% and Sharpe -0.37. The analyst abandoned it at the backtest-review gate before optimization, since no amount of tuning can manufacture positive expectancy that the near-frictionless-fee version already fails to reveal. The regime filter, meant to be the distinguishing edge, produced losses across all three volatility terciles, confirming the strategy belonged to the single-name fade/reversion graveyard.

Outcome Summary

A cheaper venue cannot rescue a strategy whose gross per-trade edge is negative — verify positive expectancy before the fee advantage, and note the regime gate here failed to confer positive expectancy in any vol regime.

Outcome Summary

The analyst returned an 'abandon' verdict at the pre-optimization backtest-review gate (abandon_class=negative_expectancy): the thesis was falsified because there was no positive gross edge for the low fee to rescue, and the distinguishing regime filter was negative in all three volatility terciles (calm -1.75%, normal -5.30%, stressed -0.94%). Optimization was never run.

Outcome Summary

Fade z-score extremes on the BTC COIN-M inverse perpetual (BTCUSD_PERP.BINANCE_CM, 4H bars), taking mean-reversion trades only in low-trend/ranging regimes (ADX-gated), betting that COIN-M's low 0.06% round-trip fee would make a moderate MR edge fee-viable where USD-M could not.

Outcome Summary

summary_BtcCmInverseFourHourRegimeGatedRever-7028723d1b.json

Outcome Summary

Over 2109 days and 230 trades it lost money on both an absolute and risk-adjusted basis: total_return -7.06%, profit_factor 0.95, Sharpe -0.37, Sortino -0.47, information_ratio -0.84, win_rate 53.5%, max_drawdown 9.8%. Critically, avg_trade_return_pct was -0.058% of notional — a negative per-trade edge, below zero rather than merely below the ~0.10% COIN-M viability floor.

Iteration History

Verification failed (Layer 4 — QA review) [class=no_edge]: - ACCOUNT LIQUIDATED: liquidated=TRUE on 2024-03-04, total_return -100.0%, max_drawdown 100.0%. The strategy shorts an INVERSE perpetual, which carries real liquidation risk on a sharp rally, and its only price protection is a CLOSE-BASED 5% stop evaluated at the 4H bar close. A fast intrabar surge (early-March-2024 BTC move the ADX gate didn't exclude) can run through the 5% level before the next close and exhaust margin. A 5%-stopped, <=0.5x-notional / 1x-leverage book should never reach -100%; that it liquidated shows the close-only stop is inadequate for the short-inverse liquidation profile. return_skew -8.13 / kurtosis 173.6 confirm the single catastrophic tail. - NEGATIVE-EXPECTANCY inverted-payoff reversion, independent of the liquidation. PF 0.645 (<1), avg_trade_return_pct -0.655% (negative), expectancy -$196, Sharpe -0.806, with the classic trap: win_rate 0.581 but avg_loss $1,319 ~= 2x avg_win $615. Same failure as the BTC CM ranging-reversion sibling (PF 0.815) — the ADX gate does not convert the fade to positive expectancy. Even with a perfect intrabar stop the mechanism loses net.
Strategy report

Backtest and paper results are hypothetical. Trading involves risk of loss.