Loan Repayment Calculator with Offset Account

Loan Repayment Calculator with Offset Account

Not calculated yet.

let calculationSteps = “”; const currencySymbol = “$”, fixedCurrency = “USD”; function calculateRepayment() { calculationSteps = “”; const loanAmount = parseFloat(document.getElementById(“loanAmount”).value); const interestRate = parseFloat(document.getElementById(“interestRate”).value) / 100 / 12; const loanTerm = parseFloat(document.getElementById(“loanTerm”).value) * 12; const offsetBalance = parseFloat(document.getElementById(“offsetBalance”).value); if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || isNaN(offsetBalance) || loanAmount <= 0 || interestRate <= 0 || loanTerm <= 0) { alert("Please enter valid positive values for all fields."); return; } const effectiveLoanAmount = loanAmount – offsetBalance; const monthlyRepayment = (effectiveLoanAmount * interestRate * Math.pow(1 + interestRate, loanTerm)) / (Math.pow(1 + interestRate, loanTerm) – 1); document.getElementById("monthlyRepayment").value = formatCurrency(monthlyRepayment); calculationSteps += `Inputs:
Loan Amount: ${formatCurrency(loanAmount)}
Offset Account Balance: ${formatCurrency(offsetBalance)}
Interest Rate: ${(interestRate * 12 * 100).toFixed(2)}%
Loan Term: ${loanTerm / 12} years

`; calculationSteps += `Formulas:
Effective Loan Amount = Loan Amount – Offset Account Balance
Monthly Repayment = (Effective Loan Amount × Interest Rate × (1 + Interest Rate)^Term) / ((1 + Interest Rate)^Term – 1)

`; calculationSteps += `Result:
Monthly Repayment: ${formatCurrency(monthlyRepayment)}
`; if (document.getElementById(“calculationSteps”).style.display === “block”) { document.getElementById(“calculationSteps”).innerHTML = calculationSteps; } } function resetCalculator() { document.querySelectorAll(“.loan-repayment-calculator input”).forEach(el => el.value = “”); calculationSteps = “”; document.getElementById(“calculationSteps”).innerHTML = “

Not calculated yet.

“; } function toggleCalculationSteps() { const steps = document.getElementById(“calculationSteps”); const arrow = document.getElementById(“toggleArrow”); if (steps.style.display === “none” || steps.style.display === “”) { steps.style.display = “block”; arrow.style.transform = “rotate(180deg)”; steps.innerHTML = calculationSteps || “

Not calculated yet.

“; } else { steps.style.display = “none”; arrow.style.transform = “rotate(0deg)”; } } function formatCurrency(n) { return currencySymbol + n.toFixed(2) + ” ” + fixedCurrency; }

Leave a Reply

Your email address will not be published. Required fields are marked *