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 $$