Skip to content

Instantly share code, notes, and snippets.

@dchenk
Created April 27, 2020 01:17
Show Gist options
  • Save dchenk/559c71e450e074408937142855f7b1bb to your computer and use it in GitHub Desktop.
Save dchenk/559c71e450e074408937142855f7b1bb to your computer and use it in GitHub Desktop.
// totalCostOverMonths returns the total cost of an amortizing loan given a fixed APR.
const totalCostOverMonths = (
p, /* The principal borrowed */
r, /* The APR / 1200 if APR is taken as a percentage; e.g., with APR of 9%, r = 9/1200 = 0.0075 */
m /* The number of months the mortgage is held for; the number of payments */
) => p * r * m / (1 - Math.pow(1 + r, -m)) - p;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment