Created
January 22, 2013 23:29
-
-
Save ghalimi/4599848 to your computer and use it in GitHub Desktop.
MIRR 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 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