Last active
March 31, 2017 23:19
-
-
Save ghalimi/4597900 to your computer and use it in GitHub Desktop.
NPV Function
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
// Copyright (c) 2012 Sutoiku, Inc. (MIT License) | |
function NPV() { | |
// Cast arguments to array | |
var args = []; | |
for (i = 0; i < arguments.length; i++) { | |
args = args.concat(arguments[i]); | |
} | |
// Lookup rate | |
var rate = args[0]; | |
// Initialize net present value | |
var value = 0; | |
// Loop on all values | |
for (var j = 1; j < args.length; j++) { | |
value += args[j] / Math.pow(1 + rate, j); | |
} | |
// Return net present value | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment