feat(BT-003B): add event comparison drilldown

This commit is contained in:
Bu5hm4nn
2026-03-26 22:05:31 +01:00
parent bdf56ecebe
commit 3c9ff201e1
8 changed files with 329 additions and 21 deletions

View File

@@ -199,3 +199,61 @@ def test_event_comparison_page_service_builds_chart_model_with_unhedged_referenc
assert chart_model.series[0].name == "Unhedged collateral baseline"
assert chart_model.series[1].name == "Protective Put ATM"
assert len(chart_model.series[0].values) == len(chart_model.dates)
def test_event_comparison_page_service_builds_drilldown_for_selected_ranking() -> None:
service = EventComparisonPageService()
report = service.run_read_only_comparison(
preset_slug="gld-jan-2024-selloff",
template_slugs=("protective-put-atm-12m", "protective-put-95pct-12m"),
underlying_units=1000.0,
loan_amount=68000.0,
margin_call_ltv=0.75,
)
drilldown = service.drilldown_model(report, template_slug="protective-put-95pct-12m")
assert drilldown.rank == 2
assert drilldown.template_name == "Protective Put 95%"
assert drilldown.margin_call_days_hedged == report.rankings[1].margin_call_days_hedged
assert drilldown.hedge_cost == report.rankings[1].hedge_cost
assert drilldown.final_equity == report.rankings[1].final_equity
assert (
drilldown.total_option_payoff_realized == report.rankings[1].result.summary_metrics.total_option_payoff_realized
)
assert drilldown.worst_ltv_date == "2024-01-08"
assert drilldown.rows[0].date == "2024-01-02"
assert drilldown.rows[-1].date == "2024-01-08"
def test_event_comparison_page_service_defaults_drilldown_to_top_ranked_strategy() -> None:
service = EventComparisonPageService()
report = service.run_read_only_comparison(
preset_slug="gld-jan-2024-selloff",
template_slugs=("protective-put-atm-12m", "protective-put-95pct-12m"),
underlying_units=1000.0,
loan_amount=68000.0,
margin_call_ltv=0.75,
)
drilldown = service.drilldown_model(report)
assert drilldown.rank == 1
assert drilldown.template_slug == report.rankings[0].template_slug
assert drilldown.template_name == report.rankings[0].template_name
def test_event_comparison_page_service_rejects_unknown_drilldown_template_slug() -> None:
service = EventComparisonPageService()
report = service.run_read_only_comparison(
preset_slug="gld-jan-2024-selloff",
template_slugs=("protective-put-atm-12m",),
underlying_units=1000.0,
loan_amount=68000.0,
margin_call_ltv=0.75,
)
with pytest.raises(ValueError, match="Unknown ranked template"):
service.drilldown_model(report, template_slug="missing-template")