Download option chains (calls + puts) from Yahoo Finance via yfinance and write CSVs. Supports single or multiple symbols, single expiry or all expirations, optional expiration range, and optional implied-volatility plotting. Implied-Vol-Surface is my project to fit implied vol curves to option prices downloaded here.
- Python 3
pandasyfinancematplotlib(only for--plot-iv)
python xget_option_prices.py SYMBOL [YYYYMMDD] [outfile.csv] [--expiry YYYYMMDD|YYYYMMDD:YYYYMMDD] [--plot-iv] [--timing] [--exp-range N:M]
python xget_option_prices.py SYMBOL1 SYMBOL2 ... [YYYYMMDD] [--expiry YYYYMMDD|YYYYMMDD:YYYYMMDD] [--plot-iv] [--timing] [--exp-range N:M]
SYMBOL: one or more tickers. If the symbol starts with^, it will be stripped in output filenames and summary labels.YYYYMMDD(optional): specific expiration date to fetch. If omitted and--expiryis not given, all expirations are fetched.outfile.csv(optional): output filename for a single symbol. Ignored for multi-symbol runs. If no expiry is supplied, a trailing.csvargument is treated as the output file for a single symbol.
- If a symbol starts with
^, wrap it in quotes (e.g.,"^SPX") so the shell passes it through. --expiry YYYYMMDD|YYYYMMDD:YYYYMMDD: select a single expiration or a date range.--exp-range N:M: filter expirations by days from today (inclusive). Empty side means open-ended (e.g.,:30or7:). IfYYYYMMDD,--expiry, and/or--exp-rangeare provided, expirations are the union.--plot-iv: plot implied volatility vs. strike for the fetched chain. Beware that the implied vols are those reported by Yahoo Finance, and I think they are often wrong.--timing: print timing summary at the end.
-
Writes a CSV per symbol (or to your custom
outfile.csv). -
The default output filename is:
SYMBOL_YYYY-MM-DD.csvwhen a single expiry is requested, orSYMBOL_all.csvwhen all expiries are fetched.
-
A per-expiration summary is printed to stdout when volume/open interest fields are present.
Fetch all expirations for one symbol:
python xget_option_prices.py "^SPX"
Fetch all expirations and write to a custom file:
python xget_option_prices.py "^SPX" spx.csv
Fetch one expiration and write to a custom file:
python xget_option_prices.py "^SPX" 20260220 spx_20260220.csv
Fetch a date range using --expiry:
python xget_option_prices.py "^SPX" --expiry 20260201:20260320
Fetch multiple symbols (all expirations):
python xget_option_prices.py SPY QQQ IWM
Fetch expirations 0–30 days out and plot IV:
python xget_option_prices.py "^SPX" --exp-range 0:30 --plot-iv
- Data source is Yahoo Finance via
yfinance. - If
--plot-ivis used, the script pulls a spot price to focus the plot around the current level. - The output CSV includes both calls and puts with an
option_typecolumn.