redditalpha logoredditalpha
← 返回看板
分享
1100%
r/optionsr/options· u/saffystaffie· 1 天前 0

我用 ChatGPT 和 Codex 构建并回测了 SPY 和 QQQ 的 0DTE 交易机器人

投资者摘要中性

作者分享了通过开盘区间突破交易 SPY 和 QQQ 0DTE 期权的 Python 机器人逻辑与回测参数。

帖子正文
高质量模型翻译结果

我使用 ChatGPT 和 Codex 开发并优化这些策略,然后用 Codex 用 Python 编写自动化交易机器人。我通过 PowerShell 启动、配置和管理该机器人。

我的经纪商是 Interactive Brokers,机器人通过运行在桌面端的 Trader Workstation (TWS) 连接,接收市场数据并下达或管理订单。

我从 TradingView 下载了 5 分钟周期的 SPY/QQQ 数据,并对 2026 年 1 月 1 日至 6 月 25 日的数据进行了回测:共 120 个交易日。目标价和止损位衡量的是标的资产的波动,而非期权溢价。

SPY

  • 9:30–10:30 ET 的开盘区间,基于 5 分钟 K 线。
  • 触发条件:价格突破区间上限或下限 $1
  • 在完成一个突破触发点的 5 分钟 K 线收盘后,入场买入当日到期的看涨或看跌期权。
  • 最多使用 20% 可用资金;每天仅允许一个交易设置。
  • 分批平仓:在 +$1.50 时卖出 25%,+$2.25 时再卖 25%,+$3.00 时再卖 25%。
  • 剩余 25% 作为“追涨单”,目标为 +$5.50
  • 硬止损:−$3
  • 若 TP1 在 60 分钟内未达成且 SPY 仍低于 +$0.50,则强制平仓。
  • 强制在 3:30 ET 关闭所有头寸。

SPY 的追涨单仅在开盘区间宽度至少达 $4.50 且至少成交四手合约时才会启用。在 TP2 时,必须满足四个条件中的三个:TP2 在 30 分钟内达成;SPY 在 30 分钟内上涨至少 +$1.50;TP2 前的回调不超过 $0.50;且没有完整的 5 分钟 K 线收盘重新穿过触发点。满足 = 继续持有追涨单以争取 +$5.50;不满足 = 在 TP2 附近卖出追涨单。SPY 的追涨单不会移至盈亏平衡点。

QQQ

  • 9:30–10:00 ET 的开盘区间。
  • 仅当区间宽度在 $4.28$5.14 之间时才交易。
  • 触发条件:价格突破区间上限或下限 $0.75;无需确认 K 线。
  • 最多使用 20% 可用资金;每天仅允许一个交易设置。
  • 分批平仓:在 +$1 时卖出 40%,+$2 时再卖 40%,剩余 20% 作为追涨单,目标为 +$5.50
  • 硬止损:−$5
  • 达到 TP2 后,将追涨单的止损移至盈亏平衡点。
  • 强制在 4:00 ET 关闭所有头寸。

入场执行

机器人以当前期权卖价提交买入限价单,随后每 0.5 秒提高 $0.02,持续最多三秒。若标的资产价格在触发后超过 $0.25,系统将取消未成交部分。部分成交的订单予以保留,不再重试。

IBKR/TWS 速率保护机制

Interactive Brokers 将新订单、修改和撤单均计入操作次数。每次通过 Trader Workstation 下单/修改/撤单前,机器人会检查其速率限制器,确保每两秒不超过六次操作,每十分钟不超过六十次。一旦接近上限,机器人将等待而非频繁发送请求,从而保护入场单、盈利目标、硬止损、过期平仓及强制关闭等指令。

回测结果

SPY:共 38 笔交易,32 胜 6 负,净赚 +57.37 点,平均每日 +1.51 点。

QQQ:共 27 笔交易,25 胜 2 负,净赚 +34.10 点,平均每日 +1.26 点。

合计:活跃于 58/120 个交易日(48%),赢利日 50 天,亏损日 8 天,总收益 +91.47 点,活跃日均 +1.58 点

仅 SPY 活跃:31 天。仅 QQQ 活跃:20 天。两者同时活跃:7 天。

每当两者同时触发时,方向始终一致,因此 QQQ 并非对冲工具——它主要增加了更多交易机会。若同时全仓运行,可获得 +91.47 点收益。若在两者同时触发时拆分仓位,预计收益约为 +79.01 点,且风险相关性更低。

