# How do I calculate Compound Interest with changing monthly contributions, quarterly contributions, and changing interest rate

John currently has \$100 in a saving account that compounds quarterly at a .25% interest rate. When the account's balance reaches \$2500 or more, the interest rate will change to .05%. I want to figure out what John's balance will be in 7 years. During the first year, each month, he'll deposit \$20 to his savings account, Except for six months where he'll deposit an additional \$150 that he earns from a paid internship. John is also considering investing in the stock market, and he'd like to deposit any money that he gains from quarterly dividends into his account. From the second year onwards, he won't make any more contributions to his account. I tried modeling this problem using the traditional future value formula, which is as follows:

``````A = P(1+r/n)^(nt) + PMT((((1+r/n)^(nt))-1)/(r/n))
``````

In this formula, "A" is the future value, "P" is the principal, "r" is the interest rate, "n" is the number of times account is compounded each year, "t" is the time (in years), and "PMT" is the amount of money contributed each month. Unfortunately, this formula only accounts for constant monthly contributions. Is there a variation of the future value formula that takes quarterly and changing monthly contributions into account? Bonus points for anyone who can find an equation that models the changing interest rate when John's balance reaches \$2500 or more.

• Any reason not to write a program as you have a number of conditionals? Formulas are for "idealized" states, as you add conditionals you are probably better off modeling it in code (see history of tech in banking). Aug 25, 2021 at 15:47
• In such a situation, I'd use a spreadsheet with one line for each deposit. Aug 25, 2021 at 16:04
• @MorrisonChang Thank you for you're answer! I actually tried to create an algorithm to calculate the future value formula that I mentioned above, but it couldn't calculate monthly contributions correctly? Do you happen to know of any good algorithms for this purpose? Aug 25, 2021 at 17:18