Skip to content

Instantly share code, notes, and snippets.

@mariusbutuc
Forked from ghalimi/PV.js
Created August 31, 2017 21:20
Show Gist options
  • Save mariusbutuc/5786c92ad8daab142a14efe82e312bc4 to your computer and use it in GitHub Desktop.
Save mariusbutuc/5786c92ad8daab142a14efe82e312bc4 to your computer and use it in GitHub Desktop.
PV Function
// 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