LumiBot AI Trading¶
Build AI trading agents. Backtest them. Trade with the same strategy.
LumiBot is a free, open-source Python framework for building trading bots. Write your own trading rules, let AI agents make decisions, or combine both. LumiBot runs your strategy against historical data, records its trades and results, and connects it to supported brokers for paper or live trading.
Why build with LumiBot?¶
Native AI trading: agents research, reason and place orders from your prompts.
Backtest before trading: evaluate AI decisions and Python rules on historical data, with charts, trades and logs.
Same strategy for backtesting and trading: keep your strategy class; change the data source and broker runner.
Multiple asset classes: stocks, options, futures, forex, crypto and prediction markets through supported brokers.
The decision reaches a broker. Inspect orders, fills and decision records. How execution works.
Tip
Build faster with BotSpot MCP. Connect your assistant for free to get LumiBot strategy-building skills, research data and tools for backtests and deployment. See what your assistant gets.
Three ways to build a strategy¶
AI-native strategies
Python strategies
Hybrid strategies
Build an AI-native strategy¶
The trading rules go in the prompt. This example creates one trading agent
in initialize() and calls it on every on_trading_iteration(). Edit
system_prompt to change its instructions; task_prompt starts each review.
You can add research agents later and pass their answers to the trading agent.
Install LumiBot with Python 3.10+ and set your model credentials. This example uses an OpenAI model and Yahoo daily prices; model calls incur charges.
pip install lumibot
export OPENAI_API_KEY="your-openai-api-key"
Save this as my_ai_strategy.py:
from datetime import datetime
from lumibot.backtesting import YahooDataBacktesting
from lumibot.strategies import Strategy
class MyAIStrategy(Strategy):
def initialize(self):
self.sleeptime = "1D"
self.agents.create(
name="trader",
default_model="openai/gpt-6-luna",
reasoning_effort="medium",
allow_trading=True,
system_prompt=(
"Trade SPY using its last 20 completed daily bars. "
"Buy when the latest completed close is above their average; "
"sell an existing position when it is below. Otherwise hold. "
"Keep the position at or below 10% of portfolio value. "
"Check cash, positions and open orders before acting. "
"No shorting or leverage. Do not duplicate pending orders. "
"Use only information available as of the strategy time."
),
)
def on_trading_iteration(self):
self.agents["trader"].run(
task_prompt="Review SPY, apply your rules and verify any orders.",
context={"as_of": self.get_datetime().isoformat()},
)
if __name__ == "__main__":
MyAIStrategy.backtest(
YahooDataBacktesting,
datetime(2026, 4, 6),
datetime(2026, 4, 11),
budget=100_000,
benchmark_asset="SPY",
)
python my_ai_strategy.py
Review the agent’s decisions, orders and backtest charts. This is an example of the API, not a claim that the trading rule is profitable. The AI quickstart shows a complete researcher-and-trader team. To run that existing example directly:
python -m lumibot.example_strategies.ai_researcher_trader
Build a Python strategy¶
Here the decisions are Python rules. This complete example buys 10 AAPL shares
on its first iteration and holds them. Save it as my_strategy.py:
from datetime import datetime
from lumibot.backtesting import YahooDataBacktesting
from lumibot.strategies import Strategy
class MyStrategy(Strategy):
def on_trading_iteration(self):
if self.first_iteration:
order = self.create_order("AAPL", 10, "buy")
self.submit_order(order)
MyStrategy.backtest(
YahooDataBacktesting,
datetime(2023, 1, 1),
datetime(2024, 1, 1),
)
python my_strategy.py
See Start with LumiBot for setup and LumiBot Python Trading Examples for indicators, options and other Python strategies.
Build a hybrid strategy¶
Keep the Python rules you need and add an agent for a specific decision.
For example, a Python moving-average signal can trigger a read-only AI risk
review. Python checks the structured answer, sizes the position and submits
the order. Give that reviewer allow_trading=False; your Python code owns
the order submission. See Design Your AI Trading Team for the code and
Run your first AI backtest for structured answers.
Run the same strategy with a broker¶
The strategy class can stay the same. The code that starts it must select a
backtest or a broker run: Strategy.backtest(...) runs historical data;
Trader.run_all() runs a strategy with a configured broker.
IS_BACKTESTING=false alone cannot change a backtest-only runner.
See Backtest, paper, or live: choose the runner and the broker guides for setup.
Connect your AI assistant¶
Use a coding assistant to help write any of these strategies. This is separate from the AI agents that run inside an AI-native strategy: the assistant helps you build and test the code; the strategy’s agents make its trading decisions.
What BotSpot MCP adds
Use Claude, ChatGPT, Codex, Cursor, VS Code or another MCP-compatible assistant? Connect the free BotSpot MCP for:
Skills: build LumiBot strategies.
Free data: news, economics and SEC filings.
Backtests: run tests and read charts.
Cloud hosting: low-cost scheduled bots.
Community: share bots and discuss trades.
Marketplace: discover and publish strategies.
Broker linking: connect accounts through BotSpot.
For local coding help, install the free LumiBot trading skills.
To give agents inside a running strategy BotSpot’s research tools, see
LumiBot strategy agents and lumibot connect botspot.
Explore the framework¶
Strategy examples
Backtesting and trading
API and comparisons
Want help building your first AI trading bot?¶
Join the free challenge with Rob Grzesik, creator of LumiBot. Follow the training and learn how to build and backtest a trading strategy.
Join the free challenge or explore the AI Trading Bootcamp.
Table of Contents¶
Start here
AI trading
Build strategies
Indicators
- Custom Indicators: What They Can Do
- Build Your First Indicator
- Settings and Outputs
- Price Chart or Own Pane
- Indicators in Backtests
- Indicators in Live Strategies
- Stream Live from a Crypto Exchange
- Outside Data in an Indicator
- Matching TradingView Numbers
- Indicator Examples
- Compare and FAQ
- Indicator Reference
- The self.indicators Accessor
Backtest and trade
Frequently asked questions¶
What is LumiBot?¶
LumiBot is a Python framework for building trading strategies. You can write strategies with your own Python rules, with AI agents, or with both. You can backtest a strategy on historical data and then connect the same strategy class to a supported broker for paper or live trading.
Is LumiBot free and open source?¶
Yes. LumiBot is free and open source under the GNU General Public License version 3 (GPL-3.0). The source code is on GitHub at github.com/Lumiwealth/lumibot.
Who created LumiBot?¶
LumiBot was created by Rob Grzesik and is published by Lumiwealth. The project
lives in the Lumiwealth/lumibot repository on GitHub.
How do I install LumiBot in Python?¶
Run pip install lumibot. To get the newest release later, run
pip install lumibot --upgrade. LumiBot needs Python 3.10 or newer.
Do I need AI or an API key to use LumiBot?¶
Python strategies run your rules directly. AI-native and hybrid strategies
that call a model need that provider’s authentication. The AI example above
uses OPENAI_API_KEY and billed model calls. Data-provider credentials
depend on the data you choose. See Run your first AI backtest.
Do I need a broker account to run a backtest?¶
No. A backtest uses historical data, not a broker. The quickstart backtest on this page uses free Yahoo Finance data and no broker account. You only need a broker account when you want to paper trade or trade live.
Which brokers does LumiBot work with?¶
LumiBot connects to 100+ brokers and crypto exchanges: Alpaca, Interactive Brokers, Tradier, Schwab, Tradovate, ProjectX, Bitunix, Polymarket, and the crypto exchanges your installed CCXT version lists. See Trading Brokers Supported by LumiBot for brokers by type, or the A to Z list for every guide.
Can I use the same code for backtesting and live trading?¶
Yes. The strategy class can stay the same. The code that starts it decides
whether it runs as a backtest or against a broker. Setting
IS_BACKTESTING=false alone does not turn a backtest-only file into paper or
live trading. See Backtest, paper, or live: choose the runner for how each mode starts.
Where can I get help with LumiBot?¶
Start with the Frequently Asked Questions (FAQ) and Common Mistakes and How to Avoid Them pages. You can also ask questions in the community links in the sidebar, including the LumiBot GitHub repository, Reddit, and Discord.