Created
August 2, 2017 15:41
-
-
Save brunokunace/b2ecfea7b3a145a50ce52c86267221cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pmt(rate_per_period, number_of_payments, present_value, future_value, type){ | |
future_value = typeof future_value !== 'undefined' ? future_value : 0; | |
type = typeof type !== 'undefined' ? type : 0; | |
if(rate_per_period != 0.0){ | |
// Interest rate exists | |
var q = Math.pow(1 + rate_per_period, number_of_payments); | |
return -(rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type))); | |
} else if(number_of_payments != 0.0){ | |
// No interest rate, but number of payments exists | |
return -(future_value + present_value) / number_of_payments; | |
} | |
return 0; | |
} | |
console.log(pmt(0.08,6,-1.08,0,1)) //0.21631538622900973 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment