Skip to content

feat: add options exposure summary command#7540

Closed
HOYALIM wants to merge 1 commit into
OpenBB-finance:developfrom
HOYALIM:codex/openbb-options-exposure
Closed

feat: add options exposure summary command#7540
HOYALIM wants to merge 1 commit into
OpenBB-finance:developfrom
HOYALIM:codex/openbb-options-exposure

Conversation

@HOYALIM

@HOYALIM HOYALIM commented Jun 17, 2026

Copy link
Copy Markdown

Summary

  • add POST command obb.derivatives.options.exposure for option-chain exposure summaries
  • aggregate open interest, volume, DEX, and GEX by strike or expiration
  • report signed net_dex/net_gex separately from gross total_dex/total_gex
  • return gamma/call/put wall and put-call ratio summary metadata
  • keep exposure math in an options helper module so the router remains focused on endpoint orchestration

Quality Hardening

  • avoid reporting misleading zero DEX/GEX when greeks or underlying price are unavailable
  • honor OptionsChainsData.last_price when users set the underlying price after fetching chains
  • derive missing DTE from eod_date for historical option-chain rows before falling back to today
  • add deterministic non-integration unit coverage for strike/expiration aggregation, OTM filtering, missing greeks, null underlying price, last_price, and historical DTE handling

Tests

  • uvx --from black black --check openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py openbb_platform/extensions/derivatives/tests/test_options_exposure.py openbb_platform/extensions/derivatives/integration/test_derivatives_python.py openbb_platform/extensions/derivatives/integration/test_derivatives_api.py
  • uvx --from ruff ruff check openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py openbb_platform/extensions/derivatives/tests/test_options_exposure.py openbb_platform/extensions/derivatives/integration/test_derivatives_python.py openbb_platform/extensions/derivatives/integration/test_derivatives_api.py
  • uvx --from openbb-devtools mypy openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py --ignore-missing-imports --scripts-are-modules --check-untyped-defs
  • uvx --from openbb-devtools pylint openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py
  • PYTHONPATH=openbb_platform/core:openbb_platform/extensions/derivatives uvx --from pytest --with pandas --with pydantic --with uuid7 --with fastapi --with python-multipart --with requests --with aiohttp --with websockets --with html5lib --with python-dotenv --with importlib-metadata --with pyjwt pytest openbb_platform/extensions/derivatives/tests/test_options_exposure.py -q
  • PYTHONPATH=<core plus all extension package dirs> uvx --from pytest --with pandas --with pydantic --with uuid7 --with fastapi --with python-multipart --with requests --with aiohttp --with websockets --with html5lib --with python-dotenv --with importlib-metadata --with pyjwt pytest openbb_platform/extensions/tests/test_routers.py -q

Refs #6948

Copilot AI review requested due to automatic review settings June 17, 2026 01:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new options “exposure” endpoint that aggregates options chain exposures (OI/volume plus DEX/GEX when available) by strike or expiration, and introduces integration coverage for both Python and HTTP API usage.

Changes:

  • Added helpers to normalize options chain inputs and compute exposure aggregates + summary metrics.
  • Added POST /derivatives/options/exposure router command with filtering controls (ITM/OTM, DTE, moneyness, strike range, etc.).
  • Added integration tests for the new exposure command via the Python client and via the REST API.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py Adds exposure aggregation helpers and the new exposure router command.
openbb_platform/extensions/derivatives/integration/test_derivatives_python.py Adds Python integration test validating exposure aggregation on synthetic chain data.
openbb_platform/extensions/derivatives/integration/test_derivatives_api.py Adds REST API integration test hitting the new exposure endpoint with synthetic data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +34
if isinstance(data, OptionsChainsData):
df = DataFrame(data.model_dump(exclude_none=True, exclude_unset=True))
elif isinstance(data, DataFrame):
df = DataFrame(data.copy())
elif isinstance(data, dict):
df = DataFrame(data if all(isinstance(v, list) for v in data.values()) else [data])
Comment on lines +24 to +25
def _options_data_to_df(data: list[Data] | Data, underlying_price: float | None = None):
"""Normalize options chain inputs into a DataFrame."""
Comment on lines +469 to +482
@router.command(
methods=["POST"],
examples=[
PythonEx(
description="Summarize gamma, delta, open interest, and volume exposure by strike.",
code=[
"data = obb.derivatives.options.chains('AAPL', provider='cboe')",
"exposure = obb.derivatives.options.exposure(data=data.results, by='strike')",
"exposure.to_df(index=None).head()",
"exposure.extra['summary']",
],
),
],
)
Comment on lines +133 to +144
def _as_native(value: Any) -> Any:
"""Convert Pandas/Numpy values to API-safe Python values."""
# pylint: disable=import-outside-toplevel
from pandas import isna

