2.1 KiB
2.1 KiB
Backtesting and Replay v1 (Backend)
Scope
Backtesting v1 is an isolated, read-only simulation pipeline under src/backtest/**.
It reuses ProStrategyEngine unchanged and is guarded by feature flag plus mode assertion.
Isolation Guarantees
- Entry path:
POST /api/backtest/runonly. - Hard guard:
if (mode !== 'backtest') throw. - No live runtime loop reuse (
src/index.tsunchanged). - No broker order placement (
ReplayExchangeConnector.placeOrder()throws). - No writes to
orders,trade_history, orcapital_ledgers. - In-memory virtual ledger only.
Deterministic Replay Rules
- Candles are normalized and strictly sorted by timestamp.
- Timeframes are validated to
15m,1h,4h. - Symbol processing order is lexicographic and stable.
- No randomness in fills/slippage/partials/exit ordering.
- Same input payload produces identical output.
Time-Window Semantics
- Replay window:
from_dateinclusive toto_dateinclusive (UTC). - Warm-up candles are loaded before
from_datewhere available. - Trades are evaluated only inside the replay window.
- Default end-of-window behavior: keep open positions as
OPEN_AT_END. - Optional execution override:
forceCloseAtWindowEnd=trueto close at last candle.
Data Sources
- CSV upload (required in v1):
symbol,timeframe,timestamp,open,high,low,close,volume. - JSON upload (array rows or nested symbol/timeframe maps).
- Replay payload adapter (read-only).
- Kraken historical loader (read-only CCXT OHLC fetch, cached in-memory, no order paths).
API Contract Highlights
BacktestResult includes:
tradessummary(netPnlUsd,winRate,maxDrawdownPct,sharpe,totalTrades)timeline(equity and drawdown points)window(UTC replay window +OPEN_AT_END/FORCE_CLOSEpolicy)warmupopenPositionsAtEndassumptionsdiagnostics
Feature Flags
ENABLE_BACKTEST=trueBACKTEST_CUSTOMER_ENABLED=false(when false, only admins can run backtests)BACKTEST_MAX_CSV_BYTESBACKTEST_MAX_ROWS
Non-Goals
- Parameter optimization
- ML tuning
- Strategy mutation
- Live/backtest blending
- Broker execution from backtest mode