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.

referencesexamples.md

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

Backtesting Examples

Example 1: Basic SMA Crossover Backtest

Test a simple moving average crossover strategy on Bitcoin:

python scripts/backtest.py \
  --strategy sma_crossover \
  --symbol BTC-USD \
  --period 1y \
  --capital 10000 \
  --params '{"fast_period": 20, "slow_period": 50}'

Expected Output:

╔══════════════════════════════════════════════════════════════════════╗
║            BACKTEST RESULTS: SMA_CROSSOVER                           ║
║            BTC-USD | 2023-01-14 to 2024-01-14                        ║
╠══════════════════════════════════════════════════════════════════════╣
║ Total Return:     +47.32%         │ Max Drawdown:      -18.45%       ║
║ Sharpe Ratio:        1.87         │ Win Rate:             58.3%      ║
╚══════════════════════════════════════════════════════════════════════╝

Example 2: RSI Reversal Strategy

Test an RSI mean reversion strategy on Ethereum:

python scripts/backtest.py \
  --strategy rsi_reversal \
  --symbol ETH-USD \
  --start 2023-01-01 \
  --end 2024-01-01 \
  --capital 25000 \
  --params '{"period": 14, "overbought": 70, "oversold": 30}'

Example 3: MACD with Custom Costs

Test MACD on Solana with realistic exchange fees:

python scripts/backtest.py \
  --strategy macd \
  --symbol SOL-USD \
  --period 6m \
  --capital 5000 \
  --commission 0.002 \
  --slippage 0.001 \
  --params '{"fast": 12, "slow": 26, "signal": 9}'

Example 4: Parameter Optimization

Find optimal SMA crossover parameters:

python scripts/optimize.py \
  --strategy sma_crossover \
  --symbol BTC-USD \
  --period 2y \
  --param-grid '{"fast_period": [10, 20, 30, 50], "slow_period": [50, 100, 150, 200]}'

Expected Output:

================================================================================
PARAMETER OPTIMIZATION RESULTS
================================================================================

TOP 10 PARAMETER COMBINATIONS (by Sharpe Ratio):
--------------------------------------------------------------------------------
fast_period  slow_period    Return%     Sharpe     MaxDD%   WinRate%    Trades
--------------------------------------------------------------------------------
         20          100       52.3       2.14      -15.2       62.5        18
         30          150       48.7       1.98      -12.8       58.3        14
         ...

BEST PARAMETERS:
  fast_period: 20
  slow_period: 100
================================================================================

Example 5: Compare Multiple Strategies

Test different strategies on the same data:

# Fetch data once
python scripts/fetch_data.py --symbol BTC-USD --period 1y

# Run each strategy
for strategy in sma_crossover ema_crossover rsi_reversal macd bollinger_bands; do
  python scripts/backtest.py --strategy $strategy --symbol BTC-USD --period 1y --quiet
done

Example 6: Bollinger Bands Mean Reversion

python scripts/backtest.py \
  --strategy bollinger_bands \
  --symbol ETH-USD \
  --period 1y \
  --params '{"period": 20, "std_dev": 2.0}'

Example 7: Breakout Strategy

python scripts/backtest.py \
  --strategy breakout \
  --symbol BTC-USD \
  --period 6m \
  --params '{"lookback": 20, "threshold": 1.0}'

Example 8: List Available Strategies

python scripts/backtest.py --list

Output:

Available strategies:
  sma_crossover: Simple Moving Average Crossover Strategy.
  ema_crossover: Exponential Moving Average Crossover Strategy.
  rsi_reversal: RSI Overbought/Oversold Reversal Strategy.
  macd: MACD Signal Line Crossover Strategy.
  bollinger_bands: Bollinger Bands Mean Reversion Strategy.
  breakout: Price Breakout Strategy.
  mean_reversion: Mean Reversion Strategy.
  momentum: Rate of Change Momentum Strategy.

Example 9: Walk-Forward Analysis

Test strategy on rolling windows:

# Train on 2022, test on 2023
python scripts/backtest.py \
  --strategy sma_crossover \
  --symbol BTC-USD \
  --start 2023-01-01 \
  --end 2023-12-31 \
  --params '{"fast_period": 20, "slow_period": 100}'  # From 2022 optimization

Example 10: Multi-Asset Portfolio

Test same strategy across multiple assets:

for symbol in BTC-USD ETH-USD SOL-USD AVAX-USD; do
  echo "=== $symbol ==="
  python scripts/backtest.py \
    --strategy sma_crossover \
    --symbol $symbol \
    --period 1y \
    --quiet
done

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