A systematic options trading strategy that sells credit spreads on SPX (S&P 500 Index) options expiring the same day (0DTE - Zero Days to Expiration).
Read more about the strategy on the blog: 0DTE Credit Spread Strategy on SPX
This volatility-selling strategy trades SPX options based on the VIX1D index expected move and market trend direction. The strategy aims to collect premium by selling credit spreads positioned outside the expected daily price range.
- Starting Capital: $10,000
- Backtest Duration: 537 days
- Win Rate: 78.17%
- Expected Value per Trade: $25.73
- Annualized Returns: 15.74%
- Sharpe Ratio: 0.97
- Max Drawdown: -16.21%
- Entry Time: 9:45 AM EST daily
- Expected Move Calculation: Uses VIX1D index to calculate half-day expected move
- Formula:
(VIX1D / √252) × 0.5 × SPX Price
- Formula:
- Market Regime Detection: Determines trend using moving averages
- Trade Selection:
- Bullish Regime (uptrend): Sell Put Credit Spread
- Short Put: At or near lower expected move boundary
- Long Put: $5 below short strike
- Bearish Regime (downtrend): Sell Call Credit Spread
- Short Call: At or near upper expected move boundary
- Long Call: $5 above short strike
- Bullish Regime (uptrend): Sell Put Credit Spread
- Maximum loss per trade: pread width minus premium collected, often around $4.00
- Positions held until expiration (0DTE)
- No intraday management
- Single contract per trade
.
├── main.py # Main backtesting engine
├── calcs.py # Market regime detection (ADX-based)
├── utils.py # Polygon.io data client wrapper
├── web_scraper_day.py # Economic calendar event scraper (daily)
├── web_scraper_month.py # Economic calendar event scraper (monthly)
├── trades.csv # Historical trade log
└── results.ipynb # Analysis and visualization notebook
Create a .env file with your Polygon.io API key:
POLYGON_API_KEY=your_api_key_here
Edit main.py to configure backtest parameters:
# Line 10-11: Set date range
trading_days = calendar.valid_days(start_date="2025-08-15", end_date="2025-08-15")- SPX Price Data: Polygon.io (I:SPX)
- VIX1D Data: Polygon.io (I:VIX1D)
- Options Chains: Polygon.io SPX options
- Economic Events: Web scraping (optional for filtering)
The backtest generates:
trades.csv: Detailed trade log with strikes, P&L, and market conditions- Console output with real-time trade execution details
- Performance visualizations (in Jupyter notebook)
The blog post mentions additional enhancements:
- Economic event filtering (avoid trading on high-impact events)
- Position sizing adjustments based on volatility environment
- Performance improvements from selective trade filtering
This code is for educational and research purposes only. Options trading involves substantial risk and is not suitable for all investors. Past performance does not guarantee future results. This is not financial advice.
MIT License
Follow for more trading strategies and analysis: ThunderAlgo Substack