
Backtesting Trading Strategies
Backtest a named trading strategy on historical OHLCV data with commissions, slippage, and risk limits before risking real capital.
Overview
backtesting-trading-strategies is an agent skill for the Validate phase that runs a Python backtest of a registered strategy against historical market data with fees and risk settings.
Install
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill backtesting-trading-strategiesWhat is this skill?
- Strategy contract: Signal (entry/exit, direction, strength) and abstract Strategy with lookback
- run_backtest() engine with initial capital, commission, slippage, and risk_settings (stop loss, take profit, max positio
- CLI via python scripts/backtest.py with strategy name, symbol, and period flags
- Documented examples for SMA crossover and RSI reversal on symbols like BTC-USD
Adoption & trust: 3.8k installs on skills.sh; 2.3k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You coded a trading idea but do not know if it survives realistic costs, slippage, and stop rules on past data.
Who is it for?
Indie builders testing systematic rules (crossover, RSI, etc.) on liquid symbols with the bundled Strategy/Signal pattern.
Skip if: Live order placement, exchange key management, or compliance review—those belong in later Build/Ship work with separate tooling.
When should I use this skill?
Run a trading strategy backtest against historical price data via /backtest-strategy <strategy_name> <symbol> [options].
What do I get? / Deliverables
You obtain a full historical backtest run you can compare across parameters and symbols before building live execution.
- BacktestResult from run_backtest (performance and trade statistics)
- Reproducible CLI command line for strategy/symbol/period runs
Recommended Skills
Journey fit
Validation is where you prove a strategy idea with evidence; historical simulation belongs before you size positions or ship a live trading bot. Pricing and risk sizing decisions depend on expected drawdown and return profiles that only a disciplined backtest surfaces.
How it compares
A strategy simulation workflow skill with a Python engine, not a market-data MCP server or charting UI.
Common Questions / FAQ
Who is backtesting-trading-strategies for?
Solo developers and small teams building rule-based trading bots who want agent-guided backtests from the command line before going live.
When should I use backtesting-trading-strategies?
Use it in Validate when comparing strategy variants, symbols, or risk caps on historical data, and before you commit capital assumptions to a production trading script.
Is backtesting-trading-strategies safe to install?
It allows Read, Write, Edit, and Bash(python:*); only install if you trust the skill source and review the Security Audits panel on this Prism page; never embed live API secrets in backtest scripts.
SKILL.md
READMESKILL.md - Backtesting Trading Strategies
# /backtest-strategy Run a complete backtest of a trading strategy against historical data. ## Usage ``` /backtest-strategy <strategy_name> <symbol> [options] ``` ## Core Architecture The backtester uses three key types: ```python from dataclasses import dataclass @dataclass class Signal: """Returned by every strategy on each bar.""" entry: bool = False # True to open a position exit: bool = False # True to close a position direction: str = "long" # "long" or "short" strength: float = 1.0 # 0-1 confidence class Strategy(ABC): name: str lookback: int # minimum bars needed @abstractmethod def generate_signals(self, data: pd.DataFrame, params: dict) -> Signal: ... ``` The engine calls `run_backtest()`: ```python def run_backtest( strategy_name: str, data: pd.DataFrame, initial_capital: float = 10000, params: dict = None, commission: float = 0.001, slippage: float = 0.0005, risk_settings: dict = None, # stop_loss, take_profit, max_position_size ) -> BacktestResult: ``` ## Examples Basic SMA crossover backtest: ```bash python ${CLAUDE_SKILL_DIR}/scripts/backtest.py \ --strategy sma_crossover --symbol BTC-USD --period 1y ``` RSI reversal with custom parameters and $50k capital: ```bash python ${CLAUDE_SKILL_DIR}/scripts/backtest.py \ --strategy rsi_reversal --symbol ETH-USD --period 6m \ --capital 50000 \ --params '{"period": 14, "overbought": 75, "oversold": 25}' ``` Specific date range with low commission: ```bash python ${CLAUDE_SKILL_DIR}/scripts/backtest.py \ --strategy macd --symbol SOL-USD \ --start 2024-01-01 --end 2025-01-01 \ --commission 0.0005 --slippage 0.0002 ``` List all available strategies: ```bash python ${CLAUDE_SKILL_DIR}/scripts/backtest.py --list ``` ## Available Strategies | Strategy | Direction | Key Parameters | |----------|-----------|----------------| | `sma_crossover` | Long only | `fast_period`, `slow_period` | | `ema_crossover` | Long only | `fast_period`, `slow_period` | | `rsi_reversal` | Long + Short | `period`, `overbought`, `oversold` | | `macd` | Long + Short | `fast`, `slow`, `signal` | | `bollinger_bands` | Long + Short | `period`, `std_dev` | | `breakout` | Long only | `lookback`, `threshold` | | `mean_reversion` | Long + Short | `period`, `z_threshold` | | `momentum` | Long only | `period`, `threshold` | ## Configuration Settings are loaded from `${CLAUDE_SKILL_DIR}/config/settings.yaml` with this priority: 1. CLI arguments (highest) 2. `settings.yaml` values 3. Hardcoded defaults (lowest) Risk management keys in `settings.yaml`: ```yaml risk: max_position_size: 0.95 # fraction of cash per trade stop_loss: 0.05 # 5% stop loss (null to disable) take_profit: 0.15 # 15% take profit (null to disable) ``` ## Output Results are saved to `${CLAUDE_SKILL_DIR}/reports/`: - `*_summary.txt` -- Performance metrics table - `*_trades.csv` -- Trade log with entry/exit times, PnL - `*_equity.csv` -- Equity curve data - `*_chart.png` -- Equity curve + drawdown chart (requires matplotlib) --- name: compare-strategies description: Compare multiple strategy backtests side by side allowed-tools: Read, Write, Edit, Bash(python:*) --- # /compare-strategies Run multiple strategies on the same data and compare performance side by side. ## Usage ``` /compare-strategies <symbol> [strategies...] [options] ``` ## Workflow 1. Fetch data once for the symbol and period 2. Run each strategy with its default (or specified) parameters 3. Collect results into a comparison table 4. Rank by chosen metric ## Example Script ```python import sys from pathlib import Path sys.path.insert(0, str(Path("${CLAUDE_SKILL_DIR}/scripts"))) from backtest import load_data, run_backtest from fetch_data import parse_perio