Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 22, 2013 23:29
Show Gist options
  • Save ghalimi/4599848 to your computer and use it in GitHub Desktop.
Save ghalimi/4599848 to your computer and use it in GitHub Desktop.
MIRR Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function MIRR(values, finance_rate, reinvest_rate) {
// Initialize number of values
var n = values.length;
// Lookup payments (negative values) and incomes (positive values)
var payments = [];
var incomes = [];
for (var i = 0; i < n; i++) {
if (values[i] < 0) {
payments.push(values[i]);
} else {
incomes.push(values[i]);
}
}
// Return modified internal rate of return
var num = -NPV(reinvest_rate, incomes) * Math.pow(1 + reinvest_rate, n - 1);
var den = NPV(finance_rate, payments) * (1 + finance_rate);
return Math.pow(num / den, 1 / (n - 1)) - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment