From 5f00f98af14b0aa8bf813e7d9c0a217014585797 Mon Sep 17 00:00:00 2001 From: Art Cashin <64659740+artcashin@users.noreply.github.com> Date: Sat, 28 Nov 2026 23:46:23 +0000 Subject: [PATCH] fix(cboe): term structure skips a side with no out-of-the-money strike (#7846) An expiry that lists a single strike has no OTM strike on one side. The strike lookup returned None and the subtraction raised a TypeError for the whole chart. Co-authored-by: Claude Fable 5.2 Co-authored-by: dlee-bq --- .../utils/options/create_term_structure.py | 5 +- .../cboe/tests/test_options_analysis.py | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/openbb_platform/providers/cboe/openbb_cboe/utils/options/create_term_structure.py b/openbb_platform/providers/cboe/openbb_cboe/utils/options/create_term_structure.py index d5f09465b1c..c9c8d2a313d 100644 --- a/openbb_platform/providers/cboe/openbb_cboe/utils/options/create_term_structure.py +++ b/openbb_platform/providers/cboe/openbb_cboe/utils/options/create_term_structure.py @@ -102,7 +102,8 @@ def create_term_structure( & (df[price_col] > 0) ] - if not calls_filtered.empty: + # An expiry with no out-of-the-money strike on a side has no point on that side. + if call_strike is not None and not calls_filtered.empty: calls = concat( [ calls, @@ -118,7 +119,7 @@ def create_term_structure( & (df[price_col] > 0) ] - if not puts_filtered.empty: + if put_strike is not None and not puts_filtered.empty: puts = concat( [ puts, diff --git a/openbb_platform/providers/cboe/tests/test_options_analysis.py b/openbb_platform/providers/cboe/tests/test_options_analysis.py index e75b3dfaf60..26a1ef3356e 100644 --- a/openbb_platform/providers/cboe/tests/test_options_analysis.py +++ b/openbb_platform/providers/cboe/tests/test_options_analysis.py @@ -260,6 +260,64 @@ class TestTermStructure: assert len(output.chart.content["data"]) == 1 + def test_expiry_without_an_otm_strike_on_one_side(self): + """An expiry listing one strike has no OTM put; that side is skipped.""" + import time_machine + + from openbb_cboe.models.options_chains import CboeOptionsChainsFetcher + + quote = { + "bid": 1.0, + "ask": 1.1, + "bid_size": 1, + "ask_size": 1, + "iv": 0.2, + "open_interest": 5, + "volume": 2, + "delta": 0.5, + "gamma": 0.1, + "theta": -0.1, + "vega": 0.1, + "rho": 0.0, + "theo": 1.05, + "change": 0.0, + "open": 1.0, + "high": 1.0, + "low": 1.0, + "tick": "up", + "last_trade_price": 1.0, + "last_trade_time": "2026-11-17T15:59:59", + "percent_change": 0.0, + "prev_day_close": 1.0, + } + # The second expiry lists a single strike, above the price. + symbols = [ + "SPY271119C00710000", + "SPY271119P00690000", + "SPY271202C00825000", + "SPY271202P00825000", + ] + payload = { + "data": { + "symbol": "SPY", + "current_price": 700.0, + "options": [{**quote, "option": symbol} for symbol in symbols], + } + } + with time_machine.travel("2026-11-17", tick=True): + chain = CboeOptionsChainsFetcher.transform_data( + CboeOptionsChainsFetcher.transform_query({"symbol": "SPY"}), payload + ).result + rows = create_term_structure(chain, metric="price").results + + assert sorted( + (str(r.expiration)[:10], r.option_type, r.strike) for r in rows + ) == [ + ("2027-11-19", "call", 710.0), + ("2027-11-19", "put", 690.0), + ("2027-12-02", "call", 825.0), + ] + def test_requires_iv(self, options_chain): """Requesting IV on a chain without it is rejected.""" stub = type("Stub", (), {"has_iv": False})()