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 with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".
Security Assessment
About backtesting-trading-strategies
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.
FAQ
Which strategies are built in?
Eight: sma_crossover, ema_crossover, rsi_reversal, macd, bollinger_bands, breakout, mean_reversion, and momentum, each with its own key parameters.
What dependencies does it need?
It requires pandas, numpy, yfinance, and matplotlib, with ta-lib, scipy, and scikit-learn listed as optional installs for advanced features.
How do I find the best parameters for a strategy?
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.
What performance and risk metrics does it report?
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.
Where does the historical data come from?
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.
All Files
10 filesInstall backtesting-trading-strategies
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
gracefullight/stock-checker