31 lines
1.5 KiB
Python
31 lines
1.5 KiB
Python
"""Pretty terminal output for `fire-planner simulate`."""
|
|
from __future__ import annotations
|
|
|
|
from fire_planner.scenarios import ScenarioSpec
|
|
from fire_planner.simulator import SimulationResult
|
|
|
|
|
|
def format_scenario(spec: ScenarioSpec, result: SimulationResult) -> str:
|
|
"""Return a multi-line string summarising one scenario's MC output."""
|
|
lines = [
|
|
f"Scenario: {spec.external_id}",
|
|
f" jurisdiction = {spec.jurisdiction}",
|
|
f" strategy = {spec.strategy}",
|
|
f" leave_uk_year = {spec.leave_uk_year}",
|
|
f" glide_path = {spec.glide_path}",
|
|
f" starting_nw_gbp = {spec.nw_seed_gbp:>12,.0f}",
|
|
f" spending_target = {spec.spending_gbp:>12,.0f}",
|
|
f" horizon_years = {spec.horizon_years}",
|
|
" ----",
|
|
f" paths = {result.n_paths:>12,}",
|
|
f" success_rate = {result.success_rate*100:>11.2f}%",
|
|
f" p10_ending_gbp = {result.ending_percentile(10):>12,.0f}",
|
|
f" p50_ending_gbp = {result.ending_percentile(50):>12,.0f}",
|
|
f" p90_ending_gbp = {result.ending_percentile(90):>12,.0f}",
|
|
f" median_lifetime_tax = {result.median_lifetime_tax():>12,.0f}",
|
|
]
|
|
ytr = result.median_years_to_ruin()
|
|
if ytr is not None:
|
|
lines.append(f" median_years_to_ruin= {ytr:>12.1f}")
|
|
lines.append(f" seq_risk_correlation= {result.sequence_risk_correlation():>12.4f}")
|
|
return "\n".join(lines)
|