-
-
Save wendylauw/c7a0e27308631fe70007b75a717efccd to your computer and use it in GitHub Desktop.
Revisions
-
ghalimi created this gist
Jan 25, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ // 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); } }