34 $rslt = self::xirrPart1(
$values, $dates);
43 $f1 = self::xnpvOrdered($x1,
$values, $dates,
false);
44 $f2 = self::xnpvOrdered($x2,
$values, $dates,
false);
46 for (
$i = 0;
$i < self::FINANCIAL_MAX_ITERATIONS; ++
$i) {
47 if (!is_numeric($f1) || !is_numeric($f2)) {
50 if (($f1 * $f2) < 0.0) {
54 } elseif (abs($f1) < abs($f2)) {
55 $f1 = self::xnpvOrdered($x1 += 1.6 * ($x1 - $x2),
$values, $dates,
false);
57 $f2 = self::xnpvOrdered($x2 += 1.6 * ($x2 - $x1),
$values, $dates,
false);
64 return self::xirrPart3(
$values, $dates, $x1, $x2);
91 return self::xnpvOrdered($rate,
$values, $dates,
true);
101 if ((!is_array(
$values)) && (!is_array($dates))) {
106 if (count(
$values) != count($dates)) {
110 $datesCount = count($dates);
111 for (
$i = 0;
$i < $datesCount; ++
$i) {
115 return $e->getMessage();
119 return self::xirrPart2(
$values);
127 for (
$i = 0;
$i < $valCount; ++
$i) {
129 if (!is_numeric($fld)) {
131 } elseif ($fld > 0) {
133 } elseif ($fld < 0) {
137 if (!self::bothNegAndPos($foundneg, $foundpos)) {
146 $f = self::xnpvOrdered($x1,
$values, $dates,
false);
156 for (
$i = 0;
$i < self::FINANCIAL_MAX_ITERATIONS; ++
$i) {
159 $f_mid = self::xnpvOrdered($x_mid,
$values, $dates,
false);
163 if ((abs($f_mid) < self::FINANCIAL_PRECISION) || (abs($dx) < self::FINANCIAL_PRECISION)) {
181 self::validateXnpv($rate,
$values, $dates);
184 return $e->getMessage();
188 for (
$i = 0;
$i < $valCount; ++
$i) {
196 return $e->getMessage();
198 if ($date0 > $datei) {
203 if (!is_numeric($dif)) {
206 $xnpv +=
$values[
$i] / (1 + $rate) ** ($dif / 365);
214 if (!is_numeric($rate)) {
218 if ($valCount != count($dates)) {
221 if ($valCount > 1 && ((min(
$values) > 0) || (max(
$values) < 0))) {
static bothNegAndPos($neg, $pos)
static validateXnpv($rate, $values, $dates)
static xirrPart1(&$values, &$dates)
static interval($startDate, $endDate, $unit='D')
DATEDIF.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static xirrPart3($values, $dates, $x1, $x2)
static presentValue($rate, $values, $dates)
XNPV.
const FINANCIAL_MAX_ITERATIONS
static rate($values, $dates, $guess=0.1)
XIRR.
static getDateValue($dateValue, bool $allowBool=true)
getDateValue.
const FINANCIAL_PRECISION
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static xirrPart2(&$values)
static xnpvOrdered($rate, $values, $dates, $ordered=true)