if isna(value):
return None
if hasattr(value, "item"):
return value.item()
if hasattr(value, "date"):
return value.date().isoformat()
return value
Comment on lines +9 to +20
SYNTHETIC_OPTIONS_CHAIN = [
{
"expiration": "2030-01-17",
"strike": 100,
"option_type": "call",
"open_interest": 10,
"volume": 5,
"delta": 0.6,
"gamma": 0.02,
"underlying_price": 100,
"contract_size": 100,
},
Comment on lines +314 to +319
result = requests.post(
url,
headers=headers,
timeout=10,
data=json.dumps({"data": SYNTHETIC_OPTIONS_CHAIN}),
)
@HOYALIM HOYALIM force-pushed the codex/openbb-options-exposure branch from a9c91e8 to ee5f3b7 Compare June 17, 2026 04:56
@HOYALIM HOYALIM force-pushed the codex/openbb-options-exposure branch from ee5f3b7 to 09e64f5 Compare June 17, 2026 06:43
@deeleeramone

Copy link
Copy Markdown
Contributor

This is a sloppy duplication of code that already exists. No AI slop please.

>>> chains = obb.derivatives.options.chains("AAPL", provider="cboe").results
>>> chains.filter_data(by="expiration", stat="gex")

    Expiration      Calls       Puts      Total  Net Percent     PCR
0   2026-06-17  214090503  273214326  487304829      13.1106  1.2762
1   2026-06-18  680939740  314556408  995496148      26.7830  0.4619
2   2026-06-22   38516758   24226907   62743665       1.6881  0.6290
3   2026-06-24   11141622    7413023   18554645       0.4992  0.6653
4   2026-06-26  101525600   43103941  144629541       3.8911  0.4246
5   2026-06-29    5524176    1304785    6828961       0.1837  0.2362
6   2026-07-02   43041360   19692821   62734181       1.6878  0.4575
7   2026-07-10   23114116   10716690   33830806       0.9102  0.4636
8   2026-07-17  451401437  145964630  597366067      16.0717  0.3234
9   2026-07-24   12392113    4803901   17196014       0.4626  0.3877
10  2026-07-31    3504463    2360221    5864684       0.1578  0.6735
11  2026-08-21  197663794   86333364  283997158       7.6407  0.4368
12  2026-09-18  197227202   64005320  261232522       7.0283  0.3245
13  2026-10-16   45612405   25137026   70749431       1.9035  0.5511
14  2026-11-20   33031872   25342215   58374087       1.5705  0.7672
15  2026-12-18   94294502   55901629  150196131       4.0409  0.5928
16  2027-01-15  174550211   95371423  269921634       7.2620  0.5464
17  2027-02-19    4230719    5830496   10061215       0.2707  1.3781
18  2027-03-19   16951943    8713374   25665317       0.6905  0.5140
19  2027-06-17   36449102   18806267   55255369       1.4866  0.5160
20  2027-09-17    4019041    2101534    6120575       0.1647  0.5229
21  2027-12-17   21150626   13545057   34695683       0.9335  0.6404
22  2028-01-21   24390774   10503889   34894663       0.9388  0.4307
23  2028-03-17    4779062    2564972    7344034       0.1976  0.5367
24  2028-12-15   11172100    4660291   15832391       0.4260  0.4171

@HOYALIM HOYALIM deleted the codex/openbb-options-exposure branch June 17, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants