feat: add backtester with parameter sweep and walk-forward validation#70
Open
HaoweiChan wants to merge 1 commit intoTraderAlice:masterfrom
Open
feat: add backtester with parameter sweep and walk-forward validation#70HaoweiChan wants to merge 1 commit intoTraderAlice:masterfrom
HaoweiChan wants to merge 1 commit intoTraderAlice:masterfrom
Conversation
Core engine: - Strategy DSL: safe recursive-descent parser for entry/exit logic - Indicator series over full candle history (RSI, EMA, SMA, BBANDS, MACD, ATR) - Historical data via OpenBB SDK + CCXT with auto asset-class detection and caching - Candle-by-candle simulation with slippage, commissions, stop-loss/take-profit - Metrics: total return, Sharpe, max drawdown, win rate, profit factor, equity curve - Persistence: trade logs (JSONL) and summaries (JSON) to data/backtests/ Advanced features: - Parameter grid search: cartesian product, ranked by Sharpe - Walk-forward validation: rolling train/test windows, overfitting detection - Volume realism: flags trades exceeding candle volume fraction - CCXT data source with fallback to OpenBB - Strategy parameters as DSL variables (e.g. RSI_14 < rsi_oversold) MCP tools: runBacktest, runParameterSweep, runWalkForward, fetchHistoricalOhlcv, listBacktests, readBacktestSummary Made-with: Cursor
addc2b3 to
7a106d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a full-featured backtesting extension to OpenAlice with 6 MCP tools accessible by Alice (or any MCP client).
Phase 1 — Core Engine
analysis-kitindicators to compute full series over historical candle dataBTC/USD→BTCUSD), and on-disk candle cachingdata/backtests/Phase 2 — Advanced Features
runParameterSweep): cartesian product over user-defined parameter ranges, runs all combinations concurrently, ranks by Sharpe ratio, persists resultsrunWalkForward): splits data into N rolling train/test windows, optimizes on training, validates on test, reports overfitting scorefetchOHLCVvia connected exchange (e.g. Binance), automatic fallback to OpenBB when CCXT unavailableRSI_14 < rsi_oversoldMCP Tools Exposed
runBacktestrunParameterSweeprunWalkForwardfetchHistoricalOhlcvlistBacktestsreadBacktestSummaryFiles Changed
src/extension/backtester/(11 modules — adapter, data, dsl, engine, index, indicators, io, realism, sweep, types, validation)src/main.ts(tool registration with lazy CCXT account getter),src/extension/trading/providers/ccxt/CcxtAccount.ts(added publicfetchOHLCVmethod)Test plan
runBacktest— EMA crossover on BTC/USD daily, 20 trades, +1.12%, Sharpe 1.21fetchHistoricalOhlcv(OpenBB) — 60 candles fetchedfetchHistoricalOhlcv(CCXT) — 60 candles fetched from BinancelistBacktests— lists 9 saved resultsreadBacktestSummary— reads saved JSON correctlyrunParameterSweep— 12 combinations (4×3), ranked output, 108msrunWalkForward— 3 windows, correctly flags overfitting (IS Sharpe 5-12 vs OOS negative)Made with Cursor