Home > Back-end >  Calculating compound interest while underlying interest rate is increasing at a constant rate
Calculating compound interest while underlying interest rate is increasing at a constant rate

Time:11-29

Question:
How do I calculate the compound interest when the underlying interest rate is also increasing by a constant growth rate (e.g. 10%) annually?

Example:
$1000, interest rate 5% annually, for a period of 5 years.
This how I would calculate the compound interest:
Compound Interest
let principal = 1000;
let n = 1;
let t = 5;
let rate = 10;
let r = rate/100;
let compoundInterest = principal*Math.pow((1 r/n),nt);

But now I actually want the rate itself to increase by 10% each year after the first year has passed.
First year: 5%
Second year: 5% (5 * 0,1) = 5,5%
Third year: 5,5% (5,5 * 0,1) = 6,05%

CodePudding user response:

Given the starting conditions:

let startingPrincipal = 1000;
let numberOfYears = 5;
let startingRate = 10;
let rateIncreaseRate = 10;

You can calculate the interest yearly for each of the years, feeding it the updated balance, and new interest rate. I simplified the formula since you have yearly compounding and the calculation for each period is just 1. Let me know if you want to be able to compound differently within the year.

let yearlyInterest = startingRate;
let currentBalance = startingPrincipal;
for (let i = 0; i < numberOfYears; i  ) {
    currentBalance *= 1   yearlyInterest / 100;
    yearlyInterest *= 1   rateIncreaseRate / 100;
}

console.log(currentBalance);

Output:

1777.9906868317107

Which you can round or trunc as needed by your requirements.

  • Related