Skip to content

gordon-strategy

Purpose

Strategy and backtest math layer for the Gordon platform. Owns the Strategy trait, market context types, signal types, the overlay / veto pipeline, 14 concrete entry-signal engines, and BacktestExecution — the simulated-fills implementation of gordon_domain::execution::ExecutionModel. Pure state machines over already-fetched candles and snapshot data. No I/O, no tokio tasks beyond the async_trait veneer, no exchange dependency.

Version + status

4.6.4 — active. New engines and overlays land as minor bumps. Trait-signature changes and fill-semantic changes require a major bump coordinated with gordon-bot and gordon-manager.

Public surface

  • Strategy — the trait every engine implements. evaluate(&self, ctx: &MarketContext) -> Result<Signal, StrategyError>.
  • MarketContext — typed inputs: Kline slices, FundingRateSnapshot, OpenInterestSnapshot, GexSnapshot, MacroSnapshot.
  • Signal, SizeHint, StrategyFill — typed outputs.
  • StrategyParams — opaque JSON wrapper, validated per-strategy via Strategy::params_schema().
  • OverlayConfig, evaluate_vetoes, extract_overlay_config — overlay / veto pipeline. Vetoes: funding z-score, OI regime, GEX regime, macro regime (MacroRegime), vol-targeting.
  • indicators — stateless indicator functions over &[Kline] slices: vpin, HurstExponent (dual-window DFA), ShannonEntropy, PermutationEntropy, OuEstimator (Ornstein-Uhlenbeck), WilderRsi, WilderAtr.
  • engines::StrategyRegistry — shared at startup by gordon-bot and gordon-manager's backtest engine.
  • backtest::BacktestExecutionExecutionModel impl with fee / funding / slippage models and an in-memory ledger. Deterministic per-candle fill detection.
  • metricsBacktestMetric trait + built-in impls: SharpeRatio, Cagr, MaxDrawdownPct, Calmar, ProfitFactor, Expectancy.

Entry strategies (14)

All under engines/<name>/mod.rs — mandatory layout, no flat peers:

EngineNotes
SupertrendStrategyValidated v4 retrospective. Sharpe 0.90, D1–8h.
EwmacStrategyValidated v4 retrospective. Sharpe 0.90, 6h–1h.
PsarStrategyValidated v4 retrospective. Sharpe 0.69–1.43, W1–D1.
BasisRevertStrategyActive, validation in progress (4.6.x).
BollingerBreakoutStrategyActive, validation in progress.
FundingArbStrategyActive, validation in progress.
HurstRegimeSwitcherStrategyActive, validation in progress.
OpeningRangeBreakoutStrategyActive, validation in progress.
PairsMrStrategyActive, validation in progress.
RsiMeanReversionStrategyActive, validation in progress.
TsMomStrategyActive, validation in progress.
VolumeSpikeBreakoutStrategyActive, validation in progress.
VpinImpulseStrategyActive, validation in progress.
VwapStretchMrStrategyActive, validation in progress.

Backtest = live, byte-parity invariant

The Strategy::evaluate code path is identical between gordon-bot's live loop and gordon-manager's backtest replay. One implementation per strategy — never forked, always parameterised.

The CI gate at tests/it_backtest_live_byte_parity.rs (DP-19) routes a 200-candle BTCUSDT/1h fixture through both BacktestExecution-driven replay and a hand-rolled evaluate_tick mock harness, then asserts the resulting intent sequence is byte-identical on (side, qty, sl_price, entry_price, candle_ts). If live diverges from backtest, the bug is in the live driver, not the strategy code.

Dependencies of note

  • gordon-domain (^1) — ExecutionModel trait surface, domain primitives (Symbol, Kline, Side, Timeframe, OrderIntent, OrderRole, EntryType, Network).
  • gordon-kernel (^2) — GordonError, gordon_warn! macro.
  • No gordon-exchange dependency. Strategies consume already-fetched candles and snapshots expressed as domain types.

Invariants

  • No I/O, no exchange dependency. A PR adding gordon-exchange to Cargo.toml must be rejected.
  • Determinism in BacktestExecution. No SystemTime::now(), no rand::*, no non-deterministic HashMap iteration on the fill path.
  • Mandatory strategy directory layout. engines/<name>/mod.rs for every engine, even single-file impls.
  • Zero #[allow(...)].

Where it lives

  • Repo: gordon-strategy/
  • kellnr: https://kellnr.lepaux.com/crates/gordon-strategy (LAN-only)

Gordon — keep compounding without blowing up