Determining "how much house can I afford?" is the crucial first step in the homebuying process. Unlike a simple loan payment calculator, a mortgage affordability calculator works backward from your financial situation to estimate the maximum home price that fits your budget.
Lenders primarily use a metric called the Debt-to-Income (DTI) ratio to decide how much they are willing to lend. There are generally two types of DTI ratios considered:
Front-End Ratio: The percentage of your gross monthly income that goes toward housing costs (principal, interest, taxes, and insurance – PITI). Lenders often prefer this to be under 28%.
Back-End Ratio: The percentage of your gross monthly income that goes toward all debt obligations, including housing, car loans, student loans, and credit card minimums. Many lenders cap this at 36% to 43%, depending on the loan type.
This calculator uses a standard conservative back-end DTI guideline (around 36%) to estimate the maximum total monthly payment you can sustain based on your income and existing debts. It then calculates the loan amount supported by that payment at your specified interest rate and adds your down payment to find your maximum purchasing power.
For example, if your household earns $90,000 annually ($7,500/month) and you have $500 in monthly debt payments (like a car note), a lender using a 36% back-end DTI limit would calculate your maximum total allowed debt at $2,700 ($7,500 * 0.36). Subtracting your existing $500 debt leaves $2,200 available for maximum mortgage housing costs.
*Note: This calculation assumes a back-end Debt-to-Income ratio of approximately 36%. Actual lender qualification depends on credit score, loan type, and current property tax/insurance rates in your area.
function calculateAffordability() {
// 1. Get Input Values
var annualIncomeInput = document.getElementById("annualIncome").value;
var monthlyDebtsInput = document.getElementById("monthlyDebts").value;
var downPaymentInput = document.getElementById("downPayment").value;
var interestRateInput = document.getElementById("interestRate").value;
var loanTermInput = document.getElementById("loanTerm").value;
// 2. Parse and Validate Inputs
var annualIncome = parseFloat(annualIncomeInput);
var monthlyDebts = parseFloat(monthlyDebtsInput);
var downPayment = parseFloat(downPaymentInput);
var interestRate = parseFloat(interestRateInput);
var loanTermYears = parseInt(loanTermInput);
// Handle edge cases and bad data
if (isNaN(annualIncome) || annualIncome <= 0) {
alert("Please enter a valid positive Annual Gross Income.");
return;
}
if (isNaN(monthlyDebts) || monthlyDebts < 0) monthlyDebts = 0;
if (isNaN(downPayment) || downPayment < 0) downPayment = 0;
if (isNaN(interestRate) || interestRate 0) {
// Prepare variables for reverse mortgage calculation
var monthlyRate = (interestRate / 100) / 12;
var totalPaymentsInMonths = loanTermYears * 12;
// Reverse Mortgage Formula to find Principal (Loan Amount) based on Payment
// P = M * [ ( (1 + r)^n – 1 ) / ( r * (1 + r)^n ) ]
// NOTE: maxHousingPayment here needs to cover Principal, Interest, Taxes, and Insurance.
// To simplify finding the Max Loan Amount, we use the max housing payment directly in the PV formula. This means the resulting loan amount is a ceiling, assuming the payment covers everything.
var mathPowTerm = Math.pow(1 + monthlyRate, totalPaymentsInMonths);
// Check to avoid division by zero if rate is somehow 0 (though validated above)
if (monthlyRate > 0) {
maxLoanAmount = maxHousingPayment * ((mathPowTerm – 1) / (monthlyRate * mathPowTerm));
} else {
// Simple division if interest is 0%
maxLoanAmount = maxHousingPayment * totalPaymentsInMonths;
}
// Final Home Price = Max Loan the bank will give + Cash Down Payment
maxHomePrice = maxLoanAmount + downPayment;
} else {
// If monthly debts exceed allowed DTI budget
maxHousingPayment = 0;
}
// 4. Output Formatting and Display
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0
});
document.getElementById("maxHomePriceOutput").innerText = formatter.format(maxHomePrice);
document.getElementById("maxMonthlyPaymentOutput").innerText = formatter.format(maxHousingPayment);
document.getElementById("loanAmountOutput").innerText = formatter.format(maxLoanAmount);
// Show result container
document.getElementById("affordabilityResult").style.display = "block";
}