我正在尝试根据所附的屏幕截图计算EMI。但在我的计算上有细微的差别。到目前为止我所做的:
function interest($investment,$year,$rate=15,$n=1){
global $total_result, $total_interest, $totalamount;
$accumulated=0;
if ($year > 1){
$accumulated=interest($investment,$year-1,$rate,$n);
}
$accumulated += $investment;
$rateC = $rate / 100;
$result = $rateC / 12 * pow(1 + ($rateC) / 12, ($year * 12)) / (pow(1 + ($rateC) / 12, ($year * 12)) - 1) * $accumulated;
$result = 85.60;
for ($i=0; $i < 12; $i++) {
// echo round($accumulated,2).'<br>';
$accumulated = $accumulated * pow(1 + $rate/(100 * $n),$n);
$innntrest = ($accumulated - $investment) / 12;
$i_result = $result - $innntrest;
$accumulated = $investment - $i_result;
$investment = $accumulated;
echo '<br>***'.round($result,2).'***'.round($i_result,2).'***'.round($innntrest,2).'<br>';
$total_result = $total_result + round($result,2);
$total_interest = $total_interest + $i_result;
$totalamount = $totalamount + $innntrest;
}
return $accumulated;
}
Where $investment=1000(loan amount), $year=1 (loan term), $rate=5%(interest rate), $n=4 (compound)
所以我想要精确的输出作为附件的屏幕截图,所以有人可以通过这段代码帮助我找出公式吗?预先感谢!
答案 0 :(得分:0)
经过几天的研究,我得到了如下解决方案:
function interest($investment,$year,$rate=15,$n=1,$payment_frequency=4){
$accumulated=0;
$accumulated += $investment;
$rateC = $rate / 100;
$total_i = 0;
if($payment_frequency == 1) {
$accumulated = $accumulated * pow(1 + $rate/(100 * $n),$n);
} else {
$rate = pow(1 + ($rateC/$n),($n*($year/($year*$payment_frequency)))) - 1;
$result = ($rate*$accumulated)/(1 - pow((1 + $rate),-($year*$payment_frequency)));
for ($i=0; $i < ($year*$payment_frequency); $i++) {
$accumulated = $accumulated * pow(1 + $rate/(100 * $n),$n);
$innntrest = ($accumulated - $investment) * 100;
$i_result = $result - $innntrest;
$accumulated = $investment - $i_result;
$investment = $accumulated;
$total_i += $innntrest;
}
return $total_i;
}
}