
Backtesting Trading Strategies
Configure and run historical backtests for SMA, EMA, RSI, MACD, and other strategies before you risk real capital on a solo trading tool.
Overview
Backtesting Trading Strategies is an agent skill most often used in Validate (also Build) that configures historical strategy simulation with commissions, slippage, risk limits, and CSV/PNG reports.
Install
npx skills add https://github.com/gracefullight/stock-checker --skill backtesting-trading-strategiesWhat is this skill?
- settings.yaml template for data (yfinance/coingecko), backtest capital, commission, and slippage
- Optional risk block: max position size, stop loss, take profit
- Reporting outputs: trade log CSV, equity curve CSV, equity chart PNG
- 8 named strategy presets with default parameters (SMA/EMA crossover, RSI, MACD, Bollinger, breakout, mean reversion, mom
- 8 strategy presets listed with default parameters
- Default commission 0.1% and slippage 0.05% in template
Adoption & trust: 1.5k installs on skills.sh; 28 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have a trading idea but no standardized way to simulate it on cached market data with realistic costs and saved artifacts.
Who is it for?
Solo builders prototyping quant or rule-based strategies with yfinance or CoinGecko data and local report folders.
Skip if: Live execution, brokerage integration, or traders who only need discretionary charting without agent-driven configuration.
When should I use this skill?
Use when configuring or running historical backtests for stock-checker strategies via settings.yaml and named strategy blocks.
What do I get? / Deliverables
You get reproducible backtest runs with trade logs, equity curves, and charts driven from a shared settings.yaml and named strategy defaults.
- settings.yaml configuration
- Trade log CSV
- Equity curve CSV and chart PNG when reporting flags enabled
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Validate → prototype is the canonical shelf because the skill centers on proving strategy edge with historical simulation, commissions, and slippage—not live trading ops. Prototype fits YAML-driven backtest defaults, cached market data, and report outputs that de-risk a strategy idea.
Where it fits
Run RSI reversal defaults against cached daily bars to see drawdown before funding a broker API.
Compare commission 0.1% and slippage 0.05% sensitivity on MACD presets.
Extend the runner to honor risk.max_position_size while keeping the same reporting outputs.
How it compares
Backtest configuration playbook—not a live trading bot or portfolio tax advisor.
Common Questions / FAQ
Who is backtesting-trading-strategies for?
Indie developers and solo quants using coding agents to validate technical strategies before wiring execution or dashboards.
When should I use backtesting-trading-strategies?
During Validate prototyping to stress-test rules on history, and during Build backend work when you extend the stock-checker runner or reporting pipeline.
Is backtesting-trading-strategies safe to install?
It implies downloading market data and writing local reports; review the Security Audits panel on this Prism page and restrict network/filesystem permissions if you sandbox agents.
SKILL.md
READMESKILL.md - Backtesting Trading Strategies
# Backtesting Configuration # Copy to settings.yaml and customize # Data source settings data: provider: yfinance # Options: yfinance, coingecko cache_dir: ./data # Where to cache downloaded data default_interval: 1d # Default bar interval # Backtest execution settings backtest: default_capital: 10000 # Starting capital in USD commission: 0.001 # Commission per trade (0.1%) slippage: 0.0005 # Slippage per trade (0.05%) # Risk management (optional) risk: max_position_size: 0.95 # Max % of capital per position stop_loss: null # Fixed stop loss % (null = disabled) take_profit: null # Fixed take profit % (null = disabled) # Report generation reporting: output_dir: ./reports # Where to save results save_trades: true # Save trade log CSV save_equity: true # Save equity curve CSV save_chart: true # Generate equity chart PNG # Strategy defaults (can be overridden via --params) strategies: sma_crossover: fast_period: 20 slow_period: 50 ema_crossover: fast_period: 12 slow_period: 26 rsi_reversal: period: 14 overbought: 70 oversold: 30 macd: fast: 12 slow: 26 signal: 9 bollinger_bands: period: 20 std_dev: 2.0 breakout: lookback: 20 threshold: 0.0 mean_reversion: period: 20 z_threshold: 2.0 momentum: period: 14 threshold: 5.0 # Error Handling Reference ## Data Fetching Errors ### No Data Returned ``` Error: No data returned for {symbol} ``` **Causes:** - Invalid symbol format (use `BTC-USD` not `BTC/USD`) - Symbol not available on data provider - Date range has no trading data **Solutions:** ```bash # Check valid symbol format for Yahoo Finance python -c "import yfinance as yf; print(yf.Ticker('BTC-USD').info.get('symbol'))" # Try CoinGecko for crypto python scripts/fetch_data.py --symbol BTC --source coingecko ``` ### Insufficient Data ``` Error: Insufficient data. Got {n} bars, need at least 50. ``` **Cause:** Date range too short or strategy lookback period exceeds data length. **Solution:** Extend the period or reduce strategy lookback: ```bash python scripts/backtest.py --strategy sma_crossover --period 1y # More data ``` ### yfinance Not Installed ``` yfinance not installed. Install with: pip install yfinance pandas ``` **Solution:** ```bash pip install yfinance pandas numpy matplotlib ``` ## Strategy Errors ### Unknown Strategy ``` ValueError: Unknown strategy: {name}. Available: [...] ``` **Solution:** Use `--list` to see available strategies: ```bash python scripts/backtest.py --list ``` ### Invalid Parameters JSON ``` json.decoder.JSONDecodeError: ... ``` **Cause:** Malformed JSON in `--params` argument. **Solution:** Ensure proper JSON format: ```bash # Correct --params '{"fast_period": 20, "slow_period": 50}' # Wrong (single quotes inside) --params "{'fast_period': 20}" ``` ### Strategy Lookback Exceeded ``` Signal generation failed: insufficient data for lookback period ``` **Cause:** Strategy needs more historical bars than available. **Solution:** Fetch more data or use shorter lookback: ```bash python scripts/fetch_data.py --symbol BTC-USD --period 2y ``` ## Calculation Errors ### Division by Zero in Metrics ``` RuntimeWarning: divide by zero encountered ``` **Cause:** No trades generated, or all trades were losses. **Solution:** This is informational. Check if strategy generates signals: - Too few signals = parameters may be too restrictive - No winning trades = strategy may not suit the asset/timeframe ### NaN in Results ``` Sharpe Ratio: nan ``` **Cause:** Zero variance in returns (e.g., all flat periods). **Solution:** Use longer test period or more volatile asset. ## File/Directory Errors ### Permission Denied ``` PermissionError: [Errno 13] Permission denied: 'reports/...' ``` **Solution:** ```bash chmod -R u+w /path/to/backtester/reports/ ``` ### Missing Directory ``` FileNotFoundError: [Errno 2] No su