Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. /**
  2. * Calculates the payment for a loan based on constant payments
  3. * and a constant interest rate.
  4. *
  5. * @param ratePerPeriod - The interest rate for the loan.
  6. * @param numberOfPayments - The total number of payments for the loan.
  7. * @param presentValue - The present value, or the total amount
  8. * that a series of future payments is worth now;
  9. * also known as the principal.
  10. * @param futureValue - The future value, or a cash balance you want
  11. * to attain after the last payment is made.
  12. * If fv is omitted, it is assumed to be 0 (zero), that is,
  13. * the future value of a loan is 0.
  14. * @param type - The number 0 (zero) or 1 and indicates when
  15. * payments are due.
  16. *
  17. * @returns {number}
  18. */
  19. function pmt(ratePerPeriod, numberOfPayments, presentValue, futureValue, type) {
  20. futureValue = typeof futureValue !== 'undefined' ? futureValue : 0;
  21. type = typeof type !== 'undefined' ? type : 0;
  22. if (ratePerPeriod != 0.0) {
  23. var q = Math.pow(1 + ratePerPeriod, numberOfPayments);
  24. return -(ratePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + ratePerPeriod * (type)));
  25. } else if (numberOfPayments != 0.0) {
  26. return -(futureValue + presentValue) / numberOfPayments;
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement