fire-planner/alembic/versions/0007_fire_target.py
Viktor Barzin edb4d11352
Some checks are pending
Build and Push / lint-and-test (push) Waiting to run
Build and Push / build (push) Blocked by required conditions
Build and Push / deploy (push) Blocked by required conditions
Build and Push / notify-failure (push) Blocked by required conditions
feat(fire-target): per-Case FIRE-number solver for the retirement countdown
Add a Monte-Carlo "FIRE number" solver so the wealth dashboard can show a £
countdown to retirement across life-stage cases, in today's money.

Viktor wants to see, per country, how far his net worth is from being able to
retire for good under three cases — Solo (his spend ×1.5), Household (+Anca
×1.5), Family (+2 kids) — with cost-of-living re-scaling per country and a 99%
Guyton-Klinger success bar.

- spend_model: per-Case real-GBP spend, COL-scaled (rent + non-rent essentials
  scale by country; Holidays fixed), ×1.5 safety. Constants sourced live from
  actualbudget (Viktor) / on-record (Anca).
- geo: city -> tax jurisdiction (nomad fallback).
- fire_target: binary-search the smallest LIQUID net worth where GK reaches the
  bar; pension modelled as a tranche unlocking at ~57, kids ramp + optional home
  as cashflows. New fire_target table (migration 0007) + idempotent upsert.
- recompute-fire-targets CLI: solve every Case x country and persist for Grafana.
- CONTEXT.md glossary + ADR-0001 (why MC-threshold on liquid NW, not 25x spend).

Reuses the existing simulator unchanged (its cashflow hooks already supported
pension/kids/home). 345 tests pass; mypy + ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 11:49:23 +00:00

60 lines
2.7 KiB
Python

"""add fire_target table for the FIRE-countdown solver
Revision ID: 0007
Revises: 0006
Create Date: 2026-06-28 00:00:00.000000
One solved FIRE number per (case, country, with_home, bar). The Grafana
countdown reads target_nw_gbp for the selected country and diffs it against
current liquid net worth. Seeded on liquid NW; the pension joins as
pension_at_unlock_gbp (see docs/adr/0001).
"""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "0007"
down_revision: str | None = "0006"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
SCHEMA = "fire_planner"
def upgrade() -> None:
op.create_table(
"fire_target",
sa.Column("id", sa.Integer(), nullable=False, autoincrement=True),
sa.Column("case", sa.String(length=16), nullable=False),
sa.Column("country_slug", sa.String(length=64), nullable=False),
sa.Column("country_display", sa.String(length=128), nullable=False),
sa.Column("jurisdiction", sa.String(length=32), nullable=False),
sa.Column("with_home", sa.Boolean(), nullable=False, server_default=sa.text("false")),
sa.Column("bar", sa.Numeric(4, 3), nullable=False, server_default=sa.text("0.99")),
sa.Column("strategy", sa.String(length=32), nullable=False,
server_default=sa.text("'guyton_klinger'")),
sa.Column("annual_spend_gbp", sa.Numeric(12, 2), nullable=False),
sa.Column("target_nw_gbp", sa.Numeric(16, 2), nullable=False),
sa.Column("pension_at_unlock_gbp", sa.Numeric(16, 2), nullable=False,
server_default=sa.text("0")),
sa.Column("success_at_target", sa.Numeric(6, 4), nullable=False),
sa.Column("reached_bar", sa.Boolean(), nullable=False, server_default=sa.text("true")),
sa.Column("horizon_years", sa.Integer(), nullable=False),
sa.Column("n_paths", sa.Integer(), nullable=False),
sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=False,
server_default=sa.func.now()),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("case", "country_slug", "with_home", "bar",
name="uq_fire_target_case_country_home_bar"),
schema=SCHEMA,
)
op.create_index("ix_fire_target_case", "fire_target", ["case"], schema=SCHEMA)
op.create_index("ix_fire_target_country_slug", "fire_target", ["country_slug"], schema=SCHEMA)
def downgrade() -> None:
op.drop_index("ix_fire_target_country_slug", table_name="fire_target", schema=SCHEMA)
op.drop_index("ix_fire_target_case", table_name="fire_target", schema=SCHEMA)
op.drop_table("fire_target", schema=SCHEMA)