Open source · Python 3.10+

Test trading ideas in plain Python.

Bring an OHLC series and a Strategy. Simple Backtest handles cash, positions, commissions, trades, and performance metrics in code you can inspect.

pip install simple-backtest
View the source

strategy.py example output
from simple_backtest import (
    Backtest, BacktestConfig,
    MovingAverageStrategy,
)

strategy = MovingAverageStrategy(
    short_window=10, long_window=30, shares=10
)
config = BacktestConfig.default(
    initial_capital=100_000
)
Portfolio equity Strategy Trade
Illustrative portfolio equity curve This example equity curve falls early, then rises over four years. Saffron circles mark trades. The chart uses sample values and makes no performance claim.

Sample output · not a performance claim

One price series, one cash-funded portfolio.

Each backtest accepts one OHLC or OHLCV series. The accounting model tracks a cash-funded spot position and makes the unsupported cases explicit.

Supported

  • Cash-funded spot
  • Fractional units
  • Custom strategies
  • Commission models

Out of scope

  • Shorting
  • Leverage
  • Derivatives
  • Live execution

You supply the data and the trading rules.

The library takes your price series and strategy objects, then returns portfolio state, trade history, metrics, and Plotly charts you can inspect in Python.

  1. 01

    Load one price series

    Pass an OHLC or OHLCV DataFrame from an API, CSV, database, or notebook.

  2. 02

    Choose or write a strategy

    Use a built-in strategy or subclass Strategy and implement your own signals.

  3. 03

    Run and compare

    Inspect trades, equity, metrics, benchmarks, and parameter searches from the result object.

Install it and pass in a DataFrame.

There is no hosted service or account. The package runs locally and accepts ordinary pandas data.

pip install simple-backtest

View package on PyPI
quick_start.py Python
from simple_backtest import (
    Backtest,
    BacktestConfig,
    MovingAverageStrategy,
)

strategy = MovingAverageStrategy(
    short_window=10,
    long_window=30,
    shares=10,
)

config = BacktestConfig.default(
    initial_capital=10_000
)

backtest = Backtest(data, config)
results = backtest.run([strategy])

print(results.compare())

What the library handles after a signal.

Run several strategies against the same series, tune parameters, validate across time windows, and plot the results with Plotly.

Measure

Sharpe, Sortino, Calmar, CAGR, drawdown, win rate, alpha, beta, and more.

Optimize

Grid search, random search, and chronological walk-forward evaluation.

Model costs

Percentage, flat, tiered, or custom commission behavior.

Six notebooks with working code.

Start with data loading and a first strategy, then move through commissions, technical signals, machine learning, and walk-forward optimization.