Finance – Calculating Optimal Frequency for Moving Funds Between Compound Interest Accounts

financeoperations researchoptimization

The Problem

I have two compound interest accounts, Account A, which has 0.5% yearly interest, but I have to keep \$30,000 there to unlock some bonus; and Account B, which has 2% yearly interest. Transferring between the two accounts costs \$0.5. I only want to keep \$30,000 in Account A to have the bonus and I want to transfer the rest to Account B. No additional money comes to Account A. Both accounts pay interest every minute.

I want to find the optimal times of moving funds from Account A to Account B that results in the most profit (a finite time horizon is imposed). The frequency can vary as time progresses. Here is a similar problem which has a solution that outputs the optimal times a transfer should happen.

What I've Tried

I've tried solving it using the compound interest formula, but got stuck at the point where the money gets transferred from one account to another, because calculating $\text{secondAmountAndInterest}$ yields incorrect results. I tried to make the calculation so it's transferring the money from one account into another (that's why I subtracted $B$ from $\text{firstAmountAndInterest}$ when calculating $\text{secondAmountAndInterest}$). Here's what I've tried:

Initial balance in USD: $B$ = 30000
First APR: $A_1 = 0.005$
Second APR: $A_2 = 0.02$
Transfer fee in USD: $T = 0.5$

\begin{align}
\text{firstAmountAndInterest} & = B \times \left(\frac {1+A_1} x\right) ^ x \\
\text{secondAmountAndInterest} & = (\text{firstAmountAndInterest} – B) \times \left(\frac {1+A_2} x\right) ^ x \\
y & = B-\text{secondAmountAndInterest} – x \times T
\end{align}

Here's a Python script I wrote that calculates the formula's maximum:

import scipy
from scipy import optimize


def f(x):
    balance_in_usd = 30000
    first_apr = 0.005
    second_apr = 0.02
    transfer_fee_in_usd = 0.5

    if x == 0:
        return 0

    first_amount_and_interest = balance_in_usd * (1 + first_apr / x) ** x
    second_amount_and_interest = (first_amount_and_interest - balance_in_usd) * (1 + second_apr / x) ** x

    return balance_in_usd + second_amount_and_interest - x * transfer_fee_in_usd


max_x = scipy.optimize.fmin(lambda x: -f(x), 0)

print("Frequency or no. of times you have to move funds annually:", max_x[0])
print("After how many days you have to move funds:", 365.25 / max_x[0])
print("After how many years you have to move funds:", 1 / max_x[0])

Output:

Optimization terminated successfully.
         Current function value: -30152.504308
         Iterations: 25
         Function evaluations: 50
Frequency or no. of times you have to move funds annually: 0.9070000000000009
After how many days you have to move funds: 402.70121278941525
After how many years you have to move funds: 1.1025358324145524

I've successfully calculated how often to compound fees when there is only one account, here's that as well. Somehow, I need to modify this so that it handles Account B as well.

Initial balance in USD: $B$ = 30000
First APR: $A_1 = 0.005$
Transfer fee in USD: $T = 0.5$

$$
y = B \times \left(\frac {1 + A_1} x\right)^x – x \times T
$$

Best Answer

With interest being paid "every minute" it would be accurate to use the continuous compounding model. Let's do some basic calculations for the case in which the time horizon is one year, and we make no transfers.

Continuous compounding says that the $30,000 principal in account A will become:

$$ 30000 \exp(0.005) = 30150.375625782 $$

while a more literal minute-by-minute compounding gives:

$$ 30000 \left(1 + \frac{0.005}{525600}\right)^{525600} = 30150.375624331 $$

This difference is tiny relative to the $0.50 cost of transfers, so we accept the continuous compounding formula for the sake of simplicity.

This computation also shows that at most 300 transfers from account A to account B could be done (in the one-year time interval), neglecting the possibility to use funds accruing in account B for such costs (they would certainly be counterproductive to maximizing profit).

This takes care of the case of not doing any transfers. The number of transfers is discrete, a value between $0$ and $300$. So instead of trying to model the "frequency" of transfers as a real number, we should explore the effect of doing a smallish number of transfers. The timing of transfers need not be periodic.

Let's begin with the case of one transfer at time $t_1$ during the year interval. The earliest we could make $t_1$ would be the point at which an accrued interest in account A reaches the transfer cost. That's clearly not optimal as nothing will actually be deposited in account B, so the profit will be less than leaving all the funds in account A until the end of the year, at which point the transfer if done at $t_1 = 1$ simply reduces the profit calculated above for no transfers by the transfer cost.

So we expect the optimal value of $t_1$ will occur between those extremes. An expression can now be given:

$$ \left[30000 \left(\exp(0.005 t_1)-1 \right) - 0.5 \right] \exp(0.02(1-t_1)) + 30000 \left(\exp(0.005 (1-t_1)) \right) $$

for the monies transferred from account A to account B at time $t_1$, there accruing interest at the higher rate for the remaining time $1-t_1$, plus the monies left in account A that accrue the lower rate of interest over that time. This expression includes the original deposit of $30,000 as is consistent with the earlier calculations without transfers.

I used a spreadsheet to isolate which $t_1$ maximizes the profit, and within the limited precision of that, the best value of $t_1$ is very near $0.5$. It gives an improvement (over no transfer) to $30150.43734 (so about a six cent increase).

Plan of Attack

I suspect the one transfer case, suitably generalized, admits a closed form solution, and this may allow us to solve multiple transfer problems by a dynamic programming approach. So we begin by polishing the one transfer case.

Related Question