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

@@ -196,12 +196,24 @@ def test_homepage_and_options_page_render() -> None:
page.get_by_role("button", name="Run comparison").click()
expect(page.locator("text=Ranked Results").first).to_be_visible(timeout=15000)
expect(page.locator("text=Scenario Results").first).to_be_visible(timeout=15000)
expect(page.locator("text=Strategy Drilldown").first).to_be_visible(timeout=15000)
expect(page.locator("text=Portfolio Value Paths").first).to_be_visible(timeout=15000)
expect(page.locator("text=Selected strategy: Protective Put ATM").first).to_be_visible(timeout=15000)
rerun_event_text = page.locator("body").inner_text(timeout=15000)
assert "Baseline series shows the unhedged collateral value path" in rerun_event_text
assert "Templates compared" in rerun_event_text and "4" in rerun_event_text
assert "Worst LTV point" in rerun_event_text
assert "Margin threshold breach dates" in rerun_event_text
assert "Daily path details" in rerun_event_text
assert "Historical scenario starts undercollateralized:" not in rerun_event_text
page.get_by_label("Strategy drilldown").click()
page.get_by_text("#4 — Protective Put 90%", exact=True).click()
expect(page.locator("text=Selected strategy: Protective Put 90%").first).to_be_visible(timeout=15000)
expect(page.locator("text=Rank #4 · Breached margin threshold").first).to_be_visible(timeout=15000)
expect(page.locator("text=2024-01-08 · 82.6%").first).to_be_visible(timeout=15000)
expect(page.locator("text=$17,939").first).to_be_visible(timeout=15000)
page.get_by_label("Event preset").click()
page.get_by_text("GLD January 2024 Drawdown", exact=True).click()
expect(page.locator("text=Results out of date").first).to_be_visible(timeout=15000)

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")