Loan Amortization Schedule Calculator
This calculator helps you understand how your loan payments are broken down over time, showing how much goes towards principal and interest for each payment. Understanding your amortization schedule is crucial for managing debt effectively and planning your financial future.
.calculator-container {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 5px;
font-weight: bold;
}
input[type="number"], select {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
grid-column: 1 / -1; /* Span across all columns */
margin-top: 10px;
}
button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 20px;
overflow-x: auto; /* Allows horizontal scrolling for wide tables */
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: right;
}
th {
background-color: #e9e9e9;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
td:first-child, th:first-child {
text-align: left;
}
function calculateAmortization() {
var loanAmount = parseFloat(document.getElementById("loanAmount").value);
var annualInterestRate = parseFloat(document.getElementById("annualInterestRate").value);
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var paymentFrequency = parseInt(document.getElementById("paymentFrequency").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(loanAmount) || isNaN(annualInterestRate) || isNaN(loanTermYears) || isNaN(paymentFrequency) || loanAmount <= 0 || annualInterestRate < 0 || loanTermYears <= 0 || paymentFrequency <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
var monthlyInterestRate = (annualInterestRate / 100) / paymentFrequency;
var numberOfPayments = loanTermYears * paymentFrequency;
var monthlyPayment = (loanAmount * monthlyInterestRate) / (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments));
if (isNaN(monthlyPayment) || !isFinite(monthlyPayment)) {
resultDiv.innerHTML = "Calculation error. Please check your inputs.";
return;
}
var amortizationTable = "
Loan Amortization Schedule
";
amortizationTable += "
";
amortizationTable += "";
amortizationTable += "| Payment # | Payment Date | Starting Balance | Payment | Interest Paid | Principal Paid | Ending Balance |
";
amortizationTable += "";
amortizationTable += "";
var currentBalance = loanAmount;
var totalInterestPaid = 0;
var totalPrincipalPaid = 0;
for (var i = 1; i <= numberOfPayments; i++) {
var interestPayment = currentBalance * monthlyInterestRate;
var principalPayment = monthlyPayment – interestPayment;
// Adjust last payment to account for rounding
if (i === numberOfPayments) {
principalPayment = currentBalance;
monthlyPayment = interestPayment + principalPayment;
}
currentBalance -= principalPayment;
totalInterestPaid += interestPayment;
totalPrincipalPaid += principalPayment;
// Format date (simple representation, could be more complex)
var paymentDate = new Date();
paymentDate.setMonth(paymentDate.getMonth() + i -1); // This is a simplification for demonstration
var formattedDate = (paymentDate.getMonth() + 1) + "/" + paymentDate.getDate() + "/" + paymentDate.getFullYear();
amortizationTable += "";
amortizationTable += "| " + i + " | ";
amortizationTable += "" + formattedDate + " | ";
amortizationTable += "$" + (loanAmount – totalPrincipalPaid + principalPayment).toFixed(2) + " | "; // Starting balance for this row
amortizationTable += "$" + monthlyPayment.toFixed(2) + " | ";
amortizationTable += "$" + interestPayment.toFixed(2) + " | ";
amortizationTable += "$" + principalPayment.toFixed(2) + " | ";
amortizationTable += "$" + Math.max(0, currentBalance).toFixed(2) + " | "; // Ensure ending balance is not negative
amortizationTable += "
";
}
amortizationTable += "";
amortizationTable += "
";
amortizationTable += "
Summary
";
amortizationTable += "
Total Payments: $" + (monthlyPayment * numberOfPayments).toFixed(2) + "";
amortizationTable += "
Total Principal Paid: $" + totalPrincipalPaid.toFixed(2) + "";
amortizationTable += "
Total Interest Paid: $" + totalInterestPaid.toFixed(2) + "";
resultDiv.innerHTML = amortizationTable;
}