每月合计:1 月 +7.99,2 月 +16.60,3 月 +22.06,4 月 +13.34,5 月 +11.46,6 月 +20.02。

这是基于六个月图表数据的回测,不代表未来盈利能力。下一步是通过 Interactive Brokers TWS 进行模拟盘交易,真实测量成交情况、买卖价差、滑点以及实时期权执行表现。

讨论 · 高赞评论15 条精选
u/options-ModTeam 1· 15 小时前

Removed for RULE: No spam, no cross-posts, no copy/paste of posts.

We incorporate the existing site-wide anti-spam rules explicitly. We consider cross-posting of all types and/or copy/pasting of posts as spam. Posts to this sub are expected to be unique and custom tailored to our community.

u/Professional_Dr_77 1· 15 小时前

“…because I can’t be bothered to write it all…”

Everything after that is irrelevant. Thanks.

u/saffystaffie 1· 15 小时前

Thank you Dr Professional

u/Eves98 1· 18 小时前

Backtesting only helps refine a strategy some. Even paper trading is going to help so much. In both cases you're not having to deal with the fact that sometimes options are just not assigned at your limit price. And that potentially ruins the whole scenario.

u/saffystaffie 1· 18 小时前

Yeah 100%. I can see how people get an account from $2000 to $200,000, and then back down to $2000 again! Scary stuff haha

u/Miamiconnectionexo 1· 20 小时前

the bit about "downloaded 5-minute SPY/QQQ data from TradingView" stands out — TradingView's 5m bars aren't clean for 0DTE backtesting because they include pre-market and after-hours prints that don't align with 9:30-4:00 SPY options settlement. you might be getting phantom signals from 4:05am or 8:00pm candles that flat out don't exist in live 0DTE trading. worth checking if your backtest filters to regular session only, or if those extra candles are inflating your win rate.

u/saffystaffie 1· 18 小时前

Thanks for your reply- so the candles start when the market opens and stop when the market opens, USA time, if that makes sense. One thing that is really bugging me, is that when I tested the same strategy for the second half of last year (after the advice I got from Reddit) June through to December, albeit with 10 min timeframe, the strategy, whilst being in profit, doesn’t hold up nearly as well. And you could say that that’s because you are using a 10 min timeframe, but when I use that for the Jan- June 2026 data, I get more or less the same results as the 5 min timeframe, so I don’t think I can blame it entirely on that. And when just looking at the price movement of 2025, I can see what someone meant by the ‘bullish market’ comment. I am new to all this and only really looked into this after seeing people’s gains on Reddit with spy and 0dte trades, and everyone has to start somewhere right? But to be honest it has kinda motivated me to educate myself further about how you can use further data and patterns to know how the market might react. Obviously ChatGPT and codex and other ai tools are a good way to sift through data quickly, but ultimately you need to make the decision about what data to use. But I guess if it were that easy to just have a simple strategy and have a computer program essentially printing money for you, everyone would be doing it right?! Sorry for the long reply haha

u/live4failure 1· 1 天前

Underlying shouldnt be used to estimate options.. every there are so many other factors than underlying price or volume. If you want to use price action backtesting then try something like TQQQ

u/saffystaffie 1· 1 天前

Thanks very much for the advice, I will definitely look into that!

u/live4failure 1· 1 天前

For sure. Keep grinding. A lot of strategies can make money but not losing money is harder. Made 10k my first month of 0DTE trading and gave it all back already, but now I know what is possible!

u/gapupandfade 1· 1 天前

I have Amibroker and 10+ years of tick data compiled and would most likely run it on a 1 min timeframe if you want me to run it for you

u/saffystaffie 1· 1 天前

That would be really helpful, thank you- I am very new to this, and I realise now that I may have jumped the gun quite a bit when thinking that I might have something special here haha. After using 10 min timeframe for the last six months for last year, I didn’t have nearly the same results as I did this year. Still profitable, but far less so. Is there a way you could possibly send me that tick data please?

u/BitterAd6419 1· 1 天前

Hang on a min so all these trades were on paper trading ?

I was interested till I read that part :) paper trading ain’t live trading, the fills are not real. The live options market on moves really fast and you often don’t get filled because of a sudden move

Run it on live and report back, I bet the results are way different

u/dad-jokes-about-you 1· 1 天前

Hey guys, I used AI to back test and I’m still poor. If this actually worked I probably wouldn’t be posting here and I would be silently stacking money

u/Inevitable-Tea5772 1· 1 天前

Does it go short also?