Browse by type
Build deterministic trading strategies, AI trading agents, and AI trading teams for stocks, options, crypto, futures, forex, prediction markets, SEC filings, FRED macro data, technical indicators, and real brokers. Backtest, paper trade, or run live with the same Python code.
Full docs: lumibot.lumiwealth.com · Managed cloud: BotSpot.trade · MCP: BotSpot for AI coding agents

Start with the open-source docs, then deploy when you are ready: Lumibot documentation · Try a sample Lumibot strategy on BotSpot
pip install lumibot
Save this as my_strategy.py:
from datetime import datetime
from lumibot.strategies import Strategy
from lumibot.backtesting import YahooDataBacktesting
class MyStrategy(Strategy):
def on_trading_iteration(self):
if self.first_iteration:
aapl = self.create_order("AAPL", 10, "buy")
self.submit_order(aapl)
MyStrategy.backtest(
YahooDataBacktesting,
datetime(2023, 1, 1),
datetime(2024, 1, 1),
)
python my_strategy.py
After the backtest works, keep the MyStrategy class and replace the final MyStrategy.backtest(...) call with a broker runner. This example uses Alpaca paper trading:
export ALPACA_API_KEY='your-alpaca-key'
export ALPACA_API_SECRET='your-alpaca-secret'
export ALPACA_IS_PAPER=true
python my_strategy.py
import os
from lumibot.brokers import Alpaca
from lumibot.traders import Trader
ALPACA_CONFIG = {
"API_KEY": os.environ["ALPACA_API_KEY"],
"API_SECRET": os.environ["ALPACA_API_SECRET"],
"PAPER": os.environ.get("ALPACA_IS_PAPER", "true").lower() != "false",
}
broker = Alpaca(ALPACA_CONFIG)
strategy = MyStrategy(broker=broker)
trader = Trader()
trader.add_strategy(strategy)
trader.run_all()
Start with paper trading. When you are ready for live trading, use the same strategy class and switch your broker account/configuration intentionally.
For full setup guides, broker tutorials, AI-agent docs, examples, and deployment notes, use the Lumibot documentation.
Lumibot now includes a built-in AI agent runtime for financial research, reasoning, debate, risk review, and trade execution. Agents can inspect market data, read filings, query indicators, search memory, compare macro context, and submit orders through the same Lumibot strategy loop used by normal backtests and live trading.
Classic Python strategies are still first-class. Lumibot lets you choose the right level of intelligence: fixed rules, AI agents, or a hybrid where Python handles the hard gates and agents reason through evidence.
Built-in AI agent tools include market/account state, order inspection, DuckDB queries, documentation search, Alpaca news when credentials exist, technical indicators, SEC fundamentals and filings, FRED macro data, local memory, and Telegram notifications.
An AI trading team is just a group of agents with different jobs inside the same Lumibot strategy. You can build a single-agent strategy, a specialist research flow, bull/bear/neutral teams, model-vs-model debates, deterministic execution gates, or agent reviewers layered on top of normal Python logic.

Here is one example pattern: a researcher gathers evidence, bull and bear agents debate the trade, and a trader agent decides what to buy or sell.

