Use this calculator to estimate how much mortgage you might be able to afford based on your income, debts, and down payment.
function calculateMortgageAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var monthlyDebt = parseFloat(document.getElementById("monthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(annualIncome) || isNaN(monthlyDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) ||
annualIncome < 0 || monthlyDebt < 0 || downPayment < 0 || interestRate < 0 || loanTerm <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields. Loan term must be greater than 0.";
return;
}
// Assumptions based on common lending guidelines (these can vary)
// Lender typically allows PITI (Principal, Interest, Taxes, Insurance) to be 28-36% of gross monthly income.
// We'll use 30% as a conservative estimate for maximum housing payment.
var maxHousingPaymentRatio = 0.30;
var estimatedTaxesInsuranceRatio = 0.01; // Assumes 1% of loan value annually for taxes & insurance
var monthlyIncome = annualIncome / 12;
var maxTotalHousingPayment = monthlyIncome * maxHousingPaymentRatio;
var maxOtherDebtPayments = monthlyIncome * 0.43; // Assuming a 43% total debt-to-income ratio is the absolute max
var availableForMortgagePayment = Math.min(maxTotalHousingPayment, maxOtherDebtPayments – monthlyDebt);
if (availableForMortgagePayment < 0) {
resultDiv.innerHTML = "Based on your income and existing debts, you may not qualify for a mortgage at this time.";
return;
}
// Calculate estimated monthly taxes and insurance
// This is a rough estimate and depends heavily on location and property type.
// For this calculator, we'll simplify and assume it's a percentage of the *potential* loan amount,
// which is difficult to know without iterating. A more robust calculator might use a fixed monthly estimate
// or ask for property tax and insurance estimates directly.
// For simplicity here, let's *estimate* the potential loan amount to then estimate PITI.
// This is an iterative problem. A simpler approach is to just estimate P&I and add a buffer.
// Let's assume the availableForMortgagePayment INCLUDES PITI.
// We need to work backward to find the loan amount.
// P&I = M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// Where:
// M = monthly payment (availableForMortgagePayment minus estimated Taxes/Insurance)
// P = principal loan amount (what we want to find)
// i = monthly interest rate (annualRate / 12 / 100)
// n = total number of payments (loanTerm * 12)
var monthlyInterestRate = interestRate / 12 / 100;
var numberOfPayments = loanTerm * 12;
// Let's refine the approach: The 28-36% rule usually applies to PITI (Principal, Interest, Taxes, Insurance).
// So, availableForMortgagePayment is the maximum PITI.
// We need to estimate T&I. A common rough estimate is 1-1.5% of the property value annually.
// Since we don't know property value yet, this is tricky.
// Let's assume the availableForMortgagePayment will cover P&I plus estimated T&I.
// For simplicity, let's try to estimate the maximum P&I by subtracting an arbitrary T&I estimate.
// A more accurate calculator would ask for T&I estimates.
// Simplified approach: Assume the 28-36% rule is for P&I, and add T&I separately.
// Let's assume P&I cannot exceed ~25% of monthly income to leave room for T&I.
var maxPrincipalInterestPayment = monthlyIncome * 0.25; // This is a very rough estimate!
if (maxPrincipalInterestPayment 0) {
principalLoanAmount = maxPrincipalInterestPayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else { // Handle 0% interest rate case
principalLoanAmount = maxPrincipalInterestPayment * numberOfPayments;
}
// Total potential purchase price = loan amount + down payment
var potentialPurchasePrice = principalLoanAmount + downPayment;
// Display results
var formattedPurchasePrice = potentialPurchasePrice.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedLoanAmount = principalLoanAmount.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedDownPayment = downPayment.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
var formattedMaxPrincipalInterest = maxPrincipalInterestPayment.toLocaleString(undefined, { style: 'currency', currency: 'USD' });
resultDiv.innerHTML = "
Estimated Mortgage Affordability
" +
"Based on your inputs, you might be able to afford a home around: " + formattedPurchasePrice + "" +
"This is based on:" +
"
" +
"
Estimated maximum Principal & Interest payment: " + formattedMaxPrincipalInterest + " per month
" +
"
Your estimated loan amount: " + formattedLoanAmount + "