{"id":50980616,"url":"https://github.com/FlashAlpha-lab/gex-explained","last_synced_at":"2026-07-07T11:00:33.338Z","repository":{"id":344415192,"uuid":"1181429414","full_name":"FlashAlpha-lab/gex-explained","owner":"FlashAlpha-lab","description":"What is Gamma Exposure (GEX) and how to compute it — theory, math, and Python code for dealer hedging, gamma regimes, and options exposure analysis","archived":false,"fork":false,"pushed_at":"2026-03-26T19:58:15.000Z","size":110,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-02T20:25:25.045Z","etag":null,"topics":["call-wall","charm","dealer-hedging","delta-exposure","gamma-exposure","gamma-flip","gex","options","options-analytics","put-wall","python","trading","vanna"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlashAlpha-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-14T05:55:48.000Z","updated_at":"2026-05-28T05:35:30.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/FlashAlpha-lab/gex-explained","commit_stats":null,"previous_names":["flashalpha-lab/gex-explained"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FlashAlpha-lab/gex-explained","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlashAlpha-lab%2Fgex-explained","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlashAlpha-lab%2Fgex-explained/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlashAlpha-lab%2Fgex-explained/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlashAlpha-lab%2Fgex-explained/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlashAlpha-lab","download_url":"https://codeload.github.com/FlashAlpha-lab/gex-explained/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlashAlpha-lab%2Fgex-explained/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35225029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-07T02:00:07.222Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["call-wall","charm","dealer-hedging","delta-exposure","gamma-exposure","gamma-flip","gex","options","options-analytics","put-wall","python","trading","vanna"],"created_at":"2026-06-19T14:00:21.570Z","updated_at":"2026-07-07T11:00:33.298Z","avatar_url":"https://github.com/FlashAlpha-lab.png","language":"Python","funding_links":[],"categories":["Gamma Exposure (GEX)"],"sub_categories":["References and Methodology"],"readme":"# What is Gamma Exposure (GEX) and Why It Moves Markets\n\n[![CI](https://github.com/FlashAlpha-lab/gex-explained/actions/workflows/ci.yml/badge.svg)](https://github.com/FlashAlpha-lab/gex-explained/actions/workflows/ci.yml)\n\nThis repository explains Gamma Exposure (GEX) from first principles — the math behind it, how it shapes market microstructure, and how to compute it yourself from a raw options chain. All code is runnable with publicly available data.\n\n---\n\n## Prerequisites\n\nYou should know what options are, what the Greeks mean, and roughly how market makers work. You do not need to be a quant.\n\n---\n\n## What is GEX?\n\nGamma Exposure is a measure of how much directional hedging pressure options dealers face as the underlying price moves.\n\nEvery time a retail trader or institution buys an option, a market maker (dealer) sells it and immediately hedges the resulting delta. That delta hedge is not static — it changes continuously as spot moves. The rate of change of delta with respect to spot is **gamma**. Dealers who are net short options are short gamma; their delta hedges move against price, forcing them to buy into rallies and sell into declines — or more precisely, to buy more as price falls and sell more as price rises. This is the source of GEX's market impact.\n\n**GEX aggregates gamma across all strikes and expirations**, scaled to the notional dollar value each contract controls, giving you a single number (or a profile by strike) that represents how much dollar-hedging activity a one-percent move in the underlying would trigger.\n\n---\n\n## The Formula\n\nThe standard SpotGamma convention for dollar GEX per strike is:\n\n```\nGEX = gamma * OI * 100 * spot^2 * 0.01\n```\n\nWhere:\n- `gamma` — the Black-Scholes gamma of the contract (per share, per dollar of underlying)\n- `OI` — open interest in contracts\n- `100` — shares per contract\n- `spot^2` — converts from per-share gamma to dollar-delta sensitivity\n- `0.01` — represents a 1% move in spot (scaling convention)\n\nFor **calls**, GEX is positive (dealers are long calls when customers buy them, so dealers are long gamma and act as stabilizers).\n\nFor **puts**, GEX is negated: dealers who sold puts to customers are short those puts, meaning they are short gamma on the put side.\n\n```\ncall_gex = gamma * OI * 100 * spot^2 * 0.01\nput_gex  = -1 * gamma * OI * 100 * spot^2 * 0.01\n```\n\nNet GEX at a given strike is the sum of call and put GEX at that strike. Total market GEX is the sum across all strikes and expirations.\n\nSee [theory/gamma-exposure.md](theory/gamma-exposure.md) for the full derivation.\n\n---\n\n## Why GEX Matters: Dealer Hedging Regimes\n\nWhen aggregate GEX is **positive**, dealers in aggregate are long gamma. As spot rises, their delta increases, so they sell to rehedge. As spot falls, their delta decreases, so they buy. This is counter-cyclical — it dampens volatility and creates mean-reversion behavior around high-GEX strikes.\n\nWhen aggregate GEX is **negative**, dealers are short gamma. As spot rises, their short-gamma position means their delta is getting shorter, so they buy to rehedge. As spot falls, they must sell. This is pro-cyclical — it amplifies moves and creates momentum-like behavior.\n\nThe practical implication: positive-GEX regimes tend to see range-bound, low-volatility trading. Negative-GEX regimes tend to see sharp, trending moves with elevated realized volatility.\n\nSee [theory/dealer-hedging.md](theory/dealer-hedging.md) and [theory/gex-regimes.md](theory/gex-regimes.md) for detail.\n\n---\n\n## The Gamma Flip\n\nThe **gamma flip** is the spot price at which aggregate dealer GEX crosses from positive to negative (or vice versa). It is arguably the most actionable level produced by GEX analysis.\n\n- Above the gamma flip: positive gamma, dealers stabilize price\n- Below the gamma flip: negative gamma, dealers amplify price moves\n\nTraders watch the gamma flip as a regime boundary. Sustained price action above it suggests a low-vol, mean-reverting environment. A break below it (especially with conviction) can trigger a volatility expansion as dealer hedging becomes pro-cyclical.\n\n---\n\n## Key Levels\n\nBeyond the gamma flip, GEX analysis identifies:\n\n- **Call Wall** — the strike with the highest positive GEX from calls. Dealers have maximum long-gamma exposure here; it often acts as a ceiling because dealer selling pressure intensifies as spot approaches it.\n- **Put Wall** — the strike with the highest negative GEX from puts. Dealers have maximum short-gamma exposure here; it often acts as a floor (or a trap door if breached).\n\n---\n\n## Code in This Repo\n\n### Core: from-scratch GEX computation\n\n| File | What it does |\n|------|-------------|\n| [code/compute_gex.py](code/compute_gex.py) | Computes GEX from a raw CSV options chain |\n| [code/plot_gex.py](code/plot_gex.py) | Bar chart of GEX by strike with key levels marked |\n| [code/compare_with_api.py](code/compare_with_api.py) | Compares manual calculation against the FlashAlpha API |\n| [data/sample_chain.csv](data/sample_chain.csv) | Sample SPY options chain (~25 rows, realistic prices) |\n\n### API examples: live GEX data via FlashAlpha\n\n| File | What it does |\n|------|-------------|\n| [code/gamma_exposure_by_strike.py](code/gamma_exposure_by_strike.py) | Full GEX profile by strike — call GEX, put GEX, net GEX, OI, volume |\n| [code/dealer_hedging_flow_analysis.py](code/dealer_hedging_flow_analysis.py) | Dealer hedging estimates at ±1% moves — shares, direction, notional |\n| [code/gamma_flip_level_tracker.py](code/gamma_flip_level_tracker.py) | Track gamma flip, call wall, put wall, max pain, 0DTE magnet |\n| [code/call_wall_put_wall_finder.py](code/call_wall_put_wall_finder.py) | Scan multiple symbols (SPY, QQQ, AAPL, TSLA, NVDA) for wall levels |\n| [code/gex_trading_spy_tsla_qqq.py](code/gex_trading_spy_tsla_qqq.py) | Comprehensive GEX trading analysis for SPY, TSLA, and QQQ |\n| [code/exposure_narrative_analysis.py](code/exposure_narrative_analysis.py) | AI-powered narrative: regime, flow, vanna, charm, 0DTE, outlook |\n| [code/delta_vanna_charm_exposure.py](code/delta_vanna_charm_exposure.py) | DEX, VEX, CHEX — delta, vanna, and charm exposure beyond gamma |\n\n### Tests\n\n| File | What it does |\n|------|-------------|\n| [tests/test_compute_gex.py](tests/test_compute_gex.py) | Unit tests for the from-scratch GEX computation logic |\n| [tests/test_unit.py](tests/test_unit.py) | Unit tests for FlashAlpha API response parsing (mocked, no key required) |\n| [tests/test_integration.py](tests/test_integration.py) | Integration tests against the live FlashAlpha API |\n\nRun the compute script:\n\n```bash\npip install numpy scipy matplotlib requests\npython code/compute_gex.py\n```\n\nRun unit tests (no API key required):\n\n```bash\npip install flashalpha pytest\npytest tests/test_compute_gex.py tests/test_unit.py -v\n```\n\nRun all tests including live API tests:\n\n```bash\nexport FLASHALPHA_API_KEY=your_key_here\npytest tests/ -v -m integration\n```\n\n---\n\n## GEX Trading Guide\n\nFor a complete walkthrough of how to use GEX data to trade SPY, TSLA, and QQQ — including regime identification, level tracking, and dealer hedging flow analysis — see:\n\n[GEX Trading Guide: Gamma Exposure API for SPY, TSLA, QQQ](https://flashalpha.com/articles/gex-trading-guide-gamma-exposure-api-spy-tsla)\n\n---\n\n## Skip the Math\n\nIf you want production GEX data without implementing any of this yourself:\n\n```bash\npip install flashalpha\n```\n\n```python\nimport flashalpha as fa\n\ngex    = fa.gex(\"SPY\")           # full GEX profile by strike\nlevels = fa.gex_levels(\"SPY\")    # gamma_flip, call_wall, put_wall\n\nprint(levels)\n```\n\nThe API is at `https://lab.flashalpha.com`. Auth via `X-Api-Key` header. See [code/compare_with_api.py](code/compare_with_api.py) for a raw-requests example.\n\n---\n\n## Related Repositories\n\n- [FlashAlpha Python SDK](https://github.com/FlashAlpha-lab/flashalpha-python) — `pip install flashalpha`\n- [0DTE Options Analytics](https://github.com/FlashAlpha-lab/0dte-options-analytics) — 0DTE pin risk, expected move, dealer hedging\n- [Volatility Surface Python](https://github.com/FlashAlpha-lab/volatility-surface-python) — SVI, variance swap, skew analysis\n- [Examples](https://github.com/FlashAlpha-lab/flashalpha-examples) — more tutorials\n- [Awesome Options Analytics](https://github.com/FlashAlpha-lab/awesome-options-analytics) — curated resource list\n\n## Beyond the basics\n\nThis repo computes the math from scratch and against the live API. Production\nworkloads (full-universe coverage, point-in-time history, aggregate vanna/charm)\nrun on the **Alpha tier**: [flashalpha.com/for-quant-teams](https://flashalpha.com/for-quant-teams?utm_source=github\u0026utm_medium=readme\u0026utm_campaign=repo-gex-explained)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlashAlpha-lab%2Fgex-explained","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFlashAlpha-lab%2Fgex-explained","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlashAlpha-lab%2Fgex-explained/lists"}