SPY Put Credit Spread Rules with Agent-Based Selection
Summary
This strategy sells one SPY put credit spread at a time, using an agent to select contracts from the option chain and a separate agent to manage trades. The research agent looks for a spread 30 to 45 days to expiration, sells a put near 0.16 delta, and buys a put five points lower. The trading agent opens the researched spread when none is held and aims to risk about 2% of the account.
The stated management rules close the position after retaining half of the opening credit, if the cost to close reaches twice that credit, or when 21 days remain. The strategy runs once per day and includes paths for backtesting and live execution. The document provides implementation logic, but no test results, transaction cost assumptions, or evidence that the rules are profitable. Its fixed delta, spread width, and exit thresholds also do not adapt to changing volatility or market conditions.
Key ideas
- The strategy sells SPY put spreads with 30 to 45 days until expiration.
- The short put is selected near 0.16 delta, with a long put five points lower.
- Separate research and trading agents select contracts and manage orders.
- The spread is closed at a half-credit profit target, a loss threshold, or a time stop.
- The code provides no performance results or transaction cost analysis.
Tags
Full text
# ai_credit_spread.py
```py
"""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()
```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.