Add FI and Coast FI milestones to the retirement planner
Base: up/retirement-plan-monte-carlo (stacked) | Head: up/retirement-plan-milestones | Draft
Part of #5567
Fork pre-flight: jaysbeekay/sure#370 (same commits, head b6beb9263)
Stacked on #5611
Last of four. Model only: no route, controller or view.
Problem
A plan says where the portfolio ends up, but not the points on the way that a user can check against, such as a quarter of the FI number, or the year they could stop saving and still get there.
Resulting behaviour
A plan names the years it reaches 25%, 50%, 75% and 100% of its FI number, and its Coast FI year. Coast FI is the first saving year from which the portfolio, with nothing more added, would grow at the real return to the FI number by the retirement year.
The design choice to know about: everything is compared in today's money. Each year's end_value_real is set against today's FI number, so inflation cannot make a milestone look closer than it is.
RetirementPlan::Milestones(pure) reads a simulation's rows and is handed everything else. A milestone already passed isreached_already, with no year. One never reached within the plan has neither. Coast FI testsend_value_real(t) >= FI / (1 + real)^(retirement_year - t - 1), withreal = (1 + r) / (1 + i) - 1, over saving years only. When the retirement year has already passed, Coast FI is absent, which means "not applicable", not "reached".RetirementPlan#milestones(as_of:, simulation:)measures against#projection's FI number, from the starting assets of the simulation it is handed. The caller hands in the simulation it draws, so in FIRE mode the milestones follow the path to the solved year. The Coast FI target stays at the plan's own retirement date. Its saving years stop at whichever comes first: the drawn path's retirement year or the plan's.
This is separate from #4385, which adds 25/50/75% marks to an ordinary Goal. That PR touches only Goal, and neither depends on the other.
Size: 104 non-test lines, all added.
Validation
- Full suite
bin/rails testat this PR's headb6beb9263: 18621 runs, 0 failures. The 8 errors areReleaseNotesWorkflowTest, which needsnode, missing from the test image. - CI at this head: lint (
bin/rubocop), Brakeman, and the unit and system test jobs pass. - The engine is run on two different days under
travel_to, insideassert_queries_count(0)and withCurrentexpected never. Both runs must give the same milestones. - Mutations, each caught by a failing assertion:
| Mutation | Caught by |
|---|---|
| nominal value instead of today's money | milestones and Coast FI are measured in today's money, at the real return |
| threshold must be beaten, not met | a milestone reached exactly on its threshold counts |
| Coast FI at the nominal return | milestones and Coast FI are measured in today's money, at the real return |
| Coast FI counts retirement years | Coast FI counts only the saving years |
| Coast FI exponent off by one | Coast FI is the first year the value would grow...; measured in today's money |
| past retirement year keeps Coast FI | a retirement year already past has no Coast FI |
| plan ignores the simulation handed in | the milestones follow the simulation the page draws when it hands one in |
| Coast FI measured to the drawn path's year | Coast FI keeps measuring to the plan's retirement date when a drawn path retires earlier |
| saving years run past the drawn path's retirement | Coast FI stops at the path's retirement when the path retires before the plan does |
Blast radius
RetirementPlan#milestones is new and has no caller yet; a planner page would pass the simulation it draws. It reads #simulation, #projection and the private #funding_total, and changes none of them. grep -rn "Milestones" app finds only RetirementPlan#milestones.
Migration notes
No migration.
Screenshots
None: this PR has no UI. The planner page that shows these figures follows as the next PRs in this stack, with before and after screenshots, and the last of them closes #5567.
Summary by cubic
Adds FI and Coast FI milestones to the retirement planner so a plan shows the years it reaches 25%, 50%, 75% and 100% of its FI number, plus the first year the user could stop saving (Coast FI). Model only: no route, controller or view yet.
- Milestones are measured in today's money, so inflation can't make them look closer than they are.
- A milestone already passed is
reached_alreadywith no year; one never reached has neither. - Coast FI counts saving years only, stopping at the earlier of the plan's or the drawn path's retirement year, and measures to the plan's own date. Without a saved retirement date (a FIRE plan) it is absent, meaning "not applicable", not "reached".
RetirementPlan#milestonestakes the simulation the page draws, so FIRE milestones follow the solved path.- Milestones start from the simulation's own assets rather than the plan's funding total, so they match the path they're drawn against.
- A plan that can't be simulated returns no milestones, even when handed a simulation built earlier.
- Today's assets and the milestone years count only the part of the current year left, as the simulation's first row does, so a 1 January start counts the whole year.
Summary by CodeRabbit
- New Features
- Added financial independence milestones at 25%, 50%, 75%, and 100% of the FI target, with estimated years, ages, and reached status.
- Milestones reflect current assets and projected progress in today’s money; already-achieved targets are identified.
- Added Coast FI milestones when applicable, based on the plan’s retirement date and projected growth.
- Milestones are unavailable when a plan cannot be simulated, and Coast FI is omitted when the retirement date is missing or outside the eligible range.