Sign the investments line so withdrawals net against contributions
ci / lint-test (push) Successful in 50s

A withdrawal from a fund is a disinvestment, not income: units convert
back to cash and net worth is unchanged. Summed unsigned it read as more
money invested. March 2026 showed $38,615.34 of investing in a month that
was net -$11,384.66, because a $25,000 Raiz withdrawal was added to an
$8,563.80 IBKR deposit instead of cancelling it.

Each credit costs twice — once for being added, once for not being
subtracted — so the error is double the credit: $50,000 in March, $3,000
in May 2025, $53,000 across the window. Since net = income - spent -
investments, March's net of -$55,918.73 should read -$5,918.73.

Filing withdrawals as income is the other tempting answer and is worse:
it books an asset disposal as earnings and feeds the same figure into net
with a flattering sign. Same reason the Up item sales in Known Gaps do
not belong on the income line.

What this cannot resolve: part of a withdrawal genuinely is income — the
capital gain. The bank descriptor is one gross figure with no cost base,
so it cannot be decomposed from statement data. Netting tracks cash
committed against cash returned and leaves the gain for holdings data to
surface; it does not assert the gain is zero.

The budget page gates the Invested card on `!== 0` rather than `> 0` — a
net-disinvesting month is real data, not an empty one — and renders
negative months in amber so the sign is not hidden by matching digits.
This commit is contained in:
2026-07-31 00:05:05 +10:00
parent f6c500b27a
commit c70d2b1fac
5 changed files with 124 additions and 4 deletions
+27
View File
@@ -192,6 +192,33 @@ export const SPEND_SIGNED = `CASE
ELSE (${SPEND_BASE})
END`;
/**
* The investment line, signed: withdrawals come back as negatives so they net
* against contributions.
*
* A withdrawal from a fund is a disinvestment — units converted back to cash,
* net worth unchanged. Summed unsigned it read as *more* money invested: March
* 2026 showed $38,615.34 of investing in a month that was net -$11,384.66,
* because a $25,000 Raiz withdrawal was added to a $8,563.80 IBKR deposit
* instead of cancelling it. Overstated by $50,000 in that month alone — each
* credit costs twice, once for being added and once for not being subtracted.
*
* Filing withdrawals as `income` instead is the other tempting answer and is
* worse: it books an asset disposal as earnings and feeds the same figure into
* `net = income - spent - investments` with a flattering sign. Same reason the
* Up item sales in Known Gaps do not belong on the income line.
*
* Caveat this cannot resolve: part of a withdrawal genuinely is income — the
* capital gain. The bank descriptor is a single gross figure with no cost base,
* so it cannot be decomposed here. Netting tracks cash committed against cash
* returned and leaves the gain for holdings data to surface; it does not claim
* the gain is zero.
*/
export const INVESTMENT_SIGNED = `CASE
WHEN t.transaction_type IN ('refund', 'credit') THEN -COALESCE(t.amount_aud, t.amount)
ELSE COALESCE(t.amount_aud, t.amount)
END`;
/**
* A split that still counts towards what someone owes.
*