๐Ÿ’ธ Sponsor the strip
REPLAUSE

Backtrader

Python backtesting and live-trading library with built-in plotting

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

by mementum โ†’

23,167 GPL-3.0updated 19 Aug '24

Overview

Backtrader is a Python library for backtesting and live trading, with data feeds and order execution for Interactive Brokers, Oanda, and Visual Chart.

  • Fortraders who want one strategy class that runs unchanged in backtest and live trading.
  • NeedsPython >= 3.2; a live connection needs IbPy (Interactive Brokers), oandapy (Oanda), or a comtypes fork (Visual Chart), plus pytz.
  • Runsa self-contained Python library (pip install backtrader) built around a Cerebro engine that you add data feeds, a strategy, and a sizer to.
  • Limitplotting needs matplotlib >= 1.4.1 and is not supported under pypy.

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/mementum/backtrader โ€” clone it and read its README and examples before writing anything; its documented setup beats what you remember.
Stack: a self-contained Python library โ€” a Cerebro engine that you add data feeds, a Strategy, and a sizer to, then run(); the same Strategy runs live against Interactive Brokers, Oanda, or Visual Chart.
Needs: Python >= 3.2 (pypy also works, without plotting); IbPy for Interactive Brokers, oandapy for Oanda, or a comtypes fork for Visual Chart if going live; pytz recommended.
Start: `pip install backtrader`, then adapt the SmaCross example from the README against a Yahoo Finance data feed before writing my own strategy.
Limit: plotting needs matplotlib >= 1.4.1 and is not supported under pypy.
Done means: you show me the plotted backtest result for the SmaCross example against my own data or symbol, and the strategy code you wrote.
Never place a live order. Paper or testnet until I say live in this chat.
Before you start, ask me: which broker or data feed I want (Interactive Brokers, Oanda, Visual Chart, or CSV/pandas only), and whether this is a backtest or a live connection.

Something wrong here? Tell us โ†’