【问题标题】:how to calculate excel pmt using php如何使用php计算excel pmt
【发布时间】:2015-06-27 11:31:57
【问题描述】:

一直在尝试将excel中使用的pmt函数实现到php中。我有公式,但计算显示不正确。

30年期6%的利率,终值为833333。

正确答案应该是 10,541。

付款应在期末到期,因此类型为零,现值为零。

<pre>
    $pv = 0;
    $fv = 833333;
    $i = 0.06/12;
    $n = 360;

    $pmt = (($pv - $fv) * $i )/ (1 - pow((1 + $i), (-$n))); 

    echo $pmt;
</pre>

Using this link as reference for formula

【问题讨论】:

  • 通过 MS Excel 本身 (=PMT(6%/12, 360, 0, 833333, 0)) 运行您的值给我的结果是 829.59
  • pmt 应该是 =PMT(0.06,30,0,833333,0)
  • 0.06 != 6%/12360 != 30....所以您在公式中使用的值不正确

标签: php html excel


【解决方案1】:

我在 PHPExcel 中用来反映 MS Excel 公式的公式是:

$PMT = (-$fv - $pv * pow(1 + $rate, $nper)) /
    (1 + $rate * $type) /
    ((pow(1 + $rate, $nper) - 1) / $rate);

在哪里

  • $rate = 利率
  • $nper = 周期数
  • $fv 是未来值
  • $pv 是现值
  • $type 是类型

当我使用时返回与 MS Excel 相同的结果

=PMT(6%/12, 360, 0, 833333, 0)

当我使用时,它会返回 -10540.755358736(与 MS Excel 相同)的结果

=PMT(0.06,30,0,833333,0)

【讨论】:

    【解决方案2】:

    更清洁的解决方案如下。

    * @param float $apr   Interest rate.
    * @param integer $term  Loan length in years. 
    * @param float $loan   The loan amount.
    
    function calPMT($apr, $term, $loan)
    {
      $term = $term * 12;
      $apr = $apr / 1200;
      $amount = $apr * -$loan * pow((1 + $apr), $term) / (1 - pow((1 + $apr), $term));
      return round($amount);
    }
    
    function loanEMI()
    {
     echo $this->calPMT(16, 1, 1020000);
    }
    

    这将为您提供与 MS Excel 中一样的精确 PMT。

    来源: https://drastikbydesign.com/blog-entry/excel-pmt-php-cleaner

    【讨论】:

    • 一直在研究这个问题。我如何合并像每周和双周这样的可变频率?
    【解决方案3】:

    这是我遇到的另一个。将来可能对某人有用。

    $pv = 0;
    $fv = 833333;
    $i = 0.06;
    $n = 30;
    $pmt = ((($pv *( pow((1+$i), $n)  )) + $fv) * $i ) / (1 - ( pow((1+$i), $n) ));
    echo $pmt;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多