quantdata.widb.arbfree#
Arbitrage-Free Market Data Filter#
The function mk_arb_free_day() in this module takes
attempts to fit an arbitrage-free fit through the bid/ask prices of the options in a given day.
It removes strikes and even expiries whenever necessary to achieve this goal.
Massaging data this way is a pre-requisite for any attempts to fit a strictly arbitrage-free model to WIDB data.
Example
>>> import datetime as dt
>>> from quantdata.widb.arbfree import mk_arb_free_day
>>> from quantdata.sanos.arbfree import MkArbFree
>>>
>>> # Generate arbitrage-free prices for SPX on a specific date
>>> df = mk_arb_free_day("SPX", dt.date(2023, 1, 15))
>>>
>>> # With custom arbitrage-free fitting configuration
>>> mk_arb_free_config = MkArbFree(no_arb_mode="surface")
>>> df = mk_arb_free_day("SPX", dt.date(2023, 1, 15), mk_arb_free=mk_arb_free_config)
>>> print(df[["pure_strike", "mask_arb_free", "pure_fit1_price", "pure_fit1_delta"]])
This file’s main can also be used to generate data manually:
python -m arbfree SPX RUT NDX –period 2020-05-01 2022-01-31
- quantdata.widb.arbfree.SCHEMA_ARB_FREE_DAY_EXPIRY = {'ask_vol': dtype('float32'), 'bdte': <class 'numpy.float32'>, 'bid_vol': dtype('float32'), 'call_ask': dtype('float32'), 'call_bid': dtype('float32'), 'call_opt_id': <class 'numpy.int32'>, 'call_symbol': dtype('O'), 'date': dtype('<M8[ms]'), 'df': <class 'numpy.float32'>, 'expiry': dtype('<M8[ms]'), 'expiry_id': <class 'numpy.int32'>, 'fit1_vol': dtype('float32'), 'fwd': dtype('float32'), 'fwd_ref': <class 'numpy.float32'>, 'is_am': <class 'numpy.bool'>, 'is_american': <class 'numpy.bool'>, 'log_open_interest': dtype('float32'), 'log_volume': dtype('float32'), 'mask_arb_free': dtype('bool'), 'mkt_call_ask': <class 'numpy.float32'>, 'mkt_call_bid': <class 'numpy.float32'>, 'mkt_call_log_open_interest': <class 'numpy.float32'>, 'mkt_call_log_volume': <class 'numpy.float32'>, 'mkt_put_ask': <class 'numpy.float32'>, 'mkt_put_bid': <class 'numpy.float32'>, 'mkt_put_log_open_interest': <class 'numpy.float32'>, 'mkt_put_log_volume': <class 'numpy.float32'>, 'nms': dtype('float32'), 'nms_atm': dtype('float32'), 'pure_ask_delta': dtype('float32'), 'pure_ask_dk': dtype('float32'), 'pure_ask_gamma': dtype('float32'), 'pure_ask_price': dtype('float32'), 'pure_ask_theta': dtype('float32'), 'pure_ask_vega': dtype('float32'), 'pure_bid_delta': dtype('float32'), 'pure_bid_dk': dtype('float32'), 'pure_bid_gamma': dtype('float32'), 'pure_bid_price': dtype('float32'), 'pure_bid_theta': dtype('float32'), 'pure_bid_vega': dtype('float32'), 'pure_fit1_delta': dtype('float32'), 'pure_fit1_dk': dtype('float32'), 'pure_fit1_gamma': dtype('float32'), 'pure_fit1_price': dtype('float32'), 'pure_fit1_theta': dtype('float32'), 'pure_fit1_vega': dtype('float32'), 'pure_strike': dtype('float32'), 'put_opt_id': <class 'numpy.int32'>, 'put_symbol': dtype('O'), 'spot': <class 'numpy.float32'>, 'spot_prev': <class 'numpy.float32'>, 'strike': <class 'numpy.float32'>, 'ticker': dtype('O'), 'tte_y': <class 'numpy.float32'>}#
Fields and their types when arbitrage mode is
"expiry".
- quantdata.widb.arbfree.SCHEMA_ARB_FREE_DAY_SURFACE = {'ask_vol': dtype('float32'), 'bdte': <class 'numpy.float32'>, 'bid_vol': dtype('float32'), 'call_ask': dtype('float32'), 'call_bid': dtype('float32'), 'call_opt_id': <class 'numpy.int32'>, 'call_symbol': dtype('O'), 'date': dtype('<M8[ms]'), 'df': <class 'numpy.float32'>, 'expiry': dtype('<M8[ms]'), 'expiry_id': <class 'numpy.int32'>, 'fit1_vol': dtype('float32'), 'fitX_vol': dtype('float32'), 'fwd': dtype('float32'), 'fwd_ref': <class 'numpy.float32'>, 'is_am': <class 'numpy.bool'>, 'is_american': <class 'numpy.bool'>, 'log_open_interest': dtype('float32'), 'log_volume': dtype('float32'), 'mask_arb_free': dtype('bool'), 'mkt_call_ask': <class 'numpy.float32'>, 'mkt_call_bid': <class 'numpy.float32'>, 'mkt_call_log_open_interest': <class 'numpy.float32'>, 'mkt_call_log_volume': <class 'numpy.float32'>, 'mkt_put_ask': <class 'numpy.float32'>, 'mkt_put_bid': <class 'numpy.float32'>, 'mkt_put_log_open_interest': <class 'numpy.float32'>, 'mkt_put_log_volume': <class 'numpy.float32'>, 'nms': dtype('float32'), 'nms_atm': dtype('float32'), 'pure_ask_delta': dtype('float32'), 'pure_ask_dk': dtype('float32'), 'pure_ask_gamma': dtype('float32'), 'pure_ask_price': dtype('float32'), 'pure_ask_theta': dtype('float32'), 'pure_ask_vega': dtype('float32'), 'pure_bid_delta': dtype('float32'), 'pure_bid_dk': dtype('float32'), 'pure_bid_gamma': dtype('float32'), 'pure_bid_price': dtype('float32'), 'pure_bid_theta': dtype('float32'), 'pure_bid_vega': dtype('float32'), 'pure_fit1_delta': dtype('float32'), 'pure_fit1_dk': dtype('float32'), 'pure_fit1_gamma': dtype('float32'), 'pure_fit1_price': dtype('float32'), 'pure_fit1_theta': dtype('float32'), 'pure_fit1_vega': dtype('float32'), 'pure_fitX_delta': dtype('float32'), 'pure_fitX_dk': dtype('float32'), 'pure_fitX_gamma': dtype('float32'), 'pure_fitX_price': dtype('float32'), 'pure_fitX_theta': dtype('float32'), 'pure_fitX_vega': dtype('float32'), 'pure_strike': dtype('float32'), 'put_opt_id': <class 'numpy.int32'>, 'put_symbol': dtype('O'), 'spot': <class 'numpy.float32'>, 'spot_prev': <class 'numpy.float32'>, 'strike': <class 'numpy.float32'>, 'ticker': dtype('O'), 'tte_y': <class 'numpy.float32'>}#
Fields and their types when arbitrage mode is
"surface".
- quantdata.widb.arbfree.mk_arb_free_day(ticker, d, enriched_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), mk_arb_free=MkArbFree(no_arb_mode='surface', smoothness=None, surface_expiry_linear=True, min_half_spread=0.0001, mid_fit_weight=0.1, min_atm_vol=0.05, min_dlv=None, max_dlv=None, timeout_seconds=300.0, min_strikes_per_expiry=5, min_density=0.0001, min_dC_eps=0.001, _debug_verbose_cvxpy=None, _remove_no_arb_strikes=True, _debug_super_dense=False, _eps_price=1e-06, _eps_density=1e-07, _eps_dens_1=0.0001, _eps_no_arb=0.01), override_cache_mode=None, raise_if_bad_day=True, verbose=<cdxcore.verbose.Context object>)[source]#
Generate an arbitrage-free fit for a single enriched WIDB day.
The returned DataFrame keeps the full input-strike rows for retained expiries and adds mask/fitted-price/Greek columns aligned to those input strikes. Expiries and strikes dropped by MkArbFree are removed from the returned frame. The underlying mechanism is described in detail in
MkArbFree.The schema of the data frame returned depend on the settings in
mk_arb_free.no_arb_mode.expriy: the dataframe has schemaSCHEMA_ARB_FREE_DAY_EXPIRY. which includes all columnsSCHEMA_ENRICHED_DAYplus the following additional columns:mask_arb_free: boolean mask indicating which strikes were retained as arbitrage-free (True) vs dropped (False).pure_fit1_price: fitted arbitrage-free price within bid/ask wheremask_arb_freeis True.pure_fit1_delta,pure_fit1_gamma,pure_fit1_vega,pure_fit1_theta,pure_fit1_dk: Greeks corresponding topure_fit1_price.
surface: the dataframe has schemaSCHEMA_ARB_FREE_DAY_SURFACE, which includes all columns fromSCHEMA_ARB_FREE_DAY_EXPIRYplus:pure_fitX_price: surface arbitrage-free closest price tofit1prices. Up to machine precision, existence of afitXwithin bid/ask is equivalent to the market being free of arbitrage.pure_fitX_delta,pure_fitX_gamma,pure_fitX_vega,pure_fitX_theta,pure_fitX_dk: Greeks corresponding topure_fitX_price.
- Returns:
Result – This function may return None if
raise_if_bad_dayis False and the day is deemed bad as defined bybad.BAD.DAYS_ALL.- Return type:
:class:`pandas.DataFrame`|None