我遇到了一个滑块计算器,它基本上是用来帮助用户计算出贷款的百分比利率。经过多次挠头,我的原始工作状态良好,经过计算,但我一定是侥幸。我需要它来计算利率或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
});
看起来你在问如何计算利率?公式为
i=n(eln(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
===编辑===
我必须道歉,这不是正确的实际利率。请忽略这个答案,看看我的另一个答案。
每个还款期复利一次的贷款当前余额的通用公式是
Ln=Ln-1(1+R)-p
其中Ln是n次付款后的余额(L0为原始贷款金额)R是每月定期利率,P是每月付款金额。
在最后一次付款后,余额将为0,因此,如果我们从那里开始,用上面的等式代替所有付款并简化,则公式为
L0(1+R)n-p((1+R
现在,如果你碰巧是一个数学天才,请随意为R求解。我能想到的最好的是
R=p/(p-RL0)1/n-1
由于RL0是第一期的利息支付,它必须小于支付金额,因此如果我们从一半的支付金额开始,步长为支付金额的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%