【问题标题】:How to calculate the monthly payment needed to reach a certain amount in savings account?如何计算储蓄账户达到一定金额所需的每月供款?
【发布时间】:2020-11-13 05:41:16
【问题描述】:

考虑到年利率、储蓄起始金额、最终金额以及让它增长的时间,我正在尝试使用 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。知道为什么吗?这不是正确的方程式吗?谢谢!

【问题讨论】:

    标签: javascript math javascript-framework


    【解决方案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>

    【讨论】:

    • Dang 的工作完全符合我的需要,非常感谢!
    • 如果每天复利,你知道如何用它来计算每月还款吗?我尝试将 i 设置为等于 0.01/3650.01/360 但两个答案都相差约 4 美元。
    • 我不熟悉财务计算。你能提供我目前使用的公式和一个我可以比较我的函数的例子吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2021-11-08
    • 1970-01-01
    相关资源
    最近更新 更多