All skills
gracefullight avatar

/backtesting-trading-strategies

@833b232

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".

Use this Skill: https://skilld.dev/gh/gracefullight/stock-checker/backtesting-trading-strategies

This session only. Nothing lands on disk.

referenceserrors.md

≈954 tokens on demand. Your agent reads this file only when SKILL.md points to it.

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:

# 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:

python scripts/backtest.py --strategy sma_crossover --period 1y  # More data

yfinance Not Installed

yfinance not installed. Install with: pip install yfinance pandas

Solution:

pip install yfinance pandas numpy matplotlib

Strategy Errors

Unknown Strategy

ValueError: Unknown strategy: {name}. Available: [...]

Solution: Use --list to see available strategies:

python scripts/backtest.py --list

Invalid Parameters JSON

json.decoder.JSONDecodeError: ...

Cause: Malformed JSON in --params argument.

Solution: Ensure proper JSON format:

# 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:

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:

chmod -R u+w /path/to/backtester/reports/

Missing Directory

FileNotFoundError: [Errno 2] No such file or directory: 'data/...'

Solution: Directories are auto-created, but ensure write permissions:

mkdir -p data reports

Optimization Errors

Memory Error During Grid Search

MemoryError: Unable to allocate array

Cause: Too many parameter combinations.

Solution: Reduce parameter grid:

# Instead of testing 10x10x10 = 1000 combinations
--param-grid '{"p1": [10,20,30], "p2": [50,100]}'  # 6 combinations

Optimization Takes Too Long

Cause: Large grid + large dataset.

Solutions:

  1. Reduce parameter grid
  2. Use shorter test period for initial optimization
  3. Parallelize (not implemented in basic version)

Performance Warnings

Unrealistic Results

Symptoms:

  • Sharpe ratio > 5
  • Win rate > 80%
  • No losing periods

Cause: Likely overfitting or look-ahead bias.

Solution:

  • Test on out-of-sample data
  • Add realistic commission/slippage
  • Verify signal generation doesn't use future data

All Trades Are Losses

Cause:

  • Commission/slippage too high
  • Strategy not suited for asset
  • Wrong direction (buying when should sell)

Solution:

  • Reduce costs: --commission 0.0005 --slippage 0.0002
  • Try different strategy
  • Check strategy logic

Source: SKILL.md on GitHub

1 warning17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides a comprehensive backtesting framework for cryptocurrency and traditional trading strategies. It allows users to fetch historical data from reliable sources like Yahoo Finance and CoinGecko, run simulations, and analyze performance metrics. No malicious behavior or security vulnerabilities were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    10/10 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 833b232. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 7 hours ago.

Activeupdated 6 months ago
What it can do
Reads files Edits files Runs commands
version
2.0.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
All 6 allowed tools
ReadWriteEditGrepGlobBash(python:*)

README badge

README badge for gracefullight/stock-checker/backtesting-trading-strategies