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 with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".
A complete framework for backtesting crypto and traditional trading strategies against historical price data before any real capital is at risk. It fits requests to test or validate a strategy, check historical performance, simulate trades, optimize parameters, or compare approaches, and is triggered by phrases such as backtest strategy or validate signals. The workflow is script-driven in Python and organized around a small set of command-line entry points.
Eight strategies ship built in - SMA and EMA crossovers, RSI reversal, MACD, Bollinger Bands, breakout, mean reversion, and momentum - each exposing its own tunable parameters. A typical run fetches and caches historical data with fetch_data.py (sourced from Yahoo Finance via yfinance), runs a backtest with backtest.py using a chosen strategy, symbol, period, starting capital, and JSON parameters, then reviews the generated reports. Output artifacts include a text performance summary, a trade log CSV, an equity-curve CSV, and a rendered equity-curve chart. Parameter tuning is handled by optimize.py, which grid-searches across supplied parameter ranges to find the best-performing combination.
Reported results are thorough: performance metrics such as total return, CAGR, Sharpe, Sortino, and Calmar ratios; risk metrics including maximum drawdown, VaR, CVaR, and annualized volatility; and trade statistics like win rate, profit factor, and expectancy. Behavior is controlled through a settings.yaml file covering default capital, commission, slippage, and position sizing, with optional fixed stop-loss and take-profit. Core dependencies are pandas, numpy, yfinance, and matplotlib, with ta-lib, scipy, and scikit-learn available for advanced features. Reference files document error handling and worked examples including multi-asset comparison and walk-forward analysis, making it a self-contained toolkit for quantitatively validating trading ideas.
Eight: sma_crossover, ema_crossover, rsi_reversal, macd, bollinger_bands, breakout, mean_reversion, and momentum, each with its own key parameters.
It requires pandas, numpy, yfinance, and matplotlib, with ta-lib, scipy, and scikit-learn listed as optional installs for advanced features.
Run optimize.py with a param-grid of value ranges (for example fast and slow periods); it performs a grid search to identify the optimal combination.
Performance metrics include total return, CAGR, Sharpe, Sortino, and Calmar; risk metrics include max drawdown, VaR, CVaR, and volatility; trade stats include win rate, profit factor, and expectancy.
Data is pulled from Yahoo Finance through the yfinance library by fetch_data.py and cached to a CSV per symbol and interval for reuse.
Quick Setup:
.claude/skills/Repository
gracefullight/stock-checker