|
| 1 | +# # Live Options Screener — filter & rank symbols in real time |
| 2 | +# |
| 3 | +# The Screener endpoint lets you filter and rank symbols across your tier's |
| 4 | +# universe by any combination of stock, expiry, strike, or contract-level |
| 5 | +# metrics: gamma exposure (GEX), VRP, implied volatility, greeks, harvest |
| 6 | +# scores, dealer flow risk, and more. Data is live from an in-memory store, |
| 7 | +# refreshed every 5-10 seconds. |
| 8 | +# |
| 9 | +# Docs: https://flashalpha.com/docs/lab-api-screener |
| 10 | +# Cookbook: https://flashalpha.com/docs/lab-api-screener-cookbook |
| 11 | +# Install: pip install "flashalpha>=0.3.0" |
| 12 | +# |
| 13 | +# Tier notes: |
| 14 | +# Growth — 10 symbols (SPY, QQQ, AAPL, TSLA, NVDA, AMZN, META, MSFT, SPX, AMD), 10 rows max |
| 15 | +# Alpha — ~250 symbols, 50 rows max, formulas, harvest/dealer-flow-risk scores |
| 16 | + |
| 17 | +import os |
| 18 | +from flashalpha import FlashAlpha |
| 19 | + |
| 20 | +fa = FlashAlpha(os.environ["FLASHALPHA_API_KEY"]) |
| 21 | + |
| 22 | +# --------------------------------------------------------------------------- |
| 23 | +# 1) Simplest call — no filters, returns the default universe |
| 24 | +# --------------------------------------------------------------------------- |
| 25 | +result = fa.screener() |
| 26 | +print(f"tier={result['meta']['tier']} universe={result['meta']['universe_size']}") |
| 27 | +for row in result["data"][:5]: |
| 28 | + print(f" {row['symbol']:6} price={row.get('price')} regime={row.get('regime')}") |
| 29 | + |
| 30 | +# --------------------------------------------------------------------------- |
| 31 | +# 2) Positive-gamma names ranked by net GEX |
| 32 | +# --------------------------------------------------------------------------- |
| 33 | +result = fa.screener( |
| 34 | + filters={"field": "regime", "operator": "eq", "value": "positive_gamma"}, |
| 35 | + sort=[{"field": "net_gex", "direction": "desc"}], |
| 36 | + select=["symbol", "price", "regime", "net_gex", "gamma_flip"], |
| 37 | +) |
| 38 | +print("\nPositive-gamma names:") |
| 39 | +for row in result["data"]: |
| 40 | + print(f" {row['symbol']:6} net_gex={row['net_gex']:>15,.0f} flip={row.get('gamma_flip')}") |
| 41 | + |
| 42 | +# --------------------------------------------------------------------------- |
| 43 | +# 3) Harvestable VRP setups (Alpha tier) |
| 44 | +# --------------------------------------------------------------------------- |
| 45 | +result = fa.screener( |
| 46 | + filters={ |
| 47 | + "op": "and", |
| 48 | + "conditions": [ |
| 49 | + {"field": "regime", "operator": "eq", "value": "positive_gamma"}, |
| 50 | + {"field": "vrp_regime", "operator": "eq", "value": "harvestable"}, |
| 51 | + {"field": "dealer_flow_risk", "operator": "lte", "value": 40}, |
| 52 | + {"field": "harvest_score", "operator": "gte", "value": 65}, |
| 53 | + ], |
| 54 | + }, |
| 55 | + sort=[{"field": "harvest_score", "direction": "desc"}], |
| 56 | + select=["symbol", "price", "harvest_score", "dealer_flow_risk", "vrp_regime"], |
| 57 | +) |
| 58 | +print("\nHarvestable VRP setups:") |
| 59 | +for row in result["data"]: |
| 60 | + print( |
| 61 | + f" {row['symbol']:6} harvest={row['harvest_score']:>3} " |
| 62 | + f"risk={row['dealer_flow_risk']:>3} vrp={row.get('vrp_regime')}" |
| 63 | + ) |
| 64 | + |
| 65 | +# --------------------------------------------------------------------------- |
| 66 | +# 4) Vol scanner — where is IV rich vs realized? |
| 67 | +# --------------------------------------------------------------------------- |
| 68 | +result = fa.screener( |
| 69 | + filters={ |
| 70 | + "op": "and", |
| 71 | + "conditions": [ |
| 72 | + {"field": "vrp_20d", "operator": "gte", "value": 5}, |
| 73 | + {"field": "atm_iv", "operator": "gte", "value": 25}, |
| 74 | + ], |
| 75 | + }, |
| 76 | + sort=[{"field": "vrp_20d", "direction": "desc"}], |
| 77 | + select=["symbol", "atm_iv", "rv_20d", "vrp_20d", "skew_25d"], |
| 78 | +) |
| 79 | +print("\nHigh VRP names (IV rich vs RV):") |
| 80 | +for row in result["data"]: |
| 81 | + print( |
| 82 | + f" {row['symbol']:6} iv={row['atm_iv']:>5} " |
| 83 | + f"rv={row['rv_20d']:>5} vrp={row['vrp_20d']:>5}" |
| 84 | + ) |
| 85 | + |
| 86 | +# --------------------------------------------------------------------------- |
| 87 | +# 5) Cascading filter — stock + expiry + strike + contract level |
| 88 | +# --------------------------------------------------------------------------- |
| 89 | +# Returns symbols with positive gamma, trimmed to expiries <= 14 days, |
| 90 | +# high-OI strikes, and only the high-delta calls. |
| 91 | +result = fa.screener( |
| 92 | + filters={ |
| 93 | + "op": "and", |
| 94 | + "conditions": [ |
| 95 | + {"field": "regime", "operator": "eq", "value": "positive_gamma"}, |
| 96 | + {"field": "expiries.days_to_expiry", "operator": "lte", "value": 14}, |
| 97 | + {"field": "strikes.call_oi", "operator": "gte", "value": 2000}, |
| 98 | + {"field": "contracts.type", "operator": "eq", "value": "C"}, |
| 99 | + {"field": "contracts.delta", "operator": "gte", "value": 0.3}, |
| 100 | + ], |
| 101 | + }, |
| 102 | + select=["symbol", "expiry_aggregates"], |
| 103 | + limit=10, |
| 104 | +) |
| 105 | +print("\nCascading filter (positive gamma, <=14 DTE, high-OI calls, delta>=0.3):") |
| 106 | +for row in result["data"]: |
| 107 | + print(f" {row['symbol']}: {len(row.get('expiry_aggregates', []))} expiries kept") |
| 108 | + |
| 109 | +# --------------------------------------------------------------------------- |
| 110 | +# 6) Custom formula — IV premium sorted descending (Alpha tier) |
| 111 | +# --------------------------------------------------------------------------- |
| 112 | +result = fa.screener( |
| 113 | + formulas=[{"alias": "iv_premium", "expression": "atm_iv - rv_20d"}], |
| 114 | + filters={"formula": "iv_premium", "operator": "gte", "value": 5}, |
| 115 | + sort=[{"formula": "iv_premium", "direction": "desc"}], |
| 116 | + select=["symbol", "atm_iv", "rv_20d", "iv_premium"], |
| 117 | + limit=20, |
| 118 | +) |
| 119 | +print("\nCustom formula (iv_premium = atm_iv - rv_20d):") |
| 120 | +for row in result["data"]: |
| 121 | + print( |
| 122 | + f" {row['symbol']:6} iv={row['atm_iv']:>5} " |
| 123 | + f"rv={row['rv_20d']:>5} premium={row['iv_premium']:>5}" |
| 124 | + ) |
| 125 | + |
| 126 | +# --------------------------------------------------------------------------- |
| 127 | +# 7) Risk-adjusted harvest score (formula ranking) |
| 128 | +# --------------------------------------------------------------------------- |
| 129 | +result = fa.screener( |
| 130 | + formulas=[ |
| 131 | + {"alias": "risk_adj", "expression": "harvest_score / (dealer_flow_risk + 1)"}, |
| 132 | + ], |
| 133 | + filters={"field": "harvest_score", "operator": "gte", "value": 50}, |
| 134 | + sort=[{"formula": "risk_adj", "direction": "desc"}], |
| 135 | + select=["symbol", "harvest_score", "dealer_flow_risk", "risk_adj"], |
| 136 | + limit=20, |
| 137 | +) |
| 138 | +print("\nRisk-adjusted harvest score (score / (risk + 1)):") |
| 139 | +for row in result["data"]: |
| 140 | + print( |
| 141 | + f" {row['symbol']:6} score={row['harvest_score']:>3} " |
| 142 | + f"risk={row['dealer_flow_risk']:>3} risk_adj={row['risk_adj']:.3f}" |
| 143 | + ) |
| 144 | + |
| 145 | +# --------------------------------------------------------------------------- |
| 146 | +# 8) Macro context filter — only show when VIX is elevated |
| 147 | +# --------------------------------------------------------------------------- |
| 148 | +result = fa.screener( |
| 149 | + filters={ |
| 150 | + "op": "and", |
| 151 | + "conditions": [ |
| 152 | + {"field": "regime", "operator": "eq", "value": "negative_gamma"}, |
| 153 | + {"field": "vix", "operator": "gte", "value": 20}, |
| 154 | + ], |
| 155 | + }, |
| 156 | + select=["symbol", "regime", "atm_iv", "vix"], |
| 157 | +) |
| 158 | +print(f"\nNegative gamma names (VIX >= 20): {result['meta']['total_count']} found") |
0 commit comments