-
-
Save mariusbutuc/5786c92ad8daab142a14efe82e312bc4 to your computer and use it in GitHub Desktop.
PV Function
This file contains hidden or 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
// Copyright (c) 2012 Sutoiku, Inc. (MIT License) | |
function PV(rate, periods, payment, future, type) { | |
// Initialize type | |
var type = (typeof type === 'undefined') ? 0 : type; | |
// Evaluate rate and periods (TODO: replace with secure expression evaluator) | |
rate = eval(rate); | |
periods = eval(periods); | |
// Return present value | |
if (rate === 0) { | |
return - payment * periods - future; | |
} else { | |
return (((1 - Math.pow(1 + rate, periods)) / rate) * payment * (1 +rate * type) - future) / Math.pow(1 + rate, periods); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment