Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 30, 2013 02:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghalimi/4670010 to your computer and use it in GitHub Desktop.
Save ghalimi/4670010 to your computer and use it in GitHub Desktop.
XNPV Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function XNPV(rate, values, dates) {
var result = 0;
for (var i = 0; i < values.length; i++) {
result += values[i] / Math.pow(1 + rate, moment(dates[i]).diff(moment(dates[0]), 'days') / 365);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment