Backtesting Trading Strategies in Python with LumiBot¶
Choose a backtesting source from the strategy’s asset class and required bar interval:
Need |
Start with |
Typical granularity |
Setup |
|---|---|---|---|
Daily stocks and ETFs |
Daily |
No data-provider credentials |
|
Intraday stocks and options |
Minute, hour, and daily |
Data Downloader and provider access |
|
Stocks, options, forex, or crypto |
Intraday and daily |
Polygon.io API key |
|
Futures and market-data schemas |
Tick through daily, by dataset |
Databento API key and dataset access |
|
Your own stock or futures data |
Whatever the supplied file contains |
Local data prepared in LumiBot’s format |
|
Interactive Brokers history |
Provider-supported intervals |
Client Portal and Data Downloader access |
|
Options with your own Alpaca account |
Minute and daily |
Alpaca API key (free accounts include option history from about February 2024) |
|
Prediction contracts |
Polymarket |
Market price history |
Polymarket market identifiers |
Use Yahoo for the simplest free daily-stock example. Use ThetaData when a stock or option strategy needs intraday history, and use Pandas when you already own the data and can prepare it in LumiBot’s input format.
Managed Backtesting on BotSpot¶
Backtesting is better on BotSpot when you want to move faster than a local setup. BotSpot already has the workflow around Lumibot: hosted data setup, parallel backtest workers, generated artifacts, charts, logs, and the path from a passing backtest into paper or live trading.
Backtesting data included. Use supported hosted stock, futures, options, macro, filings, and other data sources without sourcing every vendor, API key, downloader, and local file yourself. Some data is included; premium datasets can be much cheaper than buying direct subscriptions.
Parallel experiments. Launch multiple strategy variants on BotSpot servers and compare results instead of waiting for one local run at a time.
Better artifacts. Inspect charts, trades, logs, files, decisions, and audit history from one place instead of stitching together local output folders.
Lumibot-tuned iteration. BotSpot’s AI workflows and MCP tools understand Lumibot strategy structure, so Codex, Claude Code, Cursor, and other agents can run backtests and inspect results instead of only editing Python.
Ready for deployment. A strategy that survives backtesting can move into paper or live trading with supported broker connections, monitoring, alerts, and kill-switch controls already available.
Agentic Backtesting¶
Lumibot also supports agentic backtesting. A strategy can create one or more AI agents, run them from normal lifecycle methods, analyze point-in-time data with DuckDB, and replay identical agent runs from cache on the next backtest instead of paying for another model call.
This matters if you want:
an AI trading agent that makes decisions inside
on_trading_iteration()an LLM trading bot that can also be tested historically
external MCP tools attached to a strategy
backtest/live parity for agent-driven strategies
See Build AI Trading Agents in Python with LumiBot for the full agent runtime guide and usage examples.
Files Generated from Backtesting¶
When you run a backtest, several important files are generated, each prefixed by the strategy name and the date. These files provide detailed insights into the performance and behavior of the strategy.
Contents:
- How to Backtest a Python Trading Strategy with LumiBot
- Files Generated from Backtesting
- Backtesting Function
- Backtesting Performance (Speed + Parity)
- Free Daily Stock Backtesting with Yahoo and LumiBot
- Pandas (CSV or other data)
- Polygon.io Backtesting
- Databento Backtesting with LumiBot
- ThetaData Options and Stock Backtesting with LumiBot
- Interactive Brokers (REST) Backtesting
- Status
- Quick Start
- Supported Data
- Daily Stocks/Indexes: Warmup + Corporate Actions
- How History Is Downloaded (stocks and indexes)
- Futures Exchange Routing (auto + override)
- Expired Futures Contracts (conids)
- Caching
- Multi-provider routing (Theta + IBKR)
- Crypto futures and perpetuals
- Market Data Subscriptions (IBKR)
- Authentication / Session Behavior
- Configuration Notes
- Alpaca Backtesting
- LumiBot Backtest Tear Sheets and Performance Reports
- Trades Files
- Indicators Files
- Logs CSV
Learn to build and backtest with Rob¶
Learn with Rob Grzesik, creator of LumiBot. Join the FREE AI challenge.