Skip to content

Repository files navigation

SPX 0DTE Credit Spread Strategy

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

Strategy Overview

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.

Key Performance Metrics

  • 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%

How It Works

Trade Execution Rules

  1. Entry Time: 9:45 AM EST daily
  2. Expected Move Calculation: Uses VIX1D index to calculate half-day expected move
    • Formula: (VIX1D / √252) × 0.5 × SPX Price
  3. Market Regime Detection: Determines trend using moving averages
  4. 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

Risk Management

  • 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

Project Structure

.
├── 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

Setup

Create a .env file with your Polygon.io API key:

POLYGON_API_KEY=your_api_key_here

Configuration

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")

Data Sources

  • 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)

Output

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)

Strategy Enhancements

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

Disclaimer

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.

License

MIT License

Author

Follow for more trading strategies and analysis: ThunderAlgo Substack

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages