Backtest runner
@qtrader/backtest-runner
Backtest a trading idea on an OHLCV CSV with honest assumptions: next-bar fills, slippage, commission, no look-ahead. Built-in SMA crossover, RSI mean reversion, and buy-and-hold, plus a one-file plug-in format for your own strategies. Writes equity curve and trades CSVs and metrics (CAGR, volatility, Sharpe, Sortino, max drawdown, win rate, exposure). Not financial advice.
- Activity
- New: be the first to try it
- Installs
- 0 installs
- Likes
- 0 likes
- Clones
- 0 clones
- 1{
- 2 "name": "backtest-runner",
- 3 "owner": "qtrader",
- 4 "version": "1.0.0",
- 5 "type": "skill",
- 6 "description": "Backtest a trading idea on an OHLCV CSV with honest assumptions: next-bar fills, slippage, commission, no look-ahead. Built-in SMA crossover, RSI mean reversion, and buy-and-hold, plus a one-file plug-in format for your own strategies. Writes equity curve and trades CSVs and metrics (CAGR, volatility, Sharpe, Sortino, max drawdown, win rate, exposure). Not financial advice.",
- 7 "category": "trading",
- 8 "license": "MIT",
- 9 "compat": ["claude-code"],
- 10 "permissions": {
- 11 "shell": ["node scripts/backtest.mjs", "node scripts/selftest.mjs"],
- 12 "files": { "read": ["./data/**", "./strategies/**"], "write": ["./out/**", "./strategies/**"] }
- 13 },
- 14 "tests": {
- 15 "cases": [
- 16 {
- 17 "name": "engine and metrics match the hand-checked synthetic series",
- 18 "inputs": {},
- 19 "checks": [{ "type": "command_exits_zero", "command": "node scripts/selftest.mjs" }]
- 20 },
- 21 {
- 22 "name": "sma-cross on the example series writes all three outputs",
- 23 "inputs": {},
- 24 "checks": [
- 25 {
- 26 "type": "command_exits_zero",
- 27 "command": "node scripts/backtest.mjs --data examples/prices.csv --strategy sma-cross --param fast=10 --param slow=30 --out out/sma"
- 28 },
- 29 { "type": "file_contains", "path": "out/sma-equity.csv", "text": "date,close,position,cash,equity,drawdown" },
- 30 { "type": "file_contains", "path": "out/sma-trades.csv", "text": "id,side,entry_date,entry_price,exit_date,exit_price,qty,commission,pnl,return_pct,bars_held,status" },
- 31 {
- 32 "type": "output_matches_schema",
- 33 "path": "out/sma-metrics.json",
- 34 "schema": {
- 35 "type": "object",
- 36 "required": ["strategy", "params", "options", "metrics"],
- 37 "properties": {
- 38 "strategy": { "const": "sma-cross" },
- 39 "params": { "type": "object", "properties": { "fast": { "const": 10 }, "slow": { "const": 30 } } },
- 40 "metrics": {
- 41 "type": "object",
- 42 "required": ["total_return", "cagr", "volatility", "sharpe", "sortino", "max_drawdown", "win_rate", "exposure", "trades", "buy_hold_return"],
- 43 "properties": {
- 44 "bars": { "const": 320 },
- 45 "max_drawdown": { "type": "number", "maximum": 0, "minimum": -1 },
- 46 "exposure": { "type": "number", "minimum": 0, "maximum": 1 },
- 47 "trades": { "type": "integer", "minimum": 1 }
- 48 }
- 49 }
- 50 }
- 51 }
- 52 }
- 53 ]
- 54 },
- 55 {
- 56 "name": "plug-in strategy file loads and runs",
- 57 "inputs": {},
- 58 "checks": [
- 59 {
- 60 "type": "command_exits_zero",
- 61 "command": "node scripts/backtest.mjs --data examples/prices.csv --strategy-file examples/strategies/donchian-breakout.mjs --commission-per-share 0.005 --out out/donchian"
- 62 },
- 63 {
- 64 "type": "output_matches_schema",
- 65 "path": "out/donchian-metrics.json",
- 66 "schema": {
- 67 "type": "object",
- 68 "required": ["strategy", "metrics"],
- 69 "properties": { "strategy": { "const": "donchian-breakout" }, "metrics": { "type": "object", "properties": { "total_commission": { "type": "number", "minimum": 0.01 } } } }
- 70 }
- 71 }
- 72 ]
- 73 }
- 74 ]
- 75 }
- 76}
