MCPcopy Index your code
hub / github.com/Lumiwealth/lumibot

github.com/Lumiwealth/lumibot @v4.5.66

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.5.66 ↗ · + Follow
11,087 symbols 47,584 edges 601 files 3,069 documented · 28% updated 2d agov4.5.74 · 2026-07-08★ 1,79762 open issues

Browse by type

Functions 9,807 Types & classes 1,103 Endpoints 177
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CI Status Coverage PyPI Python License: MIT

Lumibot: Backtestable AI Agents and Python Algorithmic Trading

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

Lumibot AI trading agents overview

What You Can Build

  • Deterministic strategies: normal Python logic, indicators, if statements, scheduled rules, position sizing, and risk controls.
  • AI-agent strategies: one or more agents that reason through evidence, call tools, write memory, and optionally place orders.
  • Backtests: replay historical data and simulated orders with artifacts you can inspect.
  • Paper or live trading: reuse the same strategy code with real broker state and real order routing.

Start with the open-source docs, then deploy when you are ready: Lumibot documentation · Try a sample Lumibot strategy on BotSpot

Quick Start

Backtest a strategy

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

Run the same strategy with a paper broker

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.

AI Trading Team

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.

Design Your AI Trading Team

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.

Design your AI trading team with Lumibot

Example: Research, Bull, Bear, and Trader Agents

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.

Lumibot AI trading team workflow

In this pattern, each agent has a job:

  1. Research Agent: builds the evidence pack from market data, filings, fundamentals, news, macro data, and indicators.
  2. Bull Agent: turns that evidence into the strongest long thesis.
  3. Bear Agent: challenges the thesis, looks for risk, and argues for avoiding, delaying, or reducing the trade.
  4. Trader / Portfolio Manager Agent: checks cash, positions, open orders, and risk limits, then decides whether to trade.

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:

AI trading team backtest tear sheet compared to SPY

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

More AI Trading Team Examples

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.

  1. Citadel sector pods AI trading team: inspired by the pod-style structure associated with Ken Griffin's Citadel: sector specialists pitch their best ideas, a risk manager challenges crowding and drawdown risk, and a portfolio manager rotates into the strongest sector ETF. Watch it live on BotSpot. Source: ai_trading_team_citadel_sector_pods.py.
  2. Warren Buffett value AI trading team: uses AI agents like a patient value-investing desk: one agent digs into business quality and annual reports, one demands valuation discipline, and the portfolio manager only buys the best long-term compounder. Watch it live on BotSpot. Source: ai_trading_team_warren_buffett_value.py.
  3. Ray Dalio idea meritocracy AI trading team: turns Bridgewater-style thoughtful disagreement into a macro ETF workflow, with growth, inflation, liquidity, and disagreement agents arguing before the trader acts. Watch it live on BotSpot. Source: ai_trading_team_ray_dalio_idea_meritocracy.py.
  4. Bill Ackman concentrated AI trading team: inspired by Pershing Square-style concentrated investing: find one great business, make the activist bull case, attack it like a short seller, then let the portfolio manager take a focused position if the thesis survives. Watch it live on BotSpot. Source: ai_trading_team_bill_ackman_concentrated.py.
  5. Bull/bear leveraged ETF AI trading team: a fast, aggressive demo where bull and bear agents debate leveraged long and inverse ETFs before the trader rotates into one high-conviction ETF. Watch it live on BotSpot. Source: [ai_trading_team_bull_bear_leveraged_etf.py](lumibot/example_strategies/ai_trading

Core symbols most depended-on inside this repo

Shape

Method 6,378
Function 3,429
Class 1,103
Route 177

Languages

Python82%
TypeScript18%

Modules by API surface

docsrc/_html/bootstrap/js/bootstrap.bundle.js388 symbols
docsrc/_html/bootstrap/js/bootstrap.bundle.min.js334 symbols
docsrc/_html/bootstrap/js/bootstrap.js317 symbols
docsrc/_html/bootstrap/js/bootstrap.esm.js316 symbols
docsrc/_html/bootstrap/js/bootstrap.esm.min.js303 symbols
docsrc/_html/bootstrap/js/bootstrap.min.js296 symbols
tests/test_thetadata_helper.py221 symbols
lumibot/components/agents/builtins.py154 symbols
lumibot/strategies/strategy.py144 symbols
lumibot/tools/thetadata_helper.py136 symbols
lumibot/brokers/broker.py129 symbols
lumibot/backtesting/backtesting_broker.py125 symbols

For agents

$ claude mcp add lumibot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page