Method Deck / finance

Compound interest

Computes the final amount of a principal that compounds periodically at a fixed nominal annual rate.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Convert the annual rate to a decimal: r = annual_rate_percent / 100.
  2. Periodic rate i = r / compounds_per_year; periods n = compounds_per_year * years.
  3. final_amount = principal * (1 + i) ^ n, rounded to 2 decimals.
  4. interest_earned = final_amount - principal, rounded to 2 decimals.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"principal":1000,"annual_rate_percent":5,"compounds_per_year":12,"years":10}$1,647.01
test vector: annual compounding{"principal":5000,"annual_rate_percent":4,"compounds_per_year":1,"years":5}$6,083.26

Published card