File size: 4,320 Bytes
2b761ca
 
9f681b6
 
 
 
2b761ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Options Scanner — automated multi-strategy trade builder

Also packaged as an **MCP server** (7 tools: scan, build, position/roll checks)
for Claude Desktop, Claude Code and Hermes — see [MCP_SERVER.md](MCP_SERVER.md)
for setup and an honest evaluation of the engine.

[![Built with ML Intern](https://huggingface.co/datasets/huggingface/badges/resolve/main/built-with-ml-intern-sm.svg)](https://hf.co/chat?mode=ml-intern)

Automated options scanner: pulls option chains + stock quotes from free
online sources (Nasdaq/NYSE listed underlyings via Yahoo Finance), builds
multi-leg strategies with a defined-risk-first design, gates every candidate
through a risk engine, and outputs ranked trades as JSON/CSV for the browser
dashboard.

## Data sources

| Provider | Latency | Setup | Adapter |
|---|---|---|---|
| Alpaca (IEX) | real-time | `ALPACA_KEY_ID` + `ALPACA_SECRET_KEY` env vars (free) | `AlpacaProvider` |
| Tradier | real-time | `TRADIER_API_KEY` env var (free with brokerage account) | `TradierProvider` |
| Polygon.io | real-time | `POLYGON_API_KEY` env var (options plan) | `PolygonProvider` |
| Yahoo Finance | ~15 min delayed | none (`pip install yfinance`) | `YFinanceProvider` (default) |

The scanner auto-selects the best provider present: **Tradier > Alpaca >
Polygon > yfinance**, or force one with `--provider`. All providers share one
normalized `Chain` model, so switching feeds changes nothing else.

Alpaca's free IEX feed has no open interest and thin one-sided quotes on some
contracts; the engine treats one-sided quotes as wide markets (penalized in
scoring, never silent) and drops quotes with impossible implied vols.

> Honest note: "real-time" free options data does not exist anywhere. Free
> feeds are delayed ~15 min. Plug in a Tradier key (free tier with a broker
> account) for real-time chains.

## Strategies built

Defined-risk by default — every short leg is paired inside a spread:

- Verticals: bull/bear credit spreads and bull/bear debit spreads
- Calendars (call & put, same strike)
- Diagonals (long theta, offset strikes across expirations)
- Long butterflies and Iron butterflies
- Iron condors
- Call ratio backspreads (1x2)
- Jade lizards (credit > call-spread width where available)
- Double diagonals (the defined-risk "short strangle")
- Short straddles/strangles: rejected by default (undefined risk); pass
  `--allow-undefined-risk` to admit them with a loud warning — the defined-risk
  equivalents (iron fly / double diagonal) are built instead

## Risk engine

- Payoff-grid max profit / max loss / breakevens at the shortest leg's expiry;
  back-month legs valued with Black-Scholes at that date (honest calendar and
  diagonal risk). Max loss is floored at the debit actually paid.
- Gates: per-leg open interest, bid-ask spread vs mid, positive bids, defined
  risk, buying-power effect ≤ max % of account, earnings dates inside the
  trade window.
- POP from lognormal distance of short strikes; composite score = expectancy
  (45%) + POP (25%) + credit efficiency (20%) + liquidity (10%).

## Rolling mechanics

`rolling.RollManager.check(position, chain, rules)` marks open positions and
returns concrete actions: close at profit target (default 50% of credit),
stop at 2x credit, and rolls — out, out-and-down (tested put), out-and-up
(tested call) — when DTE hits the management window or a short strike's delta
breaches the tested threshold.

## Quick start

```bash
pip install yfinance

# auto universe (40 large caps + high-IV names + ETFs), free delayed data
python -m options_scanner.scan --output results.json --csv results.csv

# your watchlist, real-time via Alpaca
export ALPACA_KEY_ID=... ALPACA_SECRET_KEY=...
python -m options_scanner.scan --symbols SPY,QQQ,NVDA --provider alpaca
```

Tune per-trade risk with `--account-size` and `--risk-pct`.

## Output

`results.json` carries `top_candidates` (ranked by composite score, best 3 per
symbol) with full leg lists, breakevens, BPE in dollars, POP, and the reasons
each trade passed/failed gates; `errors` lists tickers that failed to load.
The JSON is what the browser dashboard reads.

## Disclaimer

Educational tooling, not financial advice. Option pricing uses delayed data
unless a real-time key is configured; verify every structure in your broker
before trading.