How the Decision tools retirement and fire planner calculator is verified

Inputs

InputFieldType
Your agecurrentAgeinteger
Invested todaycurrentPortfolionumber
Take-home income / yrannualIncomenumber
Spending / yrannualSpendingnumber
Retirement spending / yr (today's money)retirementSpendingnumber
Nominal return per year (%)nominalReturnPctnumber
Inflation per year (%)inflationPctnumber
Safe withdrawal rate (%)swrPctnumber
State or workplace pension / yrpensionAnnualnumber
Target retirement age (for Coast FI)targetRetirementAgeinteger
Project this many yearshorizonYearsinteger

The formula

Each derived value below is computed by the Valem engine from the expression shown, in this order. Nothing else runs — there is no hidden code path.

Derived valueFieldFormula (JSONata)
Saved per yearannualContribution$round(annualIncome - annualSpending, 2)
Savings ratesavingsRatePctannualIncome <= 0 ? 0 : $round((annualIncome - annualSpending) / annualIncome * 100, 1)
Real returnrealReturnPct$round(((1 + nominalReturnPct / 100) / (1 + inflationPct / 100) - 1) * 100, 4)
The number you needfiNumber$max([0, $round((retirementSpending - pensionAnnual) / (swrPct / 100), 2)])
Coast FI numbercoastNumber( $n := targetRetirementAge - currentAge; $n <= 0 ? fiNumber : $round(fiNumber / $power(1 + realReturnPct / 100, $n), 2) )
Portfolio against the number you need (today's money)projection$map([0..horizonYears], function($y) { { "year": $y, "age": currentAge + $y, "contributed": $round(currentPortfolio + annualContribution * $y, 2), "portfolio": $round($grow(currentPortfolio, annualContribution, realReturnPct / 100, $y), 2), "target": fiNumber } })
Financially independent atfiAge( $hits := $map(projection, function($p) { $p.portfolio >= $p.target ? $p.age : 0 })[$ > 0]; $count($hits) = 0 ? 0 : $min($hits) )
Years to get thereyearsToFifiAge > 0 ? fiAge - currentAge : 0
Fi ReachedfiReachedfiAge > 0
Final PortfoliofinalPortfolio( $p := $map(projection, function($r) { $r.portfolio }); $i := $count($p) - 1; $p[$i] )
Income at the endsustainableWithdrawal$round(finalPortfolio * swrPct / 100, 2)

Test vectors (4)

Every case is executed against this model on each build, by the Java engine and independently by a JavaScript one. A mismatch of a single cent fails the build, so the page cannot ship advertising a figure the model no longer produces.

Case 1 — age 30 with 100k invested, saving 40k of 100k, 7% nominal against 3% inflation, 4% withdrawal rate

given currentAge30
given currentPortfolio100000
given annualIncome100000
given annualSpending60000
given retirementSpending60000
given nominalReturnPct7
given inflationPct3
given swrPct4
expect annualContribution40000
expect savingsRatePct40
expect realReturnPct3.8835
expect fiNumber1500000
expect coastNumber478293.04
expect projection[0].portfolio100000
expect projection[1].portfolio143883.5
expect projection[22].portfolio1582779.59
expect fiAge52
expect yearsToFi22
expect fiReachedtrue
expect finalPortfolio4157295.48
expect sustainableWithdrawal166291.82

Case 2 — saving 60% instead of 40% brings independence forward five years

given annualSpending40000
expect annualContribution60000
expect savingsRatePct60
expect fiNumber1500000
expect fiAge47
expect yearsToFi17

Case 3 — a 12,000 pension cuts the number you need by exactly the pension capitalised at the withdrawal rate

given pensionAnnual12000
expect fiNumber1200000
expect coastNumber382634.43
expect fiAge48
expect yearsToFi18

Case 4 — spending everything you earn — the pot still compounds, but never reaches the target in the horizon

given annualSpending100000
expect annualContribution0
expect savingsRatePct0
expect fiAge0
expect fiReachedfalse
expect yearsToFi0
expect finalPortfolio459053.11

Sources

Check it yourself — and reuse it

The whole model as JSON — inputs, outputs, formulas, vectors and sources in one re-runnable document.

This model is published under CC BY 4.0: use it, adapt it, build on it, with attribution. The licence covers the model — the expression of each rule and the arrangement of the catalog. The rates and thresholds are law, and nobody licenses those; the sources above are where they come from.

← Back to the Decision tools retirement and fire planner calculator

Built with Valem — a live, verifiable calculator you can fork and embed.