AI Iron Condor Trading Bot

One researcher informs one trader; Python observes each minute without model calls; new events wake the trader for management.

This example considers a short iron condor on SPY near the market close. A researcher assesses the opportunity; a dedicated trader chooses the contracts, quantity and prices, places orders and manages risk. Protective options bound the expiration payoff, while quiet minute observations use no model. The trader may decline an unsuitable setup.

View or Run on BotSpot Marketplace

Explore live AI trading bots, cloud backtests, and one-click broker connections on BotSpot Marketplace without local setup.

How it works

  1. During the final 15 regular-session minutes, the research agent reviews dated volatility, trend and event evidence. The policy excludes entry when the previous completed VIX close exceeds 25. Known imminent major releases or demonstrated breakout/gap risk can rule out a setup; a missing calendar alone is not a veto.

  2. The trader evaluates listed next-trading-day options near 0.14 absolute short delta with one-dollar protective wings. It chooses an integer package count within a 3% account-value maximum-loss budget and submits the related legs together with a net limit.

  3. Python observes the trader’s saved conditions each minute. Related new warnings start one decision cycle; quiet observations do not call either model. The trader is instructed to review closing when SPY crosses 40% of the distance from the short-strike midpoint toward either short strike.

  4. The trader manages the held package and closes residual legs no later than 30 minutes before the expiration session ends. It reconciles working orders, partial fills and assignment obligations before a later entry. Python does not decide or submit those actions.

Run it on BotSpot

BotSpot provides strategy creation, backtesting and broker connections. This example’s attention API shipped in LumiBot 4.6.52. Confirm your installed runtime, options-account compatibility and model funding before a start. Matching example revisions are saved on BotSpot, but no running bot or Marketplace listing is claimed. Hosted Login with ChatGPT funding was still pending as last checked November 11, 2026; local subscription login does not establish hosted availability.

Want guided training to customize or build your own AI trading bots? Explore BotSpot Courses or join the free AI Trading Challenge.

Audited local backtest

A local LumiBot 4.6.52 run over October 5–16, 2026 completed seven condor entries and seven closes, ending flat. Starting equity was $100,000; ending equity was $99,985.60, a $14.40 loss after $36.40 of assumed fees. Fees were modeled at $0.65 per contract per side. Independent accounting and remaining-position audits reported no issues.

The same ten-session study ran the bullish call spread and the two-long/one-short call replacement. They lost $184.30 and $467.95 respectively and remained open. Minute Alpaca trade bars approximate fills; historical executable bid/ask and simultaneous package size were unavailable. These results prove mechanics and accounting, not profitability or live execution.

See the three-example report, actual curves, inference usage and source links. The report keeps local proof separate from BotSpot execution and Marketplace availability.

The code

The prompts contain the strategy decisions. The shared attention component observes conditions and coordinates agents; it does not choose quantities, prices or orders.

"""AI-owned iron condor with inexpensive minute observations.

One researcher supplies evidence; one trader owns every trading decision and
order. The trader saves its next attention conditions. Quiet minutes invoke no
model. This example requires the attention API in the installed LumiBot runtime.
Historical Alpaca option bars do not establish executable historical bid/ask.
"""
from datetime import timedelta

from lumibot.strategies import Strategy


