【问题标题】:formula to find for basic calculations of common loan types such as mortgages, auto loans, student loans, or personal loans用于计算常见贷款类型(如抵押贷款、汽车贷款、学生贷款或个人贷款)的基本计算公式
【发布时间】:2019-03-28 06:12:54
【问题描述】:

我正在尝试按照随附的屏幕截图计算 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)

所以我想要精确的输出作为附加的屏幕截图,那么任何人都可以帮助我使用此代码找出公式吗?提前致谢!

【问题讨论】:

    标签: php formula


    【解决方案1】:

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

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      • 2020-12-13
      • 1970-01-01
      • 2013-06-10
      相关资源
      最近更新 更多