Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,53 @@

# pylint: disable=too-many-lines,redefined-outer-name

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,
},
{
"expiration": "2030-01-17",
"strike": 100,
"option_type": "put",
"open_interest": 8,
"volume": 4,
"delta": -0.4,
"gamma": 0.03,
"underlying_price": 100,
"contract_size": 100,
},
{
"expiration": "2030-01-17",
"strike": 105,
"option_type": "call",
"open_interest": 20,
"volume": 10,
"delta": 0.4,
"gamma": 0.01,
"underlying_price": 100,
"contract_size": 100,
},
{
"expiration": "2030-01-17",
"strike": 95,
"option_type": "put",
"open_interest": 12,
"volume": 7,
"delta": -0.25,
"gamma": 0.015,
"underlying_price": 100,
"contract_size": 100,
},
]


@pytest.fixture(scope="session")
def headers():
Expand Down Expand Up @@ -258,3 +305,25 @@ def test_derivatives_options_surface(params, headers):
)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.integration
def test_derivatives_options_exposure(headers):
"""Test the options exposure endpoint."""
url = "http://0.0.0.0:8000/api/v1/derivatives/options/exposure?by=strike"
result = requests.post(
url,
headers=headers,
timeout=10,
json={"data": SYNTHETIC_OPTIONS_CHAIN},
)
Comment on lines +314 to +319

assert isinstance(result, requests.Response)
assert result.status_code == 200

payload = result.json()
strike_100 = next(row for row in payload["results"] if row["strike"] == 100)

assert strike_100["total_open_interest"] == 18
assert strike_100["net_gex"] == -400
assert payload["extra"]["summary"]["gamma_wall"] == 105
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,53 @@
# pylint: disable=too-many-lines,redefined-outer-name
# pylint: disable=import-outside-toplevel,inconsistent-return-statements

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 +9 to +20
{
"expiration": "2030-01-17",
"strike": 100,
"option_type": "put",
"open_interest": 8,
"volume": 4,
"delta": -0.4,
"gamma": 0.03,
"underlying_price": 100,
"contract_size": 100,
},
{
"expiration": "2030-01-17",
"strike": 105,
"option_type": "call",
"open_interest": 20,
"volume": 10,
"delta": 0.4,
"gamma": 0.01,
"underlying_price": 100,
"contract_size": 100,
},
{
"expiration": "2030-01-17",
"strike": 95,
"option_type": "put",
"open_interest": 12,
"volume": 7,
"delta": -0.25,
"gamma": 0.015,
"underlying_price": 100,
"contract_size": 100,
},
]


@pytest.fixture(scope="session")
def obb(pytestconfig):
Expand Down Expand Up @@ -226,3 +273,31 @@ def test_derivatives_options_surface(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.integration
def test_derivatives_options_exposure(obb):
"""Test options exposure aggregation."""
result = obb.derivatives.options.exposure(
data=SYNTHETIC_OPTIONS_CHAIN,
by="strike",
)

assert result
assert isinstance(result, OBBject)
assert len(result.results) == 3

strike_100 = next(row for row in result.results if row["strike"] == 100)
assert strike_100["call_open_interest"] == 10
assert strike_100["put_open_interest"] == 8
assert strike_100["total_open_interest"] == 18
assert strike_100["net_gex"] == -400
assert strike_100["net_dex"] == 28000

summary = result.extra["summary"]
assert summary["total_open_interest"] == 50
assert summary["total_gex"] == 8200
assert summary["net_gex"] == -200
assert summary["put_call_ratio_open_interest"] == 0.6667
assert summary["gamma_wall"] == 105
assert summary["put_gamma_wall"] == 100
Loading