A local-first personal finance app
:bug: Monte carlo cashflow chart underfunding fix (#8964)
Michael Clark7548b0bfa9d0
diff --git a/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.test.ts b/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.test.tsindex 4abe55c2fa..f543af510a 100644--- a/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.test.ts+++ b/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.test.ts@@ -1234,6 +1234,32 @@ describe('runMonteCarloSimulation', () => {);});+ it('keeps the spending floor on the unfunded tail after a failure', () => {+ // A small pot under guardrails: repeated cuts would take the rule's+ // plan below the 1,800 floor, so the post-failure rows must still+ // chart the floor rather than the cut-down figure+ const result = runMonteCarloSimulation(+ makeParams(+ {+ annualWithdrawal: 2_000,+ horizonYears: 8,+ inflationMean: null,+ withdrawalRule: { ...WITHDRAWAL_RULE_DEFAULTS, type: 'guardrails' },+ minimumSpending: 1_800,+ captureRunDetail: 0,+ },+ { startingBalance: 5_000, expectedReturnMean: -0.5, returnStdDev: 0 },+ ),+ );++ const rows = result.runDetail!;+ const tailRows = rows.filter(row => row.afterDepletion);+ expect(tailRows.length).toBeGreaterThan(0);+ expect(tailRows.map(row => row.plannedSpending)).toEqual(+ tailRows.map(() => 1_800),+ );+ });+it('minimum spending floor neutralizes rule cuts', () => {const base = makeParams({ annualWithdrawal: 10_000, horizonYears: 30 },diff --git a/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.ts b/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.tsindex 1a155d18c5..277eaf8625 100644--- a/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.ts+++ b/packages/desktop-client/src/components/reports/reports/monte-carlo/monteCarloSimulation.ts@@ -2341,13 +2341,26 @@ export function runMonteCarloSimulation(tailTotalPlanned,);const tailIncome = emitFrozen(tailGrossIncome);+ // The pot-funded part of the plan, with the rule's adjustment and+ // the spending floor applied exactly as in a funded year+ const tailPotFundedPlan = tailTotalPlanned - tailIncomeTowardsSpending;+ let tailAdjustedPlan = tailPotFundedPlan * adjustmentFactor;+ if (+ rule.type !== 'none' &&+ minimumSpending > 0 &&+ tailPotFundedPlan > 0+ ) {+ tailAdjustedPlan = Math.max(+ tailAdjustedPlan,+ minimumSpending * cumulativeInflation - tailIncomeTowardsSpending,+ );+ }runDetail.push({year,afterDepletion: true,startBalance: 0,plannedSpending: emitFrozen(- tailIncomeTowardsSpending +- (tailTotalPlanned - tailIncomeTowardsSpending) * adjustmentFactor,+ tailIncomeTowardsSpending + Math.max(0, tailAdjustedPlan),),// Only the income still reaches spending once the pots are gonespent: emitFrozen(tailIncomeTowardsSpending),diff --git a/upcoming-release-notes/fix-monte-carlo-spending-floor-after-failure.md b/upcoming-release-notes/fix-monte-carlo-spending-floor-after-failure.mdnew file mode 100644index 0000000000..a1f8f0dd8f--- /dev/null+++ b/upcoming-release-notes/fix-monte-carlo-spending-floor-after-failure.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [MikesGlitch]+---++Fix the Monte Carlo cashflow chart showing spending below the minimum spending floor in the years after a plan runs out