DEV Community

tomasz dobrowolski
tomasz dobrowolski

Posted on

Max Pain in Options: The Math, the Mechanics, and How to Query It via API

If you've ever watched SPY drift inexplicably toward a specific strike on expiration Friday — no news, no catalyst — you've seen max pain in action.

This post explains what max pain is, how it's calculated, why it works mechanically, and how to pull it programmatically.

What Is Max Pain?

Max pain is the strike price where the total intrinsic value paid out across all open option contracts is minimised. In other words: the settlement price where dealers keep the most premium.

The calculation iterates over every possible settlement price and sums the payouts:

Pain(K) = Σ max(K - K_put, 0) × OI_put + Σ max(K_call - K, 0) × OI_call
Enter fullscreen mode Exit fullscreen mode

The strike K that minimises Pain(K) is max pain. The inputs are just open interest by strike — calls and puts separately.

Why Does Price Move Toward It?

Delta hedging. When dealers sell options, they hedge by trading the underlying. Near expiration, gamma spikes — delta changes rapidly with small price moves, so dealers must rebalance aggressively.

In positive gamma, this creates mean-reversion: dealers buy dips, sell rallies. The net effect pulls price toward the highest-OI strike cluster, which tends to be max pain.

Not a conspiracy. An emergent outcome of mechanical hedging.

Querying Max Pain via API

FlashAlpha computes max pain in real time for 6,000+ US equities and ETFs. One call gives you everything:

curl -H "X-Api-Key: YOUR_KEY" \
  "https://lab.flashalpha.com/v1/maxpain/SPY"
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "max_pain_strike": 545,
  "distance": { "percent": 0.61, "direction": "above" },
  "dealer_alignment": {
    "alignment": "converging",
    "gamma_flip": 546,
    "call_wall": 555,
    "put_wall": 538
  },
  "pin_probability": 68,
  "regime": "positive_gamma",
  "pain_curve": [ ... ],
  "max_pain_by_expiration": [
    { "expiration": "2026-04-11", "max_pain_strike": 547, "dte": 2, "total_oi": 520000 },
    { "expiration": "2026-04-17", "max_pain_strike": 545, "dte": 8, "total_oi": 1840000 }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Python Example

import requests

API_KEY = "YOUR_API_KEY"
BASE = "https://lab.flashalpha.com"

resp = requests.get(
    f"{BASE}/v1/maxpain/SPY",
    headers={"X-Api-Key": API_KEY}
)
data = resp.json()

print(f"Max Pain: ${data['max_pain_strike']}")
print(f"Distance: {data['distance']['percent']:.1f}% {data['distance']['direction']}")
print(f"Pin Probability: {data['pin_probability']}/100")
print(f"Alignment: {data['dealer_alignment']['alignment']}")
print(f"Regime: {data['regime']}")

# Single expiry
resp = requests.get(
    f"{BASE}/v1/maxpain/SPY?expiration=2026-04-17",
    headers={"X-Api-Key": API_KEY}
)
print(f"April 17 Max Pain: ${resp.json()['max_pain_strike']}")
Enter fullscreen mode Exit fullscreen mode

Install the SDK

pip install flashalpha
Enter fullscreen mode Exit fullscreen mode
from flashalpha import FlashAlpha

fa = FlashAlpha("YOUR_KEY")
mp = fa.maxpain("SPY")
print(f"Max Pain: {mp['max_pain_strike']}, Pin: {mp['pin_probability']}/100")
Enter fullscreen mode Exit fullscreen mode

Key Fields Explained

pin_probability (0–100): Combines OI concentration (30%), proximity to current price (25%), time to expiry (25%), and gamma magnitude (20%). Above 70 = strong pin conditions.

dealer_alignment: Shows whether max pain converges with GEX levels (gamma flip, call/put walls). "Converging" is the strongest signal — hedging flows and payout minimisation point the same direction.

pain_curve: The full payout curve across all strikes. A steep V = strong pin. Flat = weak pin. Asymmetric = directional skew in the pinning pressure.

max_pain_by_expiration: Per-expiry breakdown. The expiry with the most OI has the strongest gravitational pull. Useful for spotting step-downs when weeklies roll off.

Combining With Other Endpoints

Max pain is most useful layered with exposure data:

Endpoint What It Adds
/v1/exposure/gex Per-strike gamma — where hedging pressure concentrates
/v1/exposure/levels Gamma flip, call/put walls — confirms or contradicts the pin
/v1/exposure/zero-dte 0DTE pin risk and expected move on expiration day
/v1/exposure/summary Regime (positive/negative gamma), net dealer exposures

When Max Pain Doesn't Work

  • Negative gamma regime — dealers amplify moves instead of dampening them
  • Earnings / FOMC / CPI — directional flow overwhelms hedging
  • Low OI — small caps with thin chains won't pin
  • OI shifts — max pain from Monday can be stale by Thursday; always use fresh data

Free vs. Growth

The free tier (/v1/exposure/levels) includes the max pain strike — just the number. The Growth plan ($299/mo, 2,500 req/day) unlocks the full /v1/maxpain endpoint: pain curve, pin probability, dealer alignment, multi-expiry calendar, and expected move context.

The difference: knowing max pain is $545 vs. knowing it's $545 with a 72/100 pin probability, converging dealer alignment, and price within the expected move.


Links:

FlashAlpha | Options Analytics API - Greeks, Exposure & Vol Surfaces

Real-time options analytics API - Greeks, gamma exposure, SVI vol surfaces for 6,000+ underlyings. Free tier available.

favicon flashalpha.com

Top comments (0)