This calculator helps you estimate the maximum mortgage amount you can afford based on your income, debts, and desired monthly payment. Understanding your affordability is a crucial first step in the home-buying process.
function calculateMortgageAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var monthlyDebtPayments = parseFloat(document.getElementById("monthlyDebtPayments").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value) / 100; // Annual rate
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var propertyTaxesRate = parseFloat(document.getElementById("propertyTaxes").value) / 100; // Annual rate
var homeInsurance = parseFloat(document.getElementById("homeInsurance").value);
var pmiRate = parseFloat(document.getElementById("pmi").value) / 100; // Annual rate
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(grossMonthlyIncome) || isNaN(monthlyDebtPayments) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTermYears) || isNaN(propertyTaxesRate) || isNaN(homeInsurance) || isNaN(pmiRate)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Lender typically allows a Debt-to-Income (DTI) ratio of around 28% for housing and 36% total
// We'll use a conservative approach here, aiming for a total DTI that allows for affordability.
// A common guideline is that your total housing costs (PITI) plus other debts shouldn't exceed 36%-45% of gross income.
// Let's assume a maximum total debt payment (housing + other debts) of 40% of gross monthly income.
var maxTotalMonthlyPayment = grossMonthlyIncome * 0.40;
var maxHousingPayment = maxTotalMonthlyPayment – monthlyDebtPayments;
if (maxHousingPayment <= 0) {
resultDiv.innerHTML = "Based on your existing debts and income, your maximum affordable housing payment is too low to qualify for a mortgage in most cases.";
return;
}
// Calculate monthly property taxes, homeowner's insurance, and PMI based on an estimated home value.
// This is iterative because property taxes and PMI depend on the loan amount (and thus home value).
// We'll make an initial guess for the loan amount to estimate these and refine.
var estimatedHomeValue = downPayment + 100000; // Initial guess for home value
var monthlyPropertyTaxes = (estimatedHomeValue * propertyTaxesRate) / 12;
var monthlyPMI = (estimatedHomeValue * pmiRate) / 12; // PMI is on loan amount, but often estimated on home value initially
var monthlyPrincipalAndInterest = maxHousingPayment – monthlyPropertyTaxes – homeInsurance – monthlyPMI;
if (monthlyPrincipalAndInterest 0) {
maxLoanAmount = monthlyPrincipalAndInterest * (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)) / monthlyInterestRate;
} else {
maxLoanAmount = monthlyPrincipalAndInterest * numberOfPayments;
}
// Recalculate PMI based on the actual loan amount
var actualLoanAmount = maxLoanAmount;
var actualMonthlyPMI = (actualLoanAmount * pmiRate) / 12;
// Re-evaluate maximum housing payment with actual PMI
var updatedMaxHousingPayment = maxHousingPayment – actualMonthlyPMI;
if (updatedMaxHousingPayment <= maxHousingPayment – monthlyPMI) {
// PMI significantly changed the affordability, recalculate loan amount
monthlyPrincipalAndInterest = updatedMaxHousingPayment – monthlyPropertyTaxes – homeInsurance;
if (monthlyPrincipalAndInterest 0) {
maxLoanAmount = monthlyPrincipalAndInterest * (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)) / monthlyInterestRate;
} else {
maxLoanAmount = monthlyPrincipalAndInterest * numberOfPayments;
}
}
var affordableHomePrice = maxLoanAmount + downPayment;
// Display results
resultDiv.innerHTML += "