Skip to content

OpenBacktesting: Python backtesting framework

View Markdown

Write a Python strategy, run it on historical OHLC data, and inspect trades and performance. This manual is for people using the framework.

Run your first backtest → — a complete script using bundled data, with no data download or application integration required.

Choose your next task

I want to… Read
Load market data or set asset rules Data, timeframes, and instruments
Define entry and exit logic Strategy
Set cash, fees, and execution timing Backtest
Place, cancel, protect, or close trades Orders, Position, and Trade · Account and events
Calculate or compose indicators Indicator usage · Full catalog
Make strategy parameters configurable Inputs
Read return, equity, and trade details Results · Portfolio export
Compare parameter values Best-run optimization · Saved experiments
Add visuals or colors Plotting declarations · Color
Reuse signal/trailing strategies or resample data Helpers
Run a strategy file with declared defaults Decorator and runtime

How the pieces fit

  1. Prepare a pandas DataFrame containing one asset's bars.
  2. Define a Strategy: register indicators in init(), read the current bar and place orders in next().
  3. Construct Backtest(data, MyStrategy, ...) and call .run(...).
  4. Read statistics and execution tables, or export a Portfolio report.

Order tracks a request, Trade tracks one filled lot, and Position summarizes open exposure. An order normally executes at the next bar's open. Indicator values can be invalid during initial history; your strategy checks them before acting.

Tutorials and scope

First backtest · Trading rules · Indicator recipes · Runnable examples

The engine models one asset and one settlement currency per run. It exports plotting data but includes no chart renderer or live-trading connection. See supported boundaries before interpreting results.