This calculator helps you estimate how much house you can afford based on your income, debts, and down payment. Use it as a starting point for your home-buying journey!
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.";
return;
}
// Lender's Debt-to-Income (DTI) Ratio Guidelines (commonly used)
// Front-end DTI (Housing Costs / Gross Income) should typically be below 28%
// Back-end DTI (All Debt Payments / Gross Income) should typically be below 36%
var maxHousingPaymentRatio = 0.28; // Max percentage of gross income for PITI
var maxTotalDebtRatio = 0.36; // Max percentage of gross income for all debts (including PITI)
var grossMonthlyIncome = annualIncome / 12;
// Calculate maximum total monthly debt allowed
var maxTotalMonthlyDebt = grossMonthlyIncome * maxTotalDebtRatio;
// Calculate maximum allowed monthly housing payment (PITI)
var maxMonthlyHousingPayment = grossMonthlyIncome * maxHousingPaymentRatio;
// Maximum monthly payment that can go towards principal and interest (P&I)
// We subtract existing monthly debt from the total allowed debt to find what's left for PITI,
// and then subtract estimated taxes and insurance.
// For simplicity in this calculator, we'll assume taxes and insurance are roughly 1.2% of home value annually,
// or about 0.1% of home value monthly. This is a simplification.
var estimatedTaxesAndInsuranceRatio = 0.001; // 0.1% of home value per month
var maxPITI = Math.min(maxMonthlyHousingPayment, maxTotalMonthlyDebt – monthlyDebt);
if (maxPITI maxMonthlyHousingPayment) {
// This means our initial estimation of T&I ratio against loan amount might be too high,
// or the P&I calculation needs to be more precise against the total PITI.
// A more robust calculator would iterate. For this simplified version, let's adjust.
// If the total payment exceeds the housing ratio, it means the loan amount is too high.
// Let's recalculate by ensuring PITI does not exceed maxMonthlyHousingPayment.
// This implies that the 'estimatedMaxLoanAmount' might be slightly off due to T&I estimation.
// We'll cap the affordability based on the primary DTI rules.
// The formula P = maxPITI / (pAndICoefficient + 0.001) is a simplification.
// A more accurate way is to solve for P in maxPITI = P&I(P) + (P + DownPayment)*0.001.
// This is a quadratic equation or requires numerical methods.
// For simplicity, let's just report the affordability based on the primary constraints.
// The 'estimatedHomePrice' is a good indicator.
}
var affordableHomePriceFormatted = estimatedHomePrice.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
var maxMonthlyHousingPaymentFormatted = maxMonthlyHousingPayment.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
var monthlyDebtFormatted = monthlyDebt.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
var annualIncomeFormatted = annualIncome.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
resultDiv.innerHTML = `
Estimated Affordability:
Based on your inputs, you may be able to afford a home priced around ${affordableHomePriceFormatted}.
This estimate is based on the following assumptions:
Maximum allowed monthly housing payment (Principal, Interest, Taxes, Insurance – PITI): ${maxMonthlyHousingPaymentFormatted} (which is ${maxHousingPaymentRatio * 100}% of your gross monthly income).
Your existing total monthly debt payments: ${monthlyDebtFormatted}.
The maximum total monthly debt payments (including your potential mortgage PITI) should not exceed ${maxTotalDebtRatio * 100}% of your gross monthly income.
Estimated monthly taxes and insurance are 0.1% of the *loan amount* (or 1.2% of loan amount annually) plus 0.1% of the down payment. This is a simplification and actual costs can vary significantly.
The interest rate is fixed for the entire loan term.