You are here

public static function PHPExcel_Calculation_Financial::MIRR in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php \PHPExcel_Calculation_Financial::MIRR()

* MIRR * * Returns the modified internal rate of return for a series of periodic cash flows. MIRR considers both * the cost of the investment and the interest received on reinvestment of cash. * * Excel Function: * MIRR(values,finance_rate, reinvestment_rate) * *

Parameters

float[] $values An array or a reference to cells that contain a series of payments and: * income occurring at regular intervals. * Payments are negative value, income is positive values. * @param float $finance_rate The interest rate you pay on the money used in the cash flows * @param float $reinvestment_rate The interest rate you receive on the cash flows as you reinvest them * @return float

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php, line 1435

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function MIRR($values, $finance_rate, $reinvestment_rate) {
  if (!is_array($values)) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $values = PHPExcel_Calculation_Functions::flattenArray($values);
  $finance_rate = PHPExcel_Calculation_Functions::flattenSingleValue($finance_rate);
  $reinvestment_rate = PHPExcel_Calculation_Functions::flattenSingleValue($reinvestment_rate);
  $n = count($values);
  $rr = 1.0 + $reinvestment_rate;
  $fr = 1.0 + $finance_rate;
  $npv_pos = $npv_neg = 0.0;
  foreach ($values as $i => $v) {
    if ($v >= 0) {
      $npv_pos += $v / pow($rr, $i);
    }
    else {
      $npv_neg += $v / pow($fr, $i);
    }
  }
  if ($npv_neg == 0 || $npv_pos == 0 || $reinvestment_rate <= -1) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $mirr = pow(-$npv_pos * pow($rr, $n) / ($npv_neg * $rr), 1.0 / ($n - 1)) - 1.0;
  return is_finite($mirr) ? $mirr : PHPExcel_Calculation_Functions::VALUE();
}