首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于常见贷款类型基本计算的公式,如抵押贷款、汽车贷款、学生贷款或个人贷款

用于常见贷款类型基本计算的公式,如抵押贷款、汽车贷款、学生贷款或个人贷款
EN

Stack Overflow用户
提问于 2019-03-28 14:12:54
回答 1查看 46关注 0票数 0

我正在尝试计算EMI根据附加的屏幕截图。但在我的计算中有一个很小的差异。到目前为止,我所做的工作如下:

代码语言:javascript
复制
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)

所以我想要一个准确的输出作为一个附加的屏幕截图,所以有人可以帮助我与此代码找出公式?提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-01 21:05:34

经过几天的研究,我得到了如下解决方案:

代码语言:javascript
复制
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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55391169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档