Put Credit Spread AI Trading Bot

Research agent picks 2 SPY put contracts, trading agent opens and closes the spread, then one 2-leg order

This bot sells a put credit spread on SPY about a month out. You get paid up front and keep the money if SPY stays above the short strike, and the second put caps how much you can lose. Why sell puts? Over more than 32 years, Cboe’s index of selling S&P 500 puts earned almost the same yearly return as the S&P 500 (9.54% vs 9.80%) with much smaller swings (Bondarenko for Cboe, 2019).

How it works

  1. Research agent checks SPY’s price, trend, and the live option chain. It picks an expiration 30 to 45 days out, a short put near 0.16 delta, and a long put 5 points lower.

  2. Trading agent first manages any spread you hold. It closes it when you have kept half the premium, when closing costs twice the premium, or when 21 days are left.

  3. If you hold no spread, the trading agent sells the new one, risking about 2% of the account. The bot checks once a day.

Run it on BotSpot

Run this bot on BotSpot without installing anything. BotSpot runs LumiBot in the cloud, backtests it, and connects it to your broker.

Backtest tear sheet

GPT-6 Luna, January 5 to 23, 2026, Alpaca option prices, $100,000 start. The bot sold a 4-contract SPY put spread for $0.44, closed it for $0.24 (about half the credit kept), sold a new one, closed that at its 2x loss limit, and sold a third. Each spread went in as one order and risked about 2% of the account. It ended at $99,976, about flat, while SPY was flat too.

Backtest tear sheet for the Put Credit Spread AI Trading Bot

Open the full tear sheet. A short backtest shows the bot works as written. It is not a promise of future returns.

The code

The whole bot is one short file. The prompts are plain English, and they are the strategy.

"""Put Credit Spread AI Trading Bot.

Sells a put credit spread on SPY about a month out and keeps the premium if SPY
stays above the short strike. A research agent picks the two contracts from the
live option chain. A trading agent opens the spread and closes it at the profit
target, the loss limit, or the time stop.
"""

from lumibot.strategies import Strategy


class AICreditSpreadStrategy(Strategy):
    parameters = {"symbol": "SPY"}

    def initialize(self):
        self.sleeptime = "1D"
        self.agents.create(
            name="researcher",
            allow_trading=False,
            system_prompt=(
                "Look at the symbol's price and option chain. Find a put credit spread 30 to 45 days out: "
                "sell a put near 0.16 delta and buy a put 5 points lower. Report the two contracts and the "
                "credit, and any spread we already hold with its cost to close. Do not trade."
            ),
        )
        self.agents.create(
            name="trader",
            allow_trading=True,
            system_prompt=(
                "Hold one put credit spread at a time. Close it when we have kept half the credit, when "
                "closing costs twice the credit, or when 21 days are left. If we hold none, sell the "
                "researched spread. Risk about 2% of the account."
            ),
        )

    def on_trading_iteration(self):
        facts = {"symbol": self.parameters["symbol"]}
        research = self.agents["researcher"].run(task_prompt="Find today's put credit spread.", context=facts)
        self.agents["trader"].run(
            task_prompt="Manage or open the spread.", context={**facts, "research": research.summary}
        )


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

    if IS_BACKTESTING:
        from lumibot.backtesting import AlpacaBacktesting

        AICreditSpreadStrategy.backtest(AlpacaBacktesting)
    else:
        AICreditSpreadStrategy().run_live()

Run it yourself

pip install lumibot
python -m lumibot.example_strategies.ai_credit_spread

Put these in your .env file: OPENAI_API_KEY, and your broker keys (for example ALPACA_API_KEY, ALPACA_API_SECRET, and ALPACA_IS_PAPER=true for paper trading). With IS_BACKTESTING=false the bot trades. With IS_BACKTESTING=true it backtests instead; set BACKTESTING_START and BACKTESTING_END to pick the dates, and start with a week or two, because every AI call costs a little. Option and minute-bar backtests use Alpaca’s free history, so paper Alpaca keys are enough.

Good to know

  • A sharp market drop can turn a credit spread into a full loss. Paper trade first.

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