๐Ÿ’ธ Sponsor the strip
REPLAUSE

Backtesting.py

Small Python framework for backtesting strategies on candlestick data

๐Ÿงฉ Build it Free 04 in Backtesting ๐Ÿ†• NEW TODAY
Any marketStandalonePython

by kernc โ†’

8,949 AGPL-3.0updated 5 Aug '26

Overview

Backtesting.py is a small Python framework that backtests a trading strategy against OHLC candlestick data with one Strategy class and one Backtest object.

  • Fortraders who want a small backtest of one strategy on one instrument's OHLC data.
  • NeedsPython and a pandas DataFrame of OHLC(V) data for the instrument being tested โ€” no key or account.
  • Runsa Python package (pip install backtesting) with a built-in optimizer and interactive plotting.
  • Limitit backtests one instrument at a time โ€” the Backtest object takes a single OHLC DataFrame, so a portfolio needs one run per symbol.

Vibe it

Paste this into your AI agent. Write the first line, or take a suggestion; the copy carries your words.

Source: https://github.com/kernc/backtesting.py โ€” clone it and read its README and examples before writing anything; its documented setup beats what you remember.
Stack: a small Python framework over pandas โ€” a Strategy subclass with init() and next(), run through one Backtest object, with a built-in optimizer and interactive plotting.
Needs: Python and a pandas DataFrame of OHLC(V) data for the instrument being tested.
Start: `pip install backtesting`, then run the SmaCross example from the README against the bundled GOOG test data before swapping in my own.
Limit: it backtests one instrument at a time โ€” the Backtest object takes a single OHLC DataFrame, so a portfolio needs one run per symbol.
Done means: you show me the stats output (Return, Sharpe Ratio, Max. Drawdown) from a run against my own data, and the Strategy code you wrote.
Before you start, ask me: which instrument and OHLC data file I want to test, and the entry/exit rule for the strategy.

Something wrong here? Tell us โ†’