Yahoo¶
Fetch equity option chains from Yahoo Finance.
The client is intentionally minimal: it fetches a full option chain via the
public v7/finance/options endpoint and exposes a helper to build a
VolSurfaceLoader from it.
You can import the module via
Authentication¶
Yahoo Finance requires a session cookie and a crumb token for the options
endpoint. The client fetches both on the first request and caches the crumb
for the lifetime of the instance.
quantflow.data.yahoo.Yahoo
dataclass
¶
Yahoo(url='https://query2.finance.yahoo.com/v7/finance', content_type='text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', default_headers=(lambda: {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36'})(), _crumb=None)
Bases: HttpxClient
Yahoo Finance API client
Minimal client for fetching option chains used to build volatility surfaces.
Example¶
from quantflow.data.yahoo import Yahoo
async with Yahoo() as yahoo:
loader = await yahoo.volatility_surface_loader("AAPL")
surface = loader.surface()
content_type
class-attribute
instance-attribute
¶
content_type = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'
default_headers
class-attribute
instance-attribute
¶
default_headers = field(default_factory=lambda: {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36'})
option_chain
async
¶
Return the full option chain for symbol
| PARAMETER | DESCRIPTION |
|---|---|
symbol
|
Underlying ticker symbol
TYPE:
|
Source code in quantflow/data/yahoo.py
volatility_surface_loader
async
¶
Build a VolSurfaceLoader
by fetching the option chain for symbol and passing it to
loader_from_chain.
| PARAMETER | DESCRIPTION |
|---|---|
symbol
|
Underlying ticker symbol
TYPE:
|
exclude_volume
|
Drop contracts with volume at or below this threshold
TYPE:
|
exclude_open_interest
|
Drop contracts with open interest at or below this threshold
TYPE:
|
Source code in quantflow/data/yahoo.py
loader_from_chain
classmethod
¶
Build a VolSurfaceLoader from a Yahoo option chain dictionary.
US equity options are non-inverse: prices are in the quote currency and the spot is taken from the underlying quote. Forwards are not provided by Yahoo, so they are recovered from put-call parity by the loader.
| PARAMETER | DESCRIPTION |
|---|---|
chain
|
Yahoo option chain payload
TYPE:
|
exclude_volume
|
Drop contracts with volume at or below this threshold
TYPE:
|
exclude_open_interest
|
Drop contracts with open interest at or below this threshold
TYPE:
|
Source code in quantflow/data/yahoo.py
save_fixture
async
¶
Fetch the option chain for symbol and save it as a JSON fixture.
Only the fields read by volatility_surface_loader are kept, so the fixture stays small enough to commit.
If path ends with .gz, the output is gzipped.
| PARAMETER | DESCRIPTION |
|---|---|
symbol
|
Underlying ticker symbol
TYPE:
|
path
|
File path where to save the fixture
TYPE:
|