class AIIronCondorStrategy(Strategy):
    parameters = {"symbol": "SPY", "model": None, "estimated_contract_fee": 0.65}

    def initialize(self):
        self.sleeptime = "1M"
        self.minutes_before_closing = 0
        self.agents.create(
            name="researcher", allow_trading=False, allow_network=True, model=self.parameters["model"],
            reasoning_effort="high", system_prompt=(
                (
                'Research the supplied underlying for a short iron condor held overnight through the next '
                'trading session. Use dated volatility, trend and event evidence, including the previous '
                'completed VIX close. Focus on material events inside that holding window. Distinguish known '
                'events from unavailable calendar evidence; give the trader a compact dated assessment, '
                'contrary evidence and uncertainty. Do not trade. '
            )
            ),
        )
        self.agents.create(
            name="trader", allow_trading=True, model=self.parameters["model"],
            reasoning_effort="high", system_prompt=(
                (
                'Trade at most one short/net-credit iron condor on the supplied underlying. Consider a new '
                'setup only in the final 15 regular-session minutes, at most once per session, using this '
                "session's setup research. Require the previous completed VIX close at or below 25. Use next- "
                'trading-day expiry, short strikes near 0.14 absolute delta and one-dollar outer wings. '
                'Compare at most three candidates. You choose integer package count; maximum loss including '
                'estimated round-trip per-contract fees must fit 3% of current account value. The supplied '
                'fee is an estimate, not a broker fee claim. '
                'The mandate is routine defined-risk premium collection when the priced range is reasonable. '
                'Compare candidate premiums and risk before deciding; decline for a concrete limit, known '
                'imminent major release or demonstrated breakout/gap risk. Ordinary mixed news or a missing '
                'calendar is not itself a veto. '
                'Set underlying review boundaries 40% of the distance from the short-strike midpoint toward '
                'either short strike; a breach requires your close decision. Close remaining exposure no '
                'later than 30 minutes before the expiration session ends. Leave the next eligible setup '
                'review after closure. Atomic market exits are permitted if a limit cannot meet a required '
                "close deadline. Follow LumiBot's shared options and attention guidance; you own every "
                'trading decision. '
            )
            ),
        )

    def before_starting_trading(self):
        if not self.vars.get("attention_started", False):
            self.agents.attention.watch(owner="lifecycle", watch_id="initial_review",
                operation_id="initial_setup", metric="time", comparison="gte",
                value=(self.get_datetime() + timedelta(seconds=max(
                    0, (self.broker.get_time_to_close() or 0) - 15 * 60))).isoformat(),
                reason="Initial setup review; verify entry eligibility under your policy",
                review_scope="setup")
            self.vars.set("attention_started", True)
        self.on_trading_iteration()

    def on_trading_iteration(self):
        self.agents.attention.poll()
        self.agents.attention.dispatch_team(decision_agent="trader", research_agents=["researcher"],
            context={"symbol": self.parameters["symbol"],
                     "estimated_contract_fee": self.parameters.get("estimated_contract_fee", 0.65),
                     "estimated_contract_fee_units": "USD per contract per side"})

    def on_strategy_end(self):
        self.agents.attention.join()

    def on_abrupt_closing(self):
        self.agents.attention.join()


if __name__ == "__main__":
    from lumibot.credentials import IS_BACKTESTING

    if IS_BACKTESTING:
        from lumibot.backtesting import AlpacaBacktesting
        from lumibot.entities import TradingFee

        fee = TradingFee(per_contract_fee=AIIronCondorStrategy.parameters["estimated_contract_fee"])
        AIIronCondorStrategy.backtest(AlpacaBacktesting, buy_trading_fees=[fee], sell_trading_fees=[fee])
    else:
        AIIronCondorStrategy().run_live()

Run it yourself

Use an installed LumiBot version containing the attention API before running this source. Configure the intended model funding and Alpaca data connection. For local Login with ChatGPT, follow Use your ChatGPT subscription and set the strategy’s model parameter to chatgpt/gpt-6-luna; hosted managed funding uses its normal model route and a separate connected account.

python -m lumibot.example_strategies.ai_iron_condor

Set IS_BACKTESTING=true, BACKTESTING_START and BACKTESTING_END for a backtest. Otherwise the module uses its configured broker. A paper Alpaca account alone does not establish all data permissions. Historical option trade bars are an approximation for fills, not proof of historical executable bid/ask prices.

Good to know

  • A research-and-trading decision can contain several model requests and tool continuations. Measure actual requests, tokens and latency; do not assume one call per day or a fixed backtest cost.

  • The short local historical study lost money. Neither its audited accounting nor the policy instructions establish a profitable edge.

  • Expiration, early exercise, assignment, fees and execution costs can affect actual losses. The trader must reconcile resulting positions and obligations; a submitted close is not a confirmed flat account.

See AI Trading Bot Examples for more AI trading bots and Backtest, paper, or live: choose the runner for backtest and live runners.