backtesting-trading-strategies
Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger wit
By jeremylongshore · 4,468 installs
npx skills add jeremylongshore/tons-of-skills-marketplace --skill backtesting-trading-strategies
Source repository · Upstream listing
Backtesting Trading Strategies
Overview
Simulate trading strategies against historical data. Results describe a historical simulation, not expected future performance. The framework includes 8 built in strategies, the metrics listed below, and parameter optimization.
Key Features:
8 pre built trading strategies (SMA, EMA, RSI, MACD, Bollinger, Breakout, Mean Reversion, Momentum)
Performance metrics (Sharpe, Sortino, Calmar, VaR, max drawdown)
Parameter grid search optimization
Equity curve visualization
Trade by trade analysis
Prerequisites
Before invoking this skill, the user installs the required dependencies in the
Python environment used for the simulation:
Optional for advanced features:
Instructions
1. Fetch historical data (cached to ${CLAUDE SKILL DIR}/data/ for reuse):
2. Run a backtest with default or custom parameters:
3. Analyze results saved to ${CLAUDE SKILL DIR}/reports/ includes summary.txt (performance metrics), trades.csv (trade log), equity.csv (equity curve data), and chart.png (visual equity curve).
4. Optimize parameters via grid search to find the best combination:
Output
Performance Metrics
Metric Description
Total Return Overall percentage gain/loss
CAGR Compound annual growth rate
Sharpe Ratio Historical risk adjusted return
Sortino Ratio Downside risk adjusted return
Calmar Ratio Return divided by max drawdown
Risk Metrics
Metric Description
Max Drawdown Largest peak to trough decline
VaR (95%) Value at Risk at 95% confidence
CVaR (95%) Expected loss beyond VaR
Volatility Annualized standard deviation
Trade Statistics
Metric Description
Total Trades Number of round trip trades
Win Rate Percentage of profitable trades
Profit Factor Gross profit divided by gross loss; N/A with no observed losses
Expectancy Expected value per trade
Example Output
Figure free layout; actual values depend on the input series, fees, slippage,
strategy and parameters. Do not present these placeholders as measured returns.
Profit factor is unavailable when no losing trades were observed, including a
zero trade run or a single winning/breakeven trade. A single losing trade yields
zero gross profit divided by its loss; this is not evidence of strategy quality.
Zero/one trade samples cannot establish performance, and optimization is an
in sample historical comparison rather than a forecast.
Supported Strategies
Strategy Description Key Parameters
sma crossover Simple moving average crossover fast period , slow period
ema crossover Exponential MA crossover fast period , slow period
rsi reversal RSI overbought/oversold period , overbought , oversold
macd MACD signal line crossover fast , slow , signal
bollinger bands Mean reversion on bands period , std dev
breakout Price breakout from range lookback , threshold
mean reversion Return to moving average period , z threshold
momentum Rate of change momentum period , threshold
Configuration
Create ${CLAUDE SKILL DIR}/config/settings.yaml :
Error Handling
Use Read to inspect [ references/errors.md ](references/errors.md) for common issues and solutions.
Examples
See [ references/examples.md ](references/examples.md) for detailed usage examples including:
Multi asset comparison
Walk forward analysis
Parameter optimization workflows
Files
File Purpose
scripts/backtest.py Main backtesting engine
scripts/fetch data.py Historical data fetcher
scripts/strategies.py Strategy definitions
scripts/metrics.py Performance calculations
scripts/optimize.py Parameter optimization
Resources
[yfinance](https://github.com/ranaroussi/yfinance) Yahoo Finance data
[TA Lib](https://ta lib.org/) Technical analysis library
[QuantStats](https://github.com/ranaroussi/quantstats) Portfolio analytics