gpt4 book ai didi

PHP IRR(内部 yield )财务函数

转载 作者:行者123 更新时间:2023-12-05 01:18:30 24 4
gpt4 key购买 nike

如何在 PHP 中实现 MS Excel 的“IRR()”公式?

我尝试了this page中提到的算法但结果不准确,而且速度非常慢。

最佳答案

经过一段时间的调查,我最终复制了下面的函数。

它基于this question .

function IRR($investment, $flow, $precision = 0.001) {
$min = 0;
$max = 1;
$net_present_value = 1;
while(abs($net_present_value - $investment) > $precision) {
$net_present_value = 0;
$guess = ($min + $max) / 2;
foreach ($flow as $period => $cashflow) {
$net_present_value += $cashflow / (1 + $guess) ** ($period + 1);
}
if ($net_present_value - $investment > 0) {
$min = $guess;
} else {
$max = $guess;
}
}
return $guess * 100;
}

关于PHP IRR(内部 yield )财务函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45246808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com