Managing a Daily SPY Bear Call Spread with AI Agents
Summary
This Python strategy outlines an automated same-day options approach on SPY. A research agent reviews the underlying and calls expiring that day, proposing a bear call spread by selling a call near a target delta and buying a higher-strike call. A separate trading agent may open one spread per day, with the code passing its research summary into the trading decision. The strategy is checked every 15 minutes.
The instructions specify approximate account risk, early exits based on retained credit or rising close costs, and an exit if SPY moves above the short strike. New positions are barred near the end of the session. The document includes a backtesting entry point, but no test results, assumptions about option fills, or evidence of profitability. Its rules are implementation prompts rather than a fully specified execution or risk model; actual outcomes would depend on options liquidity, spread pricing, slippage, and the agents' decisions.
Key ideas
- The strategy sells a same-day SPY call spread, with the short call chosen near a specified delta and a higher call bought for protection.
- A research agent identifies candidate contracts and reports existing position details to a trading agent.
- The trader is instructed to open no more than one spread per day and to limit approximate account risk.
- Exit conditions include capturing part of the credit, rising close costs, or SPY moving above the short strike.
- The code offers a backtesting route but reports no performance or execution evidence.
Tags
Full text
# ai_0dte_options_trading_bot.py
```py
"""0DTE Options AI Trading Bot.
Sells a same-day (0DTE) bear call spread on SPY, the S&P 500 ETF, and lets it
expire worthless when SPY stays below the short strike. A research agent checks
SPY and today's expiring calls every 15 minutes. A trading agent opens one spread
a day and closes it early when the trade goes wrong.
"""
from lumibot.strategies import Strategy
class ZeroDTEOptionsTradingBot(Strategy):
parameters = {"symbol": "SPY"}
def initialize(self):
self.sleeptime = "15M"
self.agents.create(
name="researcher",
allow_trading=False,
system_prompt=(
"Look at the symbol's price and the calls that expire today. Find a bear call spread: sell "
"the call near 0.20 delta and buy the call 5 points higher. 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=(
"Sell one bear call spread that expires today, once a day. Risk about 1% of the account. "
"Close it early when we have kept half the credit, when closing costs twice the credit, or "
"when the price rises above the short strike. Do not open a new spread in the last 30 minutes "
"of the day."
),
)
def on_trading_iteration(self):
facts = {"symbol": self.parameters["symbol"]}
research = self.agents["researcher"].run(task_prompt="Check today's 0DTE call spread.", context=facts)
self.agents["trader"].run(
task_prompt="Manage or open today's spread.", context={**facts, "research": research.summary}
)
if __name__ == "__main__":
from lumibot.credentials import IS_BACKTESTING
if IS_BACKTESTING:
from lumibot.backtesting import AlpacaBacktesting
ZeroDTEOptionsTradingBot.backtest(AlpacaBacktesting)
else:
ZeroDTEOptionsTradingBot().run_live()
```Shown in full with attribution under the source's licence. Licence: GPL-3.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.