32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from app.pages.common import strategy_metrics
|
|
from app.pages.hedge import _waterfall_options
|
|
|
|
|
|
def test_protective_put_atm_minus_20pct_improves_equity() -> None:
|
|
metrics = strategy_metrics("protective_put_atm", -20)
|
|
|
|
assert metrics["scenario_price"] == 172.0
|
|
assert metrics["unhedged_equity"] == 27_000.0
|
|
assert metrics["hedged_equity"] == 58_750.0
|
|
assert metrics["hedged_equity"] > metrics["unhedged_equity"]
|
|
assert metrics["waterfall_steps"] == [
|
|
("Base equity", 70_000.0),
|
|
("Spot move", -43_000.0),
|
|
("Option payoff", 38_000.0),
|
|
("Call cap", 0.0),
|
|
("Hedge cost", -6_250.0),
|
|
("Net equity", 58_750.0),
|
|
]
|
|
|
|
|
|
def test_hedge_waterfall_uses_zero_based_contribution_bars() -> None:
|
|
options = _waterfall_options(strategy_metrics("protective_put_atm", -20))
|
|
|
|
assert len(options["series"]) == 1
|
|
assert options["series"][0]["type"] == "bar"
|
|
values = options["series"][0]["data"]
|
|
assert values[2]["value"] == 38_000.0
|
|
assert values[2]["itemStyle"]["color"] == "#22c55e"
|