Understanding how much house you can afford is a crucial first step in the home-buying process. This mortgage affordability calculator helps you estimate the maximum mortgage loan you might qualify for based on your income, debts, and estimated interest rates. Remember, this is an estimate, and your actual borrowing capacity will be determined by lenders after a full financial assessment.
function calculateAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var estimatedInterestRate = parseFloat(document.getElementById("estimatedInterestRate").value);
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var currentMonthlyDebt = parseFloat(document.getElementById("currentMonthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Input validation
if (isNaN(grossMonthlyIncome) || grossMonthlyIncome <= 0 ||
isNaN(estimatedInterestRate) || estimatedInterestRate <= 0 ||
isNaN(loanTermYears) || loanTermYears <= 0 ||
isNaN(currentMonthlyDebt) || currentMonthlyDebt < 0 ||
isNaN(downPayment) || downPayment < 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Lender's typical debt-to-income (DTI) ratio limits
// Front-end DTI (housing costs) and Back-end DTI (all debts)
// We'll aim for a conservative back-end DTI of around 43% (including PITI)
var maxBackEndDTI = 0.43;
// Calculate maximum total monthly debt payment allowed
var maxTotalMonthlyDebt = grossMonthlyIncome * maxBackEndDTI;
// Calculate how much is available for mortgage PITI (Principal, Interest, Taxes, Insurance)
var maxPITI = maxTotalMonthlyDebt – currentMonthlyDebt;
if (maxPITI 0) {
maxLoanAmount = maxPITI * (Math.pow(1 + monthlyInterestRate, loanTermMonths) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, loanTermMonths));
} else {
// Handle case of 0% interest rate (though unlikely for mortgages)
maxLoanAmount = maxPITI * loanTermMonths;
}
// The result of the formula above is the maximum loan principal.
// The total affordable home price is the loan amount plus the down payment.
var affordableHomePrice = maxLoanAmount + downPayment;
// Display the results
var formattedMaxLoanAmount = maxLoanAmount.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedAffordableHomePrice = affordableHomePrice.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedMaxPITI = maxPITI.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
resultDiv.innerHTML = "