Skip to content

A local-first personal finance app

:chart_with_upwards_trend: Monte Carlo pot balances chart (#9158)

Michael Clarkcba8cbd3f931
diff --git a/packages/desktop-client/package.json b/packages/desktop-client/package.json
index 63846798fc..3df7e3c17f 100644
--- a/packages/desktop-client/package.json
+++ b/packages/desktop-client/package.json
@@ -65,6 +65,7 @@
"#components/reports/graphs/showActivity": "./src/components/reports/graphs/showActivity.ts",
"#components/reports/graphs/util/computePadding": "./src/components/reports/graphs/util/computePadding.ts",
"#components/reports/graphs/util/monteCarloCashflowChart": "./src/components/reports/graphs/util/monteCarloCashflowChart.ts",
+ "#components/reports/graphs/util/monteCarloPotBalancesChart": "./src/components/reports/graphs/util/monteCarloPotBalancesChart.ts",
"#components/reports/graphs/util/useMonteCarloTickFormatter": "./src/components/reports/graphs/util/useMonteCarloTickFormatter.ts",
"#components/reports/numberFormatter": "./src/components/reports/numberFormatter.ts",
"#components/reports/ReportOptions": "./src/components/reports/ReportOptions.ts",
diff --git a/packages/desktop-client/src/components/reports/graphs/MonteCarloCashflowGraphTooltip.tsx b/packages/desktop-client/src/components/reports/graphs/MonteCarloCashflowGraphTooltip.tsx
index 4a0a2cdfde..183dda698f 100644
--- a/packages/desktop-client/src/components/reports/graphs/MonteCarloCashflowGraphTooltip.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/MonteCarloCashflowGraphTooltip.tsx
@@ -20,6 +20,13 @@ type MonteCarloCashflowGraphTooltipProps = {
active?: boolean;
payload?: PayloadItem[];
groups: MonteCarloCashflowTooltipGroup[];
+ /** Shown on years after the plan ran out; defaults to the cashflow wording */
+ afterDepletionNote?: string;
+ /**
+ * Keep rows whose value is zero (and their group). Balances read better
+ * with every pot listed each year; cashflows hide what didn't move
+ */
+ showZeroMembers?: boolean;
};
const VALUE_ROW_STYLE = css({
@@ -41,6 +48,8 @@ export function MonteCarloCashflowGraphTooltip({
active,
payload,
groups,
+ afterDepletionNote,
+ showZeroMembers = false,
}: MonteCarloCashflowGraphTooltipProps) {
const { t } = useTranslation();
const format = useFormat();
@@ -49,12 +58,13 @@ export function MonteCarloCashflowGraphTooltip({
return null;
}
const point = payload[0].payload;
- // Only series with money moving this year, and only groups with any
+ // Only series with money moving this year, and only groups with any -
+ // unless the chart wants every row shown regardless
const sections = groups
.map(group => {
const members = group.series
.map(series => ({ ...series, value: point.amounts[series.key] ?? 0 }))
- .filter(series => series.value !== 0);
+ .filter(series => showZeroMembers || series.value !== 0);
return {
...group,
members,
@@ -82,7 +92,8 @@ export function MonteCarloCashflowGraphTooltip({
<div
style={{ marginBottom: 10, maxWidth: 220, color: theme.errorText }}
>
- {t('The pots had already run out - this spending went unfunded.')}
+ {afterDepletionNote ??
+ t('The pots had already run out - this spending went unfunded.')}
</div>
)}
{point.unspentIncome > 0 && (
diff --git a/packages/desktop-client/src/components/reports/graphs/MonteCarloPotBalancesGraph.tsx b/packages/desktop-client/src/components/reports/graphs/MonteCarloPotBalancesGraph.tsx
new file mode 100644
index 0000000000..2fcbf8261d
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/graphs/MonteCarloPotBalancesGraph.tsx
@@ -0,0 +1,118 @@
+import { useTranslation } from 'react-i18next';
+
+import type { CSSProperties } from '@actual-app/components/styles';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+import {
+ Area,
+ CartesianGrid,
+ ComposedChart,
+ Tooltip,
+ XAxis,
+ YAxis,
+} from 'recharts';
+
+import { useRechartsAnimation } from '#components/reports/chart-theme';
+import { Container } from '#components/reports/Container';
+import { MonteCarloCashflowGraphTooltip } from '#components/reports/graphs/MonteCarloCashflowGraphTooltip';
+import { MonteCarloCashflowLegendGroup } from '#components/reports/graphs/MonteCarloCashflowLegendGroup';
+import { computePadding } from '#components/reports/graphs/util/computePadding';
+import { buildMonteCarloPotBalancesChart } from '#components/reports/graphs/util/monteCarloPotBalancesChart';
+import { useMonteCarloTickFormatter } from '#components/reports/graphs/util/useMonteCarloTickFormatter';
+import type {
+ MonteCarloPot,
+ MonteCarloRunDetailRow,
+} from '#components/reports/reports/monte-carlo/monteCarloSimulation';
+import { useFormat } from '#hooks/useFormat';
+
+const AREA_FILL_OPACITY = 0.6;
+
+type MonteCarloPotBalancesGraphProps = {
+ /** Applies to the whole block (chart plus legend); the chart itself is Container's default height */
+ style?: CSSProperties;
+ /** The captured run to chart, one row per simulated year */
+ rows: MonteCarloRunDetailRow[];
+ pots: MonteCarloPot[];
+ /** The user's current age; the x-axis shows startAge + year - 1 */
+ startAge: number;
+};
+
+/**
+ * Each pot's balance at the end of every year of a single simulated run,
+ * as stacked areas whose top is the plan's total. See
+ * buildMonteCarloPotBalancesChart for the data shape.
+ */
+export function MonteCarloPotBalancesGraph({
+ style,
+ rows,
+ pots,
+ startAge,
+}: MonteCarloPotBalancesGraphProps) {
+ const { t } = useTranslation();
+ const format = useFormat();
+ const tickFormatter = useMonteCarloTickFormatter();
+ const animationProps = useRechartsAnimation({ animationDuration: 1000 });
+
+ const { data, series, tooltipGroups, totals } =
+ buildMonteCarloPotBalancesChart({ rows, pots, startAge, translate: t });
+
+ return (
+ <View style={style}>
+ <Container>
+ {(width, height) => (
+ <ComposedChart
+ width={width}
+ height={height}
+ data={data}
+ margin={{
+ top: 15,
+ right: 0,
+ left: computePadding(totals, value =>
+ format(value, 'financial-no-decimals'),
+ ),
+ bottom: 10,
+ }}
+ >
+ <CartesianGrid strokeDasharray="3 3" vertical={false} />
+ <XAxis
+ dataKey="age"
+ tick={{ fill: theme.pageText }}
+ tickLine={{ stroke: theme.pageText }}
+ minTickGap={30}
+ />
+ <YAxis
+ tickFormatter={tickFormatter}
+ tick={{ fill: theme.pageText }}
+ tickLine={{ stroke: theme.pageText }}
+ />
+ <Tooltip
+ content={
+ <MonteCarloCashflowGraphTooltip
+ groups={tooltipGroups}
+ afterDepletionNote={t('The pots had run out by this year.')}
+ showZeroMembers
+ />
+ }
+ isAnimationActive={false}
+ />
+ {series.map(potSeries => (
+ <Area
+ key={potSeries.key}
+ type="monotone"
+ dataKey={`amounts.${potSeries.key}`}
+ stackId="pots"
+ stroke={potSeries.color}
+ fill={potSeries.color}
+ fillOpacity={AREA_FILL_OPACITY}
+ {...animationProps}
+ />
+ ))}
+ </ComposedChart>
+ )}
+ </Container>
+ <View style={{ marginTop: 10 }}>
+ <MonteCarloCashflowLegendGroup heading={t('Pots')} series={series} />
+ </View>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/reports/graphs/util/monteCarloCashflowChart.ts b/packages/desktop-client/src/components/reports/graphs/util/monteCarloCashflowChart.ts
index ca17727cc3..80c4e9e874 100644
--- a/packages/desktop-client/src/components/reports/graphs/util/monteCarloCashflowChart.ts
+++ b/packages/desktop-client/src/components/reports/graphs/util/monteCarloCashflowChart.ts
@@ -16,6 +16,16 @@ import type {
MonteCarloSpendingPhase,
} from '#components/reports/reports/monte-carlo/monteCarloSimulation';
+/**
+ * The colour a pot is drawn in across the single-run charts: the
+ * qualitative scale from its start, in pot order, so a pot looks the
+ * same in the cashflow and pot balances charts
+ */
+export function getMonteCarloPotColor(potIndex: number): string {
+ const colorScale = getColorScale('qualitative');
+ return colorScale[potIndex % colorScale.length];
+}
+
export type MonteCarloCashflowSeriesKind =
| 'pot'
| 'income'
@@ -122,7 +132,7 @@ export function buildMonteCarloCashflowChart({
key: seriesKey('pot', potIndex),
kind: 'pot',
label: getMonteCarloPotLabel(pots, potIndex, translate),
- color: inflowColor(potIndex),
+ color: getMonteCarloPotColor(potIndex),
}));
// Only streams that pay something in this run get a series
const incomeSeries: MonteCarloCashflowSeries[] = incomeStreams.flatMap(
diff --git a/packages/desktop-client/src/components/reports/graphs/util/monteCarloPotBalancesChart.test.ts b/packages/desktop-client/src/components/reports/graphs/util/monteCarloPotBalancesChart.test.ts
new file mode 100644
index 0000000000..43a628e1f1
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/graphs/util/monteCarloPotBalancesChart.test.ts
@@ -0,0 +1,157 @@
+import type { TFunction } from 'i18next';
+import { describe, expect, it } from 'vitest';
+
+import type {
+ MonteCarloPot,
+ MonteCarloRunDetailRow,
+} from '#components/reports/reports/monte-carlo/monteCarloSimulation';
+
+import { getMonteCarloPotColor } from './monteCarloCashflowChart';
+import { buildMonteCarloPotBalancesChart } from './monteCarloPotBalancesChart';
+
+// Interpolates like i18next so labels can be asserted literally
+const translate = ((key: string, options?: Record<string, unknown>) =>
+ key.replace(/{{\w+}}/g, placeholder => {
+ const name = placeholder.slice('{{'.length, -'}}'.length);
+ return String(options?.[name]);
+ })) as unknown as TFunction;
+
+function makePot(id: string, name = '', isSurplus = false): MonteCarloPot {
+ return {
+ id,
+ name,
+ startingBalance: 0,
+ allocationPreset: 'custom',
+ allocationStocks: 0.6,
+ allocationBonds: 0.4,
+ allocationCash: 0,
+ expectedReturnMean: 0,
+ returnStdDev: 0,
+ accessAge: null,
+ accountId: null,
+ withdrawalTaxRate: 0,
+ taxableFraction: 1,
+ annualFeeFixed: 0,
+ feeAdjustsWithInflation: false,
+ annualFeeRate: 0,
+ isSurplus,
+ };
+}
+
+function makeRow(
+ overrides: Partial<MonteCarloRunDetailRow> & { year: number },
+): MonteCarloRunDetailRow {
+ return {
+ startBalance: 0,
+ withdrawal: 0,
+ plannedSpending: 0,
+ spent: 0,
+ growth: 0,
+ endBalance: 0,
+ potBalances: [],
+ potStartBalances: [],
+ inflation: null,
+ income: 0,
+ incomeAmounts: [],
+ incomeTax: 0,
+ unspentIncome: 0,
+ surplusSaved: 0,
+ contributions: 0,
+ potContributions: [],
+ contributionAmounts: [],
+ potWithdrawals: [],
+ potTaxes: [],
+ potTaxables: [],
+ taxPaid: 0,
+ feesPaid: 0,
+ potFees: [],
+ potReturns: [],
+ ...overrides,
+ };
+}
+
+const pots = [
+ makePot('surplus', '', true),
+ makePot('pot-1', 'Pension'),
+ makePot('pot-2'),
+];
+
+describe('buildMonteCarloPotBalancesChart', () => {
+ it('builds one series per pot, named and coloured like the cashflow chart', () => {
+ const { series } = buildMonteCarloPotBalancesChart({
+ rows: [],
+ pots,
+ startAge: 60,
+ translate,
+ });
+ expect(series.map(entry => entry.label)).toEqual([
+ 'Surplus cash',
+ 'Pension',
+ 'Pot 2',
+ ]);
+ expect(series.map(entry => entry.color)).toEqual([
+ getMonteCarloPotColor(0),
+ getMonteCarloPotColor(1),
+ getMonteCarloPotColor(2),
+ ]);
+ expect(series.every(entry => entry.kind === 'pot')).toBe(true);
+ });
+
+ it('charts each year as the pots end-of-year balances with their total', () => {
+ const { data, totals, tooltipGroups } = buildMonteCarloPotBalancesChart({
+ rows: [
+ makeRow({ year: 1, potBalances: [0, 90_000, 10_000] }),
+ makeRow({ year: 2, potBalances: [500, 80_000, 0] }),
+ ],
+ pots,
+ startAge: 60,
+ translate,
+ });
+ expect(data.map(point => point.age)).toEqual([60, 61]);
+ expect(data[0].amounts).toEqual({
+ 'pot-0': 0,
+ 'pot-1': 90_000,
+ 'pot-2': 10_000,
+ });
+ expect(data[1].amounts).toEqual({
+ 'pot-0': 500,
+ 'pot-1': 80_000,
+ 'pot-2': 0,
+ });
+ expect(totals).toEqual([100_000, 80_500]);
+ expect(data.every(point => point.unspentIncome === 0)).toBe(true);
+ expect(tooltipGroups).toHaveLength(1);
+ expect(tooltipGroups[0].heading).toBe('Total');
+ expect(tooltipGroups[0].listMembers).toBe(true);
+ expect(tooltipGroups[0].series).toHaveLength(3);
+ });
+
+ it('carries the years after a failure as empty, flagged points', () => {
+ const { data, totals } = buildMonteCarloPotBalancesChart({
+ rows: [
+ makeRow({ year: 1, potBalances: [0, 5_000, 0] }),
+ makeRow({ year: 2, potBalances: [0, 0, 0] }),
+ makeRow({ year: 3, afterDepletion: true, potBalances: [0, 0, 0] }),
+ ],
+ pots,
+ startAge: 60,
+ translate,
+ });
+ expect(data.map(point => point.afterDepletion)).toEqual([
+ false,
+ false,
+ true,
+ ]);
+ expect(totals).toEqual([5_000, 0, 0]);
+ });
+
+ it('treats a missing pot balance as zero', () => {
+ const { data } = buildMonteCarloPotBalancesChart({
+ rows: [makeRow({ year: 1, potBalances: [0, 1_000] })],
+ pots,
+ startAge: 60,
+ translate,
+ });
+ expect(data[0].amounts['pot-2']).toBe(0);
+ });
+});
diff --git a/packages/desktop-client/src/components/reports/graphs/util/monteCarloPotBalancesChart.ts b/packages/desktop-client/src/components/reports/graphs/util/monteCarloPotBalancesChart.ts
new file mode 100644
index 0000000000..cf4fc535be
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/graphs/util/monteCarloPotBalancesChart.ts
@@ -0,0 +1,81 @@
+import type { TFunction } from 'i18next';
+
+import { getMonteCarloPotColor } from '#components/reports/graphs/util/monteCarloCashflowChart';
+import type {
+ MonteCarloCashflowDataPoint,
+ MonteCarloCashflowSeries,
+ MonteCarloCashflowTooltipGroup,
+} from '#components/reports/graphs/util/monteCarloCashflowChart';
+import { getMonteCarloPotLabel } from '#components/reports/reports/monte-carlo/monteCarloSimulation';
+import type {
+ MonteCarloPot,
+ MonteCarloRunDetailRow,
+} from '#components/reports/reports/monte-carlo/monteCarloSimulation';
+
+export type MonteCarloPotBalancesChart = {
+ /** One point per simulated year; amounts hold each pot's end-of-year balance */
+ data: MonteCarloCashflowDataPoint[];
+ /** One stacked series per pot, in the order the pots are configured */
+ series: MonteCarloCashflowSeries[];
+ /** A single group listing every pot under the year's total */
+ tooltipGroups: MonteCarloCashflowTooltipGroup[];
+ /** Each year's total balance, for axis padding */
+ totals: number[];
+};
+
+type BuildMonteCarloPotBalancesChartInput = {
+ /** The captured run to chart, one row per simulated year */
+ rows: MonteCarloRunDetailRow[];
+ pots: MonteCarloPot[];
+ /** The user's current age; the x-axis shows startAge + year - 1 */
+ startAge: number;
+ translate: TFunction;
+};
+
+/**
+ * What every pot was worth at the end of each year of a single simulated
+ * run, shaped for stacked areas. Reuses the cashflow chart's point and
+ * series shapes so its tooltip and legend serve both charts. Every pot
+ * gets a series even when it stays empty, so the legend matches the pots
+ * list; the synthetic years after a failure carry zero balances
+ */
+export function buildMonteCarloPotBalancesChart({
+ rows,
+ pots,
+ startAge,
+ translate,
+}: BuildMonteCarloPotBalancesChartInput): MonteCarloPotBalancesChart {
+ const series = pots.map(
+ (pot, potIndex) =>
+ ({
+ key: `pot-${potIndex}`,
+ kind: 'pot',
+ label: getMonteCarloPotLabel(pots, potIndex, translate),
+ color: getMonteCarloPotColor(potIndex),
+ }) satisfies MonteCarloCashflowSeries,
+ );
+
+ const data = rows.map(row => {
+ const amounts: Record<string, number> = {};
+ series.forEach((potSeries, potIndex) => {
+ amounts[potSeries.key] = row.potBalances[potIndex] ?? 0;
+ });
+ return {
+ year: row.year,
+ age: startAge + row.year - 1,
+ afterDepletion: row.afterDepletion === true,
+ unspentIncome: 0,
+ amounts,
+ } satisfies MonteCarloCashflowDataPoint;
+ });
+
+ const totals = data.map(point =>
+ Object.values(point.amounts).reduce((sum, amount) => sum + amount, 0),
+ );
+
+ const tooltipGroups: MonteCarloCashflowTooltipGroup[] = [
+ { key: 'pots', heading: translate('Total'), series, listMembers: true },
+ ];
+
+ return { data, series, tooltipGroups, totals };
+}
diff --git a/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarlo.tsx b/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarlo.tsx
index 0cdcf11b2d..d65424e8c2 100644
--- a/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarlo.tsx
+++ b/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarlo.tsx
@@ -23,6 +23,7 @@ import { MonteCarloCashflowGraph } from '#components/reports/graphs/MonteCarloCa
import { MonteCarloGraph } from '#components/reports/graphs/MonteCarloGraph';
import type { MonteCarloGraphView } from '#components/reports/graphs/MonteCarloGraphTooltip';
import { MonteCarloHistogram } from '#components/reports/graphs/MonteCarloHistogram';
+import { MonteCarloPotBalancesGraph } from '#components/reports/graphs/MonteCarloPotBalancesGraph';
import { LoadingIndicator } from '#components/reports/LoadingIndicator';
import { MonteCarloConfiguration } from '#components/reports/reports/monte-carlo/MonteCarloConfiguration';
import { HISTORICAL_ANNUAL_RETURNS } from '#components/reports/reports/monte-carlo/monteCarloHistoricalReturns';
@@ -67,13 +68,15 @@ export function MonteCarlo() {
const [config, setConfig] = useState<MonteCarloConfig>(MONTE_CARLO_DEFAULTS);
const [graphView, setGraphView] = useState<MonteCarloGraphView>('all');
- const [resultsView, setResultsView] = useState<'chart' | 'cashflow' | 'runs'>(
- 'chart',
- );
- // Which run the cashflow view charts, as a percentile of the worst-first
- // ranking (0 = worst run, 1 = best run) - the runs table's Jump to
- // percentiles, so both land on the same runs
- const [cashflowPercentile, setCashflowPercentile] = useState(0.5);
+ const [resultsView, setResultsView] = useState<
+ 'chart' | 'cashflow' | 'pots' | 'runs'
+ >('chart');
+ // Which run the cashflow and pot balances views chart, as a percentile
+ // of the worst-first ranking (0 = worst run, 1 = best run) - the runs
+ // table's Jump to percentiles, so all land on the same runs
+ const [scenarioPercentile, setScenarioPercentile] = useState(0.5);
+ // The single-run chart views share the run picker and detail capture
+ const showsScenarioRun = resultsView === 'cashflow' || resultsView === 'pots';
const [showTodaysMoney, setShowTodaysMoney] = useState(true);
// A selected run refers to a specific simulation, so the selection is
// stored with the config it belongs to and silently expires when the
@@ -191,20 +194,20 @@ export function MonteCarlo() {
[simulation],
);
- // The cashflow view charts one run picked by percentile of the ranking
- const cashflowRunIndex =
- resultsView === 'cashflow' && simulation != null && rankedRunIndices != null
+ // The single-run chart views chart one run picked by percentile of the
+ // ranking
+ const scenarioRunIndex =
+ showsScenarioRun && simulation != null && rankedRunIndices != null
? rankedRunIndices[
Math.round(
- cashflowPercentile * (simulation.result.simulationCount - 1),
+ scenarioPercentile * (simulation.result.simulationCount - 1),
)
]
: null;
- // The run whose year-by-year detail is on screen: the cashflow view's
+ // The run whose year-by-year detail is on screen: the chart views'
// scenario, or the drill-in's selection from the runs table
- const detailRunIndex =
- resultsView === 'cashflow' ? cashflowRunIndex : selectedRunIndex;
+ const detailRunIndex = showsScenarioRun ? scenarioRunIndex : selectedRunIndex;
// Runs are seeded, so re-running with a capture index reproduces the
// selected run exactly; only computed while a run is being inspected,
@@ -483,6 +486,8 @@ export function MonteCarlo() {
<Trans>Portfolio performance</Trans>
) : resultsView === 'cashflow' ? (
<Trans>Cashflow</Trans>
+ ) : resultsView === 'pots' ? (
+ <Trans>Pot balances</Trans>
) : (
<Trans>Simulation runs</Trans>
)}
@@ -500,6 +505,12 @@ export function MonteCarlo() {
>
<Trans>Cashflow</Trans>
</ModeButton>
+ <ModeButton
+ selected={resultsView === 'pots'}
+ onSelect={() => setResultsView('pots')}
+ >
+ <Trans>Pots</Trans>
+ </ModeButton>
<ModeButton
selected={resultsView === 'runs'}
onSelect={() => setResultsView('runs')}
@@ -523,10 +534,10 @@ export function MonteCarlo() {
style={{ width: 280 }}
/>
)}
- {resultsView === 'cashflow' && (
+ {showsScenarioRun && (
<Select
- value={String(cashflowPercentile)}
- onChange={value => setCashflowPercentile(Number(value))}
+ value={String(scenarioPercentile)}
+ onChange={value => setScenarioPercentile(Number(value))}
options={getRunPercentileOptions(t)}
style={{ width: 200 }}
/>
@@ -586,6 +597,29 @@ export function MonteCarlo() {
/>
</>
)
+ ) : resultsView === 'pots' ? (
+ runDetailRows != null && (
+ <>
+ <Text
+ style={{
+ color: theme.pageText,
+ marginBottom: 10,
+ flexShrink: 0,
+ }}
+ >
+ <Trans>
+ What each pot was worth at the end of every year of this
+ simulated run, stacked to the plan&apos;s total - locked
+ pots and the surplus pot included.
+ </Trans>
+ </Text>
+ <MonteCarloPotBalancesGraph
+ rows={runDetailRows}
+ pots={resolvedConfig.pots}
+ startAge={config.currentAge}
+ />
+ </>
+ )
) : selectedRunIndex != null &&
runDetailRows != null &&
fundedRunDetailRows != null ? (
@@ -608,6 +642,14 @@ export function MonteCarlo() {
style={{ marginBottom: 15 }}
/>
}
+ potBalancesGraph={
+ <MonteCarloPotBalancesGraph
+ rows={runDetailRows}
+ pots={resolvedConfig.pots}
+ startAge={config.currentAge}
+ style={{ marginBottom: 15 }}
+ />
+ }
onBack={() => setSelectedRun(null)}
/>
) : (
diff --git a/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarloRunDetailTable.tsx b/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarloRunDetailTable.tsx
index 29c331dea1..a84f8af188 100644
--- a/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarloRunDetailTable.tsx
+++ b/packages/desktop-client/src/components/reports/reports/monte-carlo/MonteCarloRunDetailTable.tsx
@@ -7,6 +7,7 @@ import {
SvgCheveronDown,
SvgCheveronRight,
} from '@actual-app/components/icons/v1';
+import { ModeButton } from '@actual-app/components/mode-button';
import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
@@ -63,6 +64,8 @@ type MonteCarloRunDetailTableProps = {
withdrawalRule: MonteCarloWithdrawalRuleConfig;
/** Rendered between the header row and the table - the cashflow chart */
cashflowGraph?: ReactNode;
+ /** The pot balances chart; with both charts given, buttons switch between them */
+ potBalancesGraph?: ReactNode;
onBack: () => void;
};
@@ -76,6 +79,7 @@ export function MonteCarloRunDetailTable({
incomeStreams,
withdrawalRule,
cashflowGraph,
+ potBalancesGraph,
onBack,
}: MonteCarloRunDetailTableProps) {
const { t } = useTranslation();
@@ -83,6 +87,9 @@ export function MonteCarloRunDetailTable({
const [expandedYears, setExpandedYears] = useState<Set<number>>(new Set());
// Years whose detailed working is shown under the summary
const [workingYears, setWorkingYears] = useState<Set<number>>(new Set());
+ // Which of the two single-run charts sits above the table; one at a
+ // time keeps the table within reach
+ const [chartView, setChartView] = useState<'cashflow' | 'pots'>('cashflow');
const hasIncome = incomeStreams.length > 0;
const surplusPotName = getMonteCarloSurplusPotLabel(pots, t);
@@ -420,7 +427,25 @@ export function MonteCarloRunDetailTable({
</Button>
</View>
- {cashflowGraph}
+ {cashflowGraph != null && potBalancesGraph != null && (
+ <View style={{ flexDirection: 'row', gap: 5, marginBottom: 10 }}>
+ <ModeButton
+ selected={chartView === 'cashflow'}
+ onSelect={() => setChartView('cashflow')}
+ >
+ <Trans>Cashflow</Trans>
+ </ModeButton>
+ <ModeButton
+ selected={chartView === 'pots'}
+ onSelect={() => setChartView('pots')}
+ >
+ <Trans>Pots</Trans>
+ </ModeButton>
+ </View>
+ )}
+ {chartView === 'pots' && potBalancesGraph != null
+ ? potBalancesGraph
+ : (cashflowGraph ?? potBalancesGraph)}
<Text size="medium" style={{ color: theme.pageText, marginBottom: 10 }}>
<PrivacyFilter>
diff --git a/packages/docs/docs/experimental/monte-carlo-analysis.md b/packages/docs/docs/experimental/monte-carlo-analysis.md
index d69b864059..88f3784479 100644
--- a/packages/docs/docs/experimental/monte-carlo-analysis.md
+++ b/packages/docs/docs/experimental/monte-carlo-analysis.md
@@ -61,7 +61,7 @@ The tab is organized into four small groups - **A. Your plan**, **B. Simulation*
### Investment Pots
-<img width="1184" alt="The Investment pots tab with three pots and the Vanguard 401k pot expanded" src="/img/experimental/monte-carlo-analysis/[email protected]" />
+<img width="1344" alt="The Investment pots tab with three pots and the Vanguard 401k pot expanded" src="/img/experimental/monte-carlo-analysis/[email protected]" />
A _pot_ is a chunk of invested money - a pension or retirement account, an investment account, a savings account. You can model one pot or several, each with its own settings:
@@ -107,7 +107,7 @@ A plan whose income covers its spending doesn't need the pots at all, and empty
### Contributions
-<img width="1184" alt="The Contributions tab with yearly contributions into the Vanguard 401k pot" src="/img/experimental/monte-carlo-analysis/[email protected]" />
+<img width="1344" alt="The Contributions tab with yearly contributions into the Vanguard 401k pot" src="/img/experimental/monte-carlo-analysis/[email protected]" />
If you're still earning, you can model the money you add to your pots each year - pension deposits or brokerage savings, anything that tops up a pot on a regular basis. Each contribution has:
@@ -220,7 +220,17 @@ On a run that fails, the chart doesn't stop at the failure year: the remaining y
The spending bars show the _plan_ - the phase amount, adjusted for inflation, any withdrawal rule and the minimum spending floor - rather than the money actually delivered. That's what makes trouble visible: in a shortfall year the withdrawal bars fall visibly short of the spending bar.
-Use the dropdown above the chart to pick which run to look at: the worst run, a typically-bad or typically-good outcome (the 25th and 75th percentiles), the median, or the best run. These are the same runs the **Jump to** dropdown in the runs view lands on. The chart also appears above the year-by-year table when you click into any individual run, so you can see that specific run's flows at a glance.
+Use the dropdown above the chart to pick which run to look at: the worst run, a typically-bad or typically-good outcome (the 25th and 75th percentiles), the median, or the best run. These are the same runs the **Jump to** dropdown in the runs view lands on. The chart also appears above the year-by-year table when you click into any individual run, where **Cashflow** and **Pots** buttons switch between this chart and the pot balances chart.
+
+### The Pot Balances Chart
+
+<img width="1184" alt="The pot balances chart for the median run, with each pot stacked to the plan's total" src="/img/experimental/monte-carlo-analysis/[email protected]" />
+
+Switch the results view to **Pots** to see what each of your pots was worth at the end of every year, for one simulated run at a time. The pots are stacked on top of each other, one color per pot (the same colors as the cashflow chart), so the top of the stack is the plan's total balance and the bands inside it show how that total is split. Locked pots and the surplus pot are included, so you can watch a pension sit untouched until its access age, or the surplus pot fill up with income the plan didn't need.
+
+Hover over a year to see every pot's balance and the total. On a run that fails, the accessible pots are emptied in the failure year - so the stack may not reach zero that year if money is still locked in a pot that hasn't reached its access age - and every year after it is drawn as zero.
+
+The dropdown above the chart picks the run, exactly as it does for the cashflow chart, and the chart also appears above the year-by-year table when you click into a run from the **Runs** view, where **Cashflow** and **Pots** buttons switch between the two charts. Like every other figure in the results, the balances follow the **Show values in today's money** checkbox.
### When Did the Pot Run Out?
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 8eea3f437c..dfce968ce4 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 87c3fd56fd..ec76c00c45 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index fa82acfa85..370e9ae8b0 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 1f9bfcf148..7811dc25e6 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 06e5cdc03f..f5c26fa645 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 73d5703c2a..b360eb53e1 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 3fbe2efc84..8212bcdace 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
new file mode 100644
index 0000000000..02fe299b84
Binary files /dev/null and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 956888c321..9c11646d22 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 146510c1d6..a15354076b 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 3b09192efc..6b973497c2 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 05e3dc05cb..bf1de80c42 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 5bce1888a9..d35047d756 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected]
index 4da70c400c..85904236a9 100644
Binary files a/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] and b/packages/docs/static/img/experimental/monte-carlo-analysis/[email protected] differ
diff --git a/upcoming-release-notes/monte-carlo-pot-balances-chart.md b/upcoming-release-notes/monte-carlo-pot-balances-chart.md
new file mode 100644
index 0000000000..4696aadcf4
--- /dev/null
+++ b/upcoming-release-notes/monte-carlo-pot-balances-chart.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [MikesGlitch]
+---
+
+Add a pot balances chart to the Monte Carlo report showing what each pot is worth at the end of every year