quantdata.widb.day#
Generating one day of WRDS Option Metrics data for one ticker#
Key functions:
collect_raw_day()- Collect raw option data with minimal analytics for a ticker and dateenrich_day()- Enrich raw data with implied volatilities, greeks, and synthetic call options
Summary#
This module provides tools to process daily option data from WRDS Option Metrics (IvyDB):
collect_raw_day: Downloads spot, forward, discount factor, and option data. Cleans bad options and computes business days to expiry and implied discount factors. Returns a raw DataFrame.
enrich_day: Builds on raw data by computing implied forwards from put-call parity, synthetic minimal-spread call options, implied volatilities, and option greeks (delta, gamma, vega, theta).
Both functions use filtering configurations to control data quality and processing parameters.
Usage Example#
>>> from quantdata.widb.day import collect_raw_day, enrich_day, RawDayFilter, ExpiryFilter
>>> from quantdata.biz_calendar import to_date
>>> from cdxcore.verbose import Context
>>> import datetime as dt
>>>
>>> # Define date and filters
>>> d = to_date("2022-01-03")
>>> ticker = "SPX"
>>> raw_filter = RawDayFilter(min_bid=0.015)
>>> enriched_filter = ExpiryFilter(num_min_both_traded=5)
>>>
>>> # Collect and enrich data
>>> raw_data = collect_raw_day(ticker, d, raw_filter, verbose=Context())
>>> enriched_data = enrich_day(ticker, d, raw_data, raw_day_filter=raw_filter,
... expiry_filter=enriched_filter, verbose=Context())
>>>
>>> # Access results
>>> print(enriched_data[['strike', 'fwd', 'ask_vol', 'bid_vol', 'pure_ask_delta']].head())
This file’s main can also be used to generate data manually:
python -m day SPX RUT NDX –period 2020-05-01 2022-01-31
- class quantdata.widb.day.RawDayFilter(min_bid=0.011, drop_irregular_expiries=True)[source]#
Bases:
object
- quantdata.widb.day.collect_raw_day(ticker, d, raw_day_filter, *, raise_if_bad_day=True, verbose=<cdxcore.verbose.Context object>, secid=None)[source]#
Collect raw data with minimal analytics for a given ticker and date.
The function returns a panda data frame with columns
SCHEMA_RAW_DAY.The function:
Downloads spot, forward, discount and option data.
Removes and bad days/tickers/options using
quantdata.widb.bad.BAD.Removes options with same-day expiry, NA or zero bid prices, and bad settlement (ss_flag != ‘0’). By default the function also removed irregular expiries, which are holidays that were announced shortly before the expiry date, leading to data issues.
Computes the implied discount factor from the zero curve and the refernece forward price from the forward table (which is off as the forward table is 15min delayed).
Computes business days to expiry and a unique expiry ID (which includes AM/PM).
Typically the result of this function is processed with
enrich_day().- Parameters:
ticker (
str) – Ticker symbol, e.g. “SPX”d (
date) – Date for which to collect dataconfig (
RawDayFilter) – Configuration for data collectionraise_if_bad_day (
bool) – IfTrue, raises an error if the date is in the BAD data sets. IfFalse, returns an empty data set instead. (In no other condition will an empty data set returned)verbose (
Context) – Verbose context for logging
- Returns:
Daily data – Cleaned DataFrame with all relevant data for the given ticker and date, with the schema
SCHEMA_RAW_DAY. This data set is not empty unlessraise_if_bad_dayis True and the date/ticker is in the BAD data sets.- Return type:
- Raises:
Not found –
LookupError: If no data was downloaded from IvyDB for the given ticker and date.No data –
EOFError: If no data was available for the given ticker and date.Bad day –
IndexError: If this date and ticker are known to have bad data; seequantdata.widb.bad.BADfor details.Bad data –
RuntimeError: If data was downloaded but found to be bad after basic cleaning steps. This can happen for example if the forward price is highly suspicious, or if all options had zero or NA bid prices. Please check the date range and calendar settings, and consider adding the date/ticker to the BAD data sets if the issue is confirmed.
- class quantdata.widb.day.ExpiryFilter(num_min_either_traded=10, num_min_both_traded=4, min_pure_spread=1e-06, min_implied_vol=0.01, max_implied_vol=5.0, normalize=False)[source]#
Bases:
objectHow to filter expiries to be able to compute implied forwards
- quantdata.widb.day.enrich_day(ticker, d, raw_data=None, *, raw_day_filter=RawDayFilter(min_bid=0.011, drop_irregular_expiries=True), expiry_filter=ExpiryFilter(num_min_either_traded=10, num_min_both_traded=4, min_pure_spread=1e-06, min_implied_vol=0.01, max_implied_vol=5.0, normalize=False), override_cache_mode=None, raise_if_bad_day=True, verbose=<cdxcore.verbose.Context object>)[source]#
Enrich a day’s data.
Compute synthetic minimal spread call options.
Compute an implied forward from inverse-spread weighted bid/ask call prices.
Compute implied volatilities and (pure) greeks.
The returned daya data frame has the schema
SCHEMA_ENRICHED_DAY, which includes all columns fromSCHEMA_RAW_DAY.- Parameters:
ticker (
str) – Ticker symbol, e.g. “SPX”d (
date) – Date for which to collect datadata (
pandas.DataFrame| None, defaultNone) – Raw data for the given ticker and date. IfNone, data will be generated usingcollect_raw_day().raw_day_filter (
RawDayFilter) – Configuration for data collectionexpiry_filter (
ExpiryFilter) – Filter for expiries to be able to compute implied forwardsoverride_cache_mode (
CacheMode|None) – If notNone, overrides the cache mode for the raw day data. Set to"update"to refresh the underlying raw cache.raise_if_bad_day (
bool) – IfTrue, raises an error if the date is in the BAD data sets. IfFalse, returns an empty data set instead. (In no other condition will an empty data set be returned)verbose (
Context) – Verbose context for logging
- Returns:
Daily data – Cleaned DataFrame with all relevant data for the given ticker and date, creating the schema
SCHEMA_ENRICHED_DAY.- Return type:
- Raises:
Not found –
LookupError: If no data was downloaded from IvyDB for the given ticker and date.No data –
EOFError: If no data was available for the given ticker and date.Bad day –
IndexError: If this date and ticker are known to have bad data; seequantdata.widb.bad.BADfor details.Bad data –
RuntimeError: If data was downloaded but found to be bad after basic cleaning steps. This can happen for example if the forward price is highly suspicious, or if all options had zero or NA bid prices. Please check the date range and calendar settings, and consider adding the date/ticker to the BAD data sets if the issue is confirmed.