-1

我遇到了一个滑块计算器,它基本上是为了帮助用户计算出按利率百分比计算的贷款付款。经过多次挠头后,我的原始工作正常,这是计算出来的,但我一定是碰巧了。我需要它来计算利率或 199.9%。

有什么帮助吗?

$(function () {
//First Calculator Slider
$("#slider_low").slider({
    range: "min",
    value: 1000,
    min: 500,
    max: 5000,
    step: 500,
    slide: function (event, ui) {
        $("#span_amount").html("£ " + ui.value);
        $("#hdn_span_amount").val(ui.value);
        total();
    }
});
$("#span_amount").html("£ " + $("#slider_low").slider("value"));
$("#hdn_span_amount").val($("#slider_low").slider("value"));
//End First Calculator Slider

//Go by Month
$("#slider_low_secondary").slider({
    range: "min",
    value: 12,
    min: 3,
    max: 36,
    step: 3,
    slide: function (event, ui) {
        $("#months").html(ui.value + " Months");
        $("#hdn_span_month").val(ui.value);
        total();
    }
});
$("#months").html($("#slider_low_secondary").slider("value") + " Months");
$("#hdn_span_month").val($("#slider_low_secondary").slider("value"));
//End Go by Month

total();

//Total 
function total() {
    var amountval = $("#hdn_span_amount").val();
    var monthVal = $("#hdn_span_month").val();
    var interestRate = 0.108;
    var setupfee = 69;
    var interest = parseInt(monthVal * amountval * interestRate);

    //$('#interest').html('�' + interest);
    var totel = parseInt(amountval) + parseInt(interest) + parseInt(setupfee);
    totel = parseInt(totel / monthVal);
    $('#total_amount').html("£ " + (totel.toFixed(0)));
    $('#hdn_total_amount').val((totel.toFixed(0)));
    }
    //End Total
    });
4

2 回答 2

1

看起来你在问如何计算利率?公式是

i = n(e ln(R+1)/n -1)

其中 i 是周期利率,n 是周期数,R 是实际利率。实际利率为:

R = I/L

其中 I 是利息支付总额,L 是原始贷款价值。

您已经计算了interest变量的总利息,因此实际利率为

interest/amountVal

所以你的月利率是

var monthlyRate = monthVal * (Math.exp(Math.log(intest/amountval + 1)/monthVal) - 1) 

乘以 12 得到 APR

===编辑===

我必须道歉,这不是正确的实际利率。请忽略此答案并查看我的其他答案。

于 2013-09-04T20:13:30.193 回答
0

每个还款期复利一次的贷款当前余额的一般公式为

L n = L n-1 (1 + R) - P
其中 L n为 n 次还款后的余额(L 0为原始贷款金额) R 为每月定期利率,P 为每月还款金额。

最后一次付款后,余额将为 0,因此如果我们从那里开始并用上面的等式代替所有付款并简化,则公式为

L 0 (1+R) n - P((1+R) n - 1)/R = 0

现在,如果您碰巧是个数学天才,请随时为 R 解决这个问题。我能想到的最好的方法是

R = P/(P-RL 0 ) 1/n -1

由于 RL 0是第一期利息的支付,它必须小于支付金额,所以如果我们从支付金额的一半开始,步长为支付金额的 1/4,然后迭代,移动估计更接近实际,每次减半,我们应该能够在十几次左右的迭代中得出一个合理的估计。

function calcInterest(loanAmt, monthlyPayment, nPayments) {
    var ipmt = monthlyPayment/2;
    var newstep = ipmt/2;
    var step = 0;
    var i = 100; //set this to a suitable value to prevent infinite loops
    while (newstep > 0.01 && step != newstep && i > 0) { //decrease 0.01 to increase accuracy
      step = newstep;
      if ((ipmt/loanAmt) > (Math.pow(monthlyPayment/(monthlyPayment-ipmt),(1/nPayments)) - 1)) {
          ipmt += step;
      } else {
          ipmt -= step;
      }
      ipmt = Math.round(ipmt*100)/100;
      newstep = Math.round(step/2*100)/100;
      i--;
    }
    // this returns the APR
    // take off the * 12 if you want the monthly periodic rate
    return((Math.pow(monthlyPayment/(monthlyPayment-ipmt),(1/nPayments)) - 1) * 12); 
}

在我的测试中,calcInterest(1000,197,12);返回 1.9880787972304255,约为 198.81%

于 2013-09-06T04:51:00.470 回答