-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgex_trading_spy_tsla_qqq.py
More file actions
147 lines (113 loc) · 4.99 KB
/
gex_trading_spy_tsla_qqq.py
File metadata and controls
147 lines (113 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""
GEX trading guide for SPY, TSLA, QQQ — gamma exposure analysis in Python
This script is a comprehensive GEX trading reference for the three most
actively traded options markets: SPY (macro/index), QQQ (tech/growth), and
TSLA (high-vol single name). Each behaves differently in GEX terms:
- SPY: enormous open interest, tight dealer hedging, consistent GEX regime
- QQQ: correlated with SPY but amplified; gamma flip often diverges
- TSLA: wide spreads, high gamma from frequent 0DTE flow, fast regime shifts
For each symbol the script prints:
1. Current regime (positive vs negative gamma)
2. Key levels (gamma flip, call wall, put wall, max pain, 0DTE magnet)
3. AI-generated narrative outlook (if available on your plan)
Usage:
export FLASHALPHA_API_KEY=your_key_here
python code/gex_trading_spy_tsla_qqq.py
Install:
pip install flashalpha
"""
import os
from flashalpha import FlashAlpha, FlashAlphaError, TierRestrictedError
SYMBOLS = ["SPY", "QQQ", "TSLA"]
def print_separator(title: str) -> None:
line = "=" * 60
print(f"\n{line}")
print(f" {title}")
print(line)
def print_gex_summary(symbol: str, fa: FlashAlpha) -> None:
"""Fetch and print the GEX regime for a symbol."""
try:
data = fa.gex(symbol)
except FlashAlphaError as exc:
print(f" GEX error: {exc}")
return
net_gex = data.get("net_gex", 0)
regime = data.get("net_gex_label", "unknown")
gamma_flip = data.get("gamma_flip")
spot = data.get("underlying_price")
print(f"\n Net GEX : ${net_gex:>15,.0f}")
print(f" Regime : {regime}")
if spot:
print(f" Spot : ${spot:.2f}")
if gamma_flip is not None:
relation = "ABOVE" if (spot or 0) > gamma_flip else "BELOW"
print(f" Flip : {gamma_flip:.2f} (spot is {relation} the flip)")
def print_levels(symbol: str, fa: FlashAlpha) -> None:
"""Fetch and print key exposure levels for a symbol."""
try:
data = fa.exposure_levels(symbol)
levels = data.get("levels", {})
except FlashAlphaError as exc:
print(f" Levels error: {exc}")
return
gamma_flip = levels.get("gamma_flip")
call_wall = levels.get("call_wall")
put_wall = levels.get("put_wall")
max_pain = levels.get("max_pain")
dte_magnet = levels.get("zero_dte_magnet")
print(f"\n Gamma flip : {gamma_flip:.2f}" if gamma_flip else "\n Gamma flip : N/A")
print(f" Call wall : {call_wall:.2f}" if call_wall else " Call wall : N/A")
print(f" Put wall : {put_wall:.2f}" if put_wall else " Put wall : N/A")
print(f" Max pain : {max_pain:.2f}" if max_pain else " Max pain : N/A")
print(f" 0DTE magnet : {dte_magnet}" if dte_magnet else " 0DTE magnet : N/A")
if call_wall and put_wall:
width = call_wall - put_wall
print(f" GEX range : {put_wall:.0f} — {call_wall:.0f} (width: {width:.0f})")
def print_narrative(symbol: str, fa: FlashAlpha) -> None:
"""Fetch and print the AI narrative for a symbol (requires Growth+ plan)."""
try:
data = fa.narrative(symbol)
except TierRestrictedError:
print("\n Narrative: requires Growth+ plan (https://flashalpha.com)")
return
except FlashAlphaError as exc:
print(f"\n Narrative error: {exc}")
return
outlook = data.get("outlook") or data.get("summary")
regime = data.get("regime")
if regime:
print(f"\n Regime narrative : {regime}")
if outlook:
print(f" Outlook : {outlook}")
def main() -> None:
api_key = os.environ.get("FLASHALPHA_API_KEY", "YOUR_API_KEY")
fa = FlashAlpha(api_key)
print("GEX Trading Analysis: SPY, QQQ, TSLA")
print("Data from FlashAlpha — https://flashalpha.com")
for symbol in SYMBOLS:
print_separator(f"{symbol} — Gamma Exposure Analysis")
print("\n[1] GEX Regime")
print_gex_summary(symbol, fa)
print("\n[2] Key Levels")
print_levels(symbol, fa)
print("\n[3] Narrative Outlook")
print_narrative(symbol, fa)
print("\n" + "=" * 60)
print(" READING GUIDE")
print("=" * 60)
print()
print(" Positive gamma regime (net GEX > 0):")
print(" Dealers are net long gamma. Hedging flows are counter-cyclical.")
print(" Expect rangebound, low-vol trading. Sell premium, fade extremes.")
print()
print(" Negative gamma regime (net GEX < 0):")
print(" Dealers are net short gamma. Hedging flows are pro-cyclical.")
print(" Expect trending, high-vol behavior. Ride breakouts, buy premium.")
print()
print(" Call wall: overhead resistance — dealers sell into this level.")
print(" Put wall: downside support — dealers buy here, but breach = cascade.")
print(" Gamma flip: the most important level. Regime changes when price crosses it.")
print()
print("Learn more: https://flashalpha.com/articles/gex-trading-guide-gamma-exposure-api-spy-tsla")
if __name__ == "__main__":
main()