Quick Start
Get a working backtest running in under 5 minutes.
Installation
Install via pip and set up your environment.
Core Concepts
Learn how Strategy, Backtest, and orders work together.
API Reference
Full reference for every class, method, and parameter.
What is Backtesting.py?
Backtesting.py is a Python framework for testing trading strategies against historical market data. You define a strategy by subclassingStrategy, load OHLCV price data into a Backtest, then call .run() to simulate trading and .plot() to visualize the results interactively.
quickstart.py
Key features
Fast execution
NumPy-powered engine simulates thousands of bars per second.
Built-in optimizer
Grid search or Bayesian optimization across any strategy parameters.
Interactive plots
Bokeh-powered equity curves, drawdown charts, and trade markers.
Rich statistics
Sharpe, Sortino, Calmar, SQN, Kelly Criterion, CAGR, and more.
Full order types
Market, limit, stop-limit, stop-loss, and take-profit orders.
Indicator agnostic
Works with TA-Lib, pandas-ta, NumPy, or any Python function.
Multiple time frames
Combine signals from different resolutions in one strategy.
Composable strategies
Extend
SignalStrategy, TrailingStrategy, or FractionalBacktest.Performance results
A complete backtest of a simple SMA crossover strategy on Google stock (2004–2013) produces detailed statistics in seconds:Supports any instrument
Backtesting.py works with any asset class that has candlestick data — stocks, ETFs, forex pairs, cryptocurrencies, commodities, and futures. As long as your data hasOpen, High, Low, Close columns in a pandas DataFrame, you can backtest against it.
Optimization guide
Tune parameters with grid search and heatmaps.
Multiple time frames
Combine daily signals with intraday execution.
Machine learning
Integrate ML models as trading signals.
Multi-asset
Run parallel backtests across many instruments.