In this pattern, each agent has a job:
The copy-paste example below implements that exact team. It uses Gemini Flash Lite because it is fast and inexpensive for experiments.
To run it with a broker in paper mode, set your AI and Alpaca credentials and run the file:
export GEMINI_API_KEY='your-key-here'
export ALPACA_API_KEY='your-alpaca-key'
export ALPACA_API_SECRET='your-alpaca-secret'
export ALPACA_IS_PAPER=true
python ai_trading_team_bull_bear_leveraged_etf.py
To backtest the same strategy instead, change IS_BACKTESTING = False to IS_BACKTESTING = True in the runner:
export GEMINI_API_KEY='your-key-here'
python ai_trading_team_bull_bear_leveraged_etf.py
Save this as ai_trading_team_bull_bear_leveraged_etf.py. If an AI key is missing or invalid, Lumibot stops and prints a clear provider key error with a link to create a key.
import os
from datetime import datetime
from lumibot.strategies.strategy import Strategy
class AITradingTeamBullBearLeveragedETFStrategy(Strategy):
parameters = {
"universe": ["TQQQ", "SQQQ", "UPRO", "SPXU", "UDOW", "SDOW", "TNA", "TZA", "TECL", "TECS", "SOXL", "SOXS", "WEBL", "WEBS", "FAS", "FAZ", "LABU", "LABD", "ERX", "ERY", "GUSH", "DRIP", "DRN", "DRV", "TMF", "TMV", "NUGT", "DUST"],
}
def initialize(self):
self.sleeptime = "1D"
model = os.environ.get("AI_TRADING_TEAM_MODEL", "gemini-3.1-flash-lite")
# The first three agents are read-only. They can reason, but cannot trade.
self.agents.create(
name="researcher",
model=model,
allow_trading=False,
system_prompt="Rank the ETFs by upside. Be direct.",
)
self.agents.create(
name="bull",
model=model,
allow_trading=False,
system_prompt="Argue for the strongest money-making trade.",
)
self.agents.create(
name="bear",
model=model,
allow_trading=False,
system_prompt="Point out the biggest risk, briefly.",
)
# Only this final agent can submit orders through Lumibot.
self.agents.create(
name="trader",
model=model,
allow_trading=True,
system_prompt="Buy one ETF from the universe aggressively. Use nearly all cash.",
)
def on_trading_iteration(self):
# Each trading day, pass the same market context through the team.
context = {
"date": self.get_datetime().date().isoformat(),
"universe": self.parameters["universe"],
}
research = self.agents["researcher"].run(
task_prompt="Pick the strongest ETF.",
context=context,
)
bull = self.agents["bull"].run(
task_prompt="Make the bull case.",
context={**context, "research": research.summary},
)
bear = self.agents["bear"].run(
task_prompt="Make the bear case.",
context={**context, "research": research.summary, "bull": bull.summary},
)
self.agents["trader"].run(
task_prompt="Sell anything that is not the pick, then buy the best ETF with nearly all available cash.",
context={**context, "research": research.summary, "bull": bull.summary, "bear": bear.summary},
)
if __name__ == "__main__":
IS_BACKTESTING = False
if IS_BACKTESTING:
from lumibot.backtesting import YahooDataBacktesting
AITradingTeamBullBearLeveragedETFStrategy.backtest(
YahooDataBacktesting,
datetime(2026, 4, 7),
datetime(2026, 5, 22),
)
else:
from lumibot.brokers import Alpaca
from lumibot.traders import Trader
ALPACA_CONFIG = {
"API_KEY": os.environ["ALPACA_API_KEY"],
"API_SECRET": os.environ["ALPACA_API_SECRET"],
"PAPER": os.environ.get("ALPACA_IS_PAPER", "true").lower() != "false",
}
broker = Alpaca(ALPACA_CONFIG)
strategy = AITradingTeamBullBearLeveragedETFStrategy(broker=broker)
trader = Trader()
trader.add_strategy(strategy)
trader.run_all()
Example backtest artifact from this sample strategy:

Backtests are not expected future performance. The point is that the full AI trading team runs inside Lumibot's normal broker and backtest loops, so the decisions, orders, and artifacts are inspectable before you connect real money.
See this AI trading team running live on BotSpot
These examples show different ways to organize an AI trading team. Each page explains the inspiration, the agent flow, how to run it with a broker in paper mode, and how to backtest it.
ai_trading_team_citadel_sector_pods.py.ai_trading_team_warren_buffett_value.py.ai_trading_team_ray_dalio_idea_meritocracy.py.ai_trading_team_bill_ackman_concentrated.py.ai_trading_team_bull_bear_leveraged_etf.py](lumibot/example_strategies/ai_trading$ claude mcp add lumibot \
-- python -m otcore.mcp_server <graph>