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:Klineslices,FundingRateSnapshot,OpenInterestSnapshot,GexSnapshot,MacroSnapshot.Signal,SizeHint,StrategyFill— typed outputs.StrategyParams— opaque JSON wrapper, validated per-strategy viaStrategy::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::BacktestExecution—ExecutionModelimpl with fee / funding / slippage models and an in-memory ledger. Deterministic per-candle fill detection.metrics—BacktestMetrictrait + built-in impls:SharpeRatio,Cagr,MaxDrawdownPct,Calmar,ProfitFactor,Expectancy.
Entry strategies (14)
All under engines/<name>/mod.rs — mandatory layout, no flat peers:
| Engine | Notes |
|---|---|
SupertrendStrategy | Validated v4 retrospective. Sharpe 0.90, D1–8h. |
EwmacStrategy | Validated v4 retrospective. Sharpe 0.90, 6h–1h. |
PsarStrategy | Validated v4 retrospective. Sharpe 0.69–1.43, W1–D1. |
BasisRevertStrategy | Active, validation in progress (4.6.x). |
BollingerBreakoutStrategy | Active, validation in progress. |
FundingArbStrategy | Active, validation in progress. |
HurstRegimeSwitcherStrategy | Active, validation in progress. |
OpeningRangeBreakoutStrategy | Active, validation in progress. |
PairsMrStrategy | Active, validation in progress. |
RsiMeanReversionStrategy | Active, validation in progress. |
TsMomStrategy | Active, validation in progress. |
VolumeSpikeBreakoutStrategy | Active, validation in progress. |
VpinImpulseStrategy | Active, validation in progress. |
VwapStretchMrStrategy | Active, 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) —ExecutionModeltrait surface, domain primitives (Symbol,Kline,Side,Timeframe,OrderIntent,OrderRole,EntryType,Network).gordon-kernel(^2) —GordonError,gordon_warn!macro.- No
gordon-exchangedependency. Strategies consume already-fetched candles and snapshots expressed as domain types.
Invariants
- No I/O, no exchange dependency. A PR adding
gordon-exchangetoCargo.tomlmust be rejected. - Determinism in
BacktestExecution. NoSystemTime::now(), norand::*, no non-deterministicHashMapiteration on the fill path. - Mandatory strategy directory layout.
engines/<name>/mod.rsfor every engine, even single-file impls. - Zero
#[allow(...)].
Where it lives
- Repo:
gordon-strategy/ - kellnr:
https://kellnr.lepaux.com/crates/gordon-strategy(LAN-only)
Related
- gordon-domain —
ExecutionModeltrait + domain types consumed by strategies. - gordon-exchange — explicitly out of scope for this crate.