Use this calculator to estimate how much you can afford for a mortgage. It considers your income, debts, and down payment to give you a realistic idea of your borrowing capacity.
function calculateAffordability() {
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
// — Input Validation —
if (isNaN(annualIncome) || annualIncome <= 0) {
resultDiv.innerHTML = "Please enter a valid annual income.";
return;
}
if (isNaN(monthlyDebt) || monthlyDebt < 0) {
resultDiv.innerHTML = "Please enter a valid monthly debt amount.";
return;
}
if (isNaN(downPayment) || downPayment < 0) {
resultDiv.innerHTML = "Please enter a valid down payment amount.";
return;
}
if (isNaN(interestRate) || interestRate <= 0) {
resultDiv.innerHTML = "Please enter a valid interest rate.";
return;
}
if (isNaN(loanTerm) || loanTerm <= 0) {
resultDiv.innerHTML = "Please enter a valid loan term in years.";
return;
}
// — Affordability Calculation Logic —
// This is a simplified calculation. Lenders use more complex algorithms.
// A common guideline is that total housing costs (PITI) shouldn't exceed 28% of gross monthly income,
// and total debt (including PITI) shouldn't exceed 36% of gross monthly income.
var grossMonthlyIncome = annualIncome / 12;
// Maximum PITI (Principal, Interest, Taxes, Insurance) based on income
var maxPITI_income = grossMonthlyIncome * 0.28;
// Maximum total debt payment based on income
var maxTotalDebt_income = grossMonthlyIncome * 0.36;
// Maximum affordable monthly mortgage payment (PITI) after deducting other debts
var maxMonthlyMortgagePayment = Math.min(maxPITI_income, maxTotalDebt_income – monthlyDebt);
if (maxMonthlyMortgagePayment 0 && numberOfPayments > 0) {
estimatedMaxLoan_PI_only = maxMonthlyMortgagePayment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
}
// Now, let's refine this by considering T&I as a percentage of the *potential* home price.
// Home Price = Loan Amount + Down Payment
// Monthly T&I = (Home Price * Annual Tax Rate / 12) + (Home Price * Annual Insurance Rate / 12)
// Monthly T&I = Home Price * (Annual Tax Rate + Annual Insurance Rate) / 12
// Max Monthly Mortgage Payment = P&I Payment + Monthly T&I
// Max Monthly Mortgage Payment = P&I Payment + (Loan Amount + Down Payment) * (Tax Rate + Ins Rate) / 12
// This still requires solving for Loan Amount or Home Price, which involves more complex algebra or iteration.
// For a user-friendly calculator, we often simplify or use approximations.
// A common simplified approach is to estimate a target home price and then calculate affordability.
// Let's try to estimate affordability based on the loan amount that results in the maxMonthlyMortgagePayment *if* that payment was P&I.
// Then we can see if the T&I on that implied home price fits within the overall affordability limits.
var potentialHomePrice_initial = estimatedMaxLoan_PI_only + downPayment;
var estimatedMonthlyTaxes = potentialHomePrice_initial * estimatedAnnualPropertyTaxRate / 12;
var estimatedMonthlyInsurance = potentialHomePrice_initial * estimatedAnnualHomeInsuranceRate / 12;
var totalEstimatedMonthlyTaxesAndInsurance = estimatedMonthlyTaxes + estimatedMonthlyInsurance;
var actualMaxMonthlyMortgagePayment_PITI = maxMonthlyMortgagePayment; // This is our target PITI
// Let's check if the T&I derived from the 'estimatedMaxLoan_PI_only' fits within the `maxMonthlyMortgagePayment`.
// The difference `actualMaxMonthlyMortgagePayment_PITI – totalEstimatedMonthlyTaxesAndInsurance` is what's left for Principal & Interest.
var maxPAndI_payment = actualMaxMonthlyMortgagePayment_PITI – totalEstimatedMonthlyTaxesAndInsurance;
var maxLoanAmount_refined = 0;
if (maxPAndI_payment > 0 && monthlyInterestRate > 0 && numberOfPayments > 0) {
maxLoanAmount_refined = maxPAndI_payment * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else if (maxPAndI_payment <= 0) {
// If T&I alone exceed the affordable monthly payment, then no loan is possible.
maxLoanAmount_refined = 0;
}
var maxAffordableHomePrice = maxLoanAmount_refined + downPayment;
// — Display Results —
var output = "
Estimated Mortgage Affordability
";
output += "Based on your inputs, you may be able to afford a home up to:";
output += "$" + maxAffordableHomePrice.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') + "";
output += "This is an estimate and assumes:";
output += "
";
output += "
Your total monthly housing costs (Principal, Interest, Taxes, Insurance – PITI) should not exceed 28% of your gross monthly income.
";
output += "
Your total monthly debt payments (including PITI) should not exceed 36% of your gross monthly income.