Recently did the project encountered the issue of equal principal and equal principal and interest, if you do not understand the two ways to look at this point or skip the code directly, this code can also be used for the development of mortgage calculator project.
Matching principal and Interest Calculation formula: (loan principal x month rate X (1+ month rate) ^ repayment months)÷((1+ month interest rate) ^ repayment months -1)
Equal principal calculation formula: Monthly Repayment amount = (loan Principal and repayment month) + (principal-accumulated amount of Principal return) x monthly interest rate
Where the ^ symbol represents the exponentiation.
Give an example to explain
Suppose to 10000 yuan as the principal, in the bank loan 10, the benchmark interest rate is 6.65%, compares the two kinds of loan way difference:
Repayment method of equal principal and interest
Monthly interest rate = annual interest Rate ÷12=0.0665÷12=0.005541667
Monthly repayment principal =(10000x0.005541667x (1+0.005541667) ^120)÷((1+0.005541667) ^120-1)=114.3127 yuan
Total repayment 13717.52 yuan
Total interest 37.1752 million yuan
181.4511278796992481203007518797 1.12502104984600E+271 1.005541667^120-1 0.9409241291
Equal principal repayment method:
Monthly Repayment amount = (loan principal and monthly repayment) + (principal-accumulated amount of Principal return) x monthly interest rate
= (10000÷120) + (10000-cumulative amount of principal returned) x0.005541667
The first month repayment 138.75 yuan monthly decreases 0.462 yuan
Total repayment 13352.71 yuan
Interest 3352.71 Yuan
Equal principal and interest
code is as follows |
copy code |
function debx () { $dkm = 240;//number of loan months, 20 is 240 months $dkTotal = 10000;//Total loan $dknl = 0.0515; //Loan annual interest rate $emTotal = $dkTotal * $DKN L/12 * POW (1 + $dknl/12, $dkm)/(POW (1 + $dknl/12, $dkm)-1); Monthly repayment amount $lxTotal = 0;//Total Interest for ($i = 0; $i < $dkm; $i + +) { $lx = $dkTotal * $DKNL/12; //monthly repayment interest $em = $emTotal-$LX; //monthly repayment principal echo "". ($i + 1). "Period", "Principal:", $em, "interest:". $LX, "total:". $emTotal, "<br/>"; $dkTotal = $dkTotal-$em; $lxTotal = $lxTotal + $lx; } Echo "Total interest:". $lxTotal; } |
equal principal
code is as follows |
copy code |
function DEBJ () { $dkm = 240;//loan months, 20 is 240 months $dkTotal = 10000;//Total loans $dknl = 0.0515; //Loan annual interest rate $em = $dkTotal/$dkm;//Monthly repayment principal $lxTotal = 0; Total Interest for ($i = 0; $i < $dkm; $i + +) { $lx = $dkTotal * $DKNL/12;//monthly repayment interest E Cho "First". ($i + 1). "Period", "Principal:", $em, "interest:". $LX, "total:". ($em + $lx), "<br/>"; $dkTotal-= $em; $lxTotal = $lxTotal + $lx; } Echo "Total interest:". $lxTotal; } |