My wife and I recently started paying two of our kids allowance. One of them likes to spend it, while the other likes to save it. I looked into opening a bank account so our saver could earn a return on the money, but it was too complicated. We don’t have any brick-and-mortar banks in walking distance from our house, and an online bank may make deposits and withdrawals tricky. There’s also questions of joint ownership or custodianship. Too serious for this age and amount of money.
I decided instead that we parents could act as the bank. Actually, I had toyed with this idea a few years ago and even made a Google Sheet for it. Looking at the spreadsheet, I saw that there was a formula implemented in “Apps Script” for computing the balance at a date:
function balance_at_date(date, compounding_rate, transaction_list) {
const timestamp = (new Date(date)).getTime();
const relevant_transactions = transaction_list.filter(
function(transaction) {
const transaction_timestamp = (new Date(transaction[0])).getTime();
return transaction_timestamp && transaction_timestamp <= timestamp;
}
);
const balance = relevant_transactions.reduce(
function(accumulator, transaction) {
const transaction_timestamp = (new Date(transaction[0])).getTime();
return accumulator + transaction[1] * Math.exp(compounding_rate * (timestamp - transaction_timestamp));
},
0
);
return balance;
}
Apparently I had written it a few years ago (the idiosyncratic JavaScript style is undeniably mine 😁), but neglected to write comments, so now I was puzzled by it [1]. It boils down to this:
and the code claims that the balance at time should be given by
It’s alluringly simple: each deposit/withdrawal accrues interest independent of the others. Can that be right? Why is it right?
[1] Aside: it’s unnecessary to use Apps Script for this. I’ve since replaced it with a “named function” (I think this is a new-ish feature) which looks like =ARRAYFORMULA(SUM(transaction_amounts * EXP(LN(1+rate)/365.25*(date-transaction_dates))))
.
In a sense, it’s right simply because the choice of how my bank pays out interest is arbitrary. But is it compatible with my understanding of continuous compound interest? Namely, if some principal is invested with a rate , then after a time its value is .
With that in mind, the thing that seems “clearly right” to me is to compute the balance according to:
This leads us to write down this recurrence relation:
Starting with , we quickly find
and by induction we have
which is essentially the same as the first formula (if we’re interested in an arbitrary time , consider a final deposit of at ). So, yes, these two perspectives are compatible: (1) adjust the balance after each deposit/withdrawal and then accrue interest on that balance, and (2) every deposit/withdrawal accrues interest independently.
We can see that the balance is “linear” in the deposits, in the sense that a function is linear in its argument if . Going back to the textbook formula, , it’s pretty clearly linear in . But in the current context, we’re dealing with a balance function whose input is a list of tuples, and it’s not as clear. Taking addition in the domain to be concatenation of the lists, we can show linearity with:
Also note that the differential equation is linear in and that the linear combination is a solution. I don’t think that implies that it must be the solution we were looking for, but maybe there’s some way to argue that.
I still find that linearity a bit surprising (so maybe I’m missing a key insight). But if I made two simultaneous deposits of instead of one deposit of , it’s not too hard to believe that they’d earn the same interest. It’s less obvious to me that deposits made at different times should accrue interest independently: shouldn’t the second deposit combine with the existing balance to enhance the earnings? Yes, but exactly as if the first continued to accrue interest independently, and the second accrued interest independently.
What does the term mean for a withdrawal (), though? I think this can be seen as an opportunity cost. Had it been left in the account instead of withdrawn, it would have earned that interest. In the formula for the balance, this opportunity cost is there in order to offset the interest that continues being accrued by that same money prior to its withdrawal. I suppose this is why a mortgage pre-payment should be considered like an investment at the mortgage interest rate: the future principal is reduced as if the extra payment were accruing that interest.
One last obvious thing to point out is that the balance is not linear in its time argument: . Instead, the dependence on time is exponential, which is what makes compound interest so interesting and “the most powerful force in the universe”, according to Einstein somebody.