Installment Debt Data Calculation with Algorithm for Interest Rate
This tool is used to calculate installment debt related data:
Choose Item to be Calculated:
Loan Amount
Monthly Payment
Monthly Payment:
dollar(s)
Duration:
year(s)
Annual Interest Rate:
%
Loan Amount:
dollar(s)
dollar(s)
Duration:
year(s)
Annual Interest Rate:
%
Loan Amount:
dollar(s)
| Term | Principal Paid | Interest | Remaining Debt |
|---|
Algorithm for Interest Rate
Of all 4 items of installment debt calculation, loan amount, duration in month, annual interest rate and monthly payment, only the annual interest rate can not be derived by knowing the other 3. By looking at this formula, we just can't single out "r" and to calculate.
Solution
To calculate annual interest rate for the present value of an annuity, we use a method that is similar to binary search. Starting with an interes rate and calculate the monthly payment, since we kwow all the other variables. Then we compare the first result to the already-known monthly payment. If the result is bigger we substrate the strating interest rate by some number which is divide by2, and add it other wise.
startrate = 10;
gap = 10;
//this is the to-add or to-subtract to the startrate if the
//result monthly payment is bigger or smaller than the target.
monthlystartrate = startrate/1200;
tryout = loanamount*monthlystartrate/(1-1/(Math.pow(1+monthlystartrate,duration*12)));
//tryout is the approximated monthly payment based on guessed rate.
diff = tryout - monthlypayment;
do {
if(diff > 0.1){
gap = gap/2
startrate = startrate - gap;
monthlystartrate = startrate/1200;
tryout = loanamount*monthlystartrate/(1-1/(Math.pow(1+monthlystartrate,duration*12)));
diff = tryout - monthlypayment;
}else if(diff < -0.1){
startrate = startrate + gap;
monthlystartrate = startrate/1200;
tryout = loanamount*monthlystartrate/(1-1/(Math.pow(1+monthlystartrate,duration*12)));
diff = tryout - monthlypayment;
}else{
diff = tryout - monthlypayment;
}
}while(Math.abs(diff) > .1)
Comments
Post a Comment