backtesting-trading-strategies

Backtest trading strategies against historical price data with performance metrics and parameter optimization.

1|Updated May 6, 2026
One-click install
npx skills add https://github.com/surfingalien/FinSurfing --skill backtesting-trading-strategies-surfingalien
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: backtesting-trading-strategies
Source: https://github.com/surfingalien/FinSurfing/tree/main/Downloads/FinSurfing/.agents/skills/backtesting-trading-strategies
Command: npx skills add https://github.com/surfingalien/FinSurfing --skill backtesting-trading-strategies-surfingalien

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pandas, numpy, yfinance, matplotlib, pyyaml, requests, and includes scripts (resource) and references (resource) components.

What problem does it solve? Validating a trading strategy before risking real capital requires running it against historical data, computing risk-adjusted performance metrics, and tuning parameters—work that is tedious and error-prone to do manually. ## Core Features & Use Cases - Eight Built-in Strategies: SMA/EMA crossover, RSI reversal, MACD, Bollinger Bands, breakout, mean reversion, and momentum, each with configurable parameters and long/short signal support. - Comprehensive Metrics: Calculates Sharpe, Sortino, and Calmar ratios, max drawdown, VaR/CVaR, win rate, profit factor, and expectancy, then saves summary reports, trade logs, equity curves, and charts. - Parameter Optimization: Grid search over parameter combinations ranked by a chosen metric, plus walk-forward analysis for out-of-sample validation. - Use Case: Test an SMA crossover strategy on BTC-USD over one year of daily data, then grid-search fast/slow period combinations to find the parameters with the highest Sharpe ratio. ## Quick Start Ask the assistant to backtest the sma_crossover strategy on BTC-USD over the past year with $10,000 starting capital and show the performance metrics.

Frequently Asked Questions about backtesting-trading-strategies

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I backtest a trading strategy in Python?

Run the backtest.py script with a strategy name, symbol, and period, for example: python scripts/backtest.py --strategy sma_crossover --symbol BTC-USD --period 1y. Results include performance metrics, a trade log CSV, equity curve data, and a chart saved to the reports directory.

How to optimize trading strategy parameters with grid search?

Use optimize.py with a JSON parameter grid, such as --param-grid '{"fast_period": [10, 20, 30], "slow_period": [50, 100, 200]}'. It runs a backtest per combination and ranks results by Sharpe ratio or another metric you choose with --metric.

What data sources does this backtester support?

It fetches historical data from Yahoo Finance via yfinance by default and supports CoinGecko as an alternative source for crypto symbols. Downloaded data is cached as CSV files in the data directory for reuse across runs.

Why does my backtest show a Sharpe ratio above 5 or an 80% win rate?

Unrealistically high metrics usually indicate overfitting or look-ahead bias. Test on out-of-sample data with walk-forward analysis, add realistic commission and slippage, and verify signals do not use future data.

Can I add a custom trading strategy to the backtester?

Yes. Create a class extending the Strategy base class in scripts/strategies.py, implement generate_signals() to return a Signal with entry, exit, and direction fields, then register it in the STRATEGIES dictionary.

What are the limitations of this backtesting approach?

It uses daily bars by default, so intraday strategies are not modeled, and grid search is single-threaded so large parameter grids are slow. CoinGecko data approximates OHLC values, which reduces accuracy for band-based strategies.