如何计算达到一定数量的储蓄帐户所需的每月付款?

时间:2020-07-23 13:16:51

标签: javascript math javascript-framework

考虑到年利率,储蓄起始金额,最终金额和增长时间,我正在尝试使用Javascript获取储蓄帐户中一定数量资金所需的每月付款。这是一个示例:

PV=1000
FV=10000
Nper = 5 * 12 = 60
Rate = 1% /12 = 0.0083%

答案是$145.51,但我尝试的每个公式给出的结果都不相同。在excel上,它的用法如下:PMT(0.083%,60,1000,-10000),我尝试了以下操作:

var pv = 1000;
var fv = -10000;
var i = 0.01 / 12;
var n = 60;

function payment() {
  return (pv - fv) * (i) / (1 - (Math.pow(1 + i, -n)));
}

这没有给出所需的答案。这给了我188.03而不是145.51。知道为什么吗?这不是正确的方程式吗?谢谢!

1 个答案:

答案 0 :(得分:1)

这是PMT的正确方程式。我添加了快速集成以进行验证。来源:https://gist.github.com/maarten00/23400873d51bf2ec4eeb

const pv = 1000;
const fv = -10000;
const i = 0.01 / 12;
const n = 60;

function pmt(rate_per_period, number_of_payments, present_value, future_value, type){
    future_value = typeof future_value !== 'undefined' ? future_value : 0;
    type = typeof type !== 'undefined' ? type : 0;

    if(rate_per_period != 0.0){
        // Interest rate exists
        var q = Math.pow(1 + rate_per_period, number_of_payments);
        return -(rate_per_period * (future_value + (q * present_value))) / ((-1 + q) * (1 + rate_per_period * (type)));

    } else if(number_of_payments != 0.0){
        // No interest rate, but number of payments exists
        return -(future_value + present_value) / number_of_payments;
    }

    return 0;
}

document.getElementById("showPayment").innerHTML = pmt(i, n, pv, fv);
<div class="showPayment" id="showPayment">

</div>

相关问题