function calculateAffordability() {
// Retrieve inputs
var income = parseFloat(document.getElementById('aff_income').value);
var debts = parseFloat(document.getElementById('aff_debts').value);
var down = parseFloat(document.getElementById('aff_down').value);
var rate = parseFloat(document.getElementById('aff_rate').value);
var term = parseFloat(document.getElementById('aff_term').value);
var tax = parseFloat(document.getElementById('aff_tax').value);
var ins = parseFloat(document.getElementById('aff_ins').value);
// Validation
if (isNaN(income) || income <= 0) {
alert("Please enter a valid annual income.");
return;
}
if (isNaN(debts)) debts = 0;
if (isNaN(down)) down = 0;
if (isNaN(rate) || rate <= 0) {
alert("Please enter a valid interest rate.");
return;
}
if (isNaN(tax)) tax = 0;
if (isNaN(ins)) ins = 0;
// Calculations
// 1. Calculate Monthly Gross Income
var monthlyIncome = income / 12;
// 2. Calculate Maximum Monthly Payment based on DTI Rules
// Rule 1: Front-end ratio (28% of income for housing costs)
var maxHousingFront = monthlyIncome * 0.28;
// Rule 2: Back-end ratio (36% of income for housing + debts)
// Note: Some lenders go higher (43% or 50%), but 36% is conservative/standard
var maxTotalBack = monthlyIncome * 0.36;
var maxHousingBack = maxTotalBack – debts;
// The limiting factor is the lower of the two
var maxAllowedHousingPayment = Math.min(maxHousingFront, maxHousingBack);
// Subtract non-mortgage housing costs (Tax and Insurance) to find P&I capability
var monthlyTax = tax / 12;
var monthlyIns = ins / 12;
var availableForPI = maxAllowedHousingPayment – monthlyTax – monthlyIns;
var resultContainer = document.getElementById('aff_results');
var errorMsg = document.getElementById('error_msg');
resultContainer.style.display = 'block';
if (availableForPI <= 0) {
document.getElementById('result_price').innerText = "$0";
document.getElementById('result_monthly').innerText = "$0";
document.getElementById('result_loan').innerText = "$0";
document.getElementById('result_dti').innerText = "N/A";
errorMsg.style.display = 'block';
errorMsg.innerText = "Based on your income and debts, you cannot currently qualify for a mortgage payment.";
return;
} else {
errorMsg.style.display = 'none';
}
// 3. Calculate Max Loan Amount using Present Value formula
// PV = PMT * (1 – (1+r)^-n) / r
var r = rate / 100 / 12; // Monthly interest rate
var n = term * 12; // Total number of payments
var maxLoanAmount = availableForPI * ( (1 – Math.pow(1 + r, -n)) / r );
// 4. Calculate Max Home Price
var maxHomePrice = maxLoanAmount + down;
// 5. Calculate Actual Total Monthly Payment
// This is simply the maxAllowedHousingPayment we derived, unless maxLoanAmount was capped by other factors (not applicable here)
var totalMonthlyPayment = availableForPI + monthlyTax + monthlyIns;
// Format Output
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0
});
document.getElementById('result_price').innerText = formatter.format(maxHomePrice);
document.getElementById('result_monthly').innerText = formatter.format(totalMonthlyPayment);
document.getElementById('result_loan').innerText = formatter.format(maxLoanAmount);
// Calculate which DTI was used
var usedRatio = (totalMonthlyPayment + debts) / monthlyIncome * 100;
document.getElementById('result_dti').innerText = usedRatio.toFixed(1) + "%";
}
Understanding Your Mortgage Affordability
Buying a home is one of the largest financial commitments you will make. This Mortgage Affordability Calculator helps you estimate how much house you can afford by analyzing your income, current debts, and down payment savings against standard lender guidelines.
How Do Lenders Decide What I Can Afford?
Lenders primarily use two metrics called Debt-to-Income (DTI) Ratios to determine your loan eligibility:
-
The Front-End Ratio (28% Rule): Standard guidelines suggest that your monthly housing costs (principal, interest, taxes, and insurance) should not exceed 28% of your gross monthly income.
-
The Back-End Ratio (36% Rule): This is often the more critical number. It states that your total monthly debt payments—including your new mortgage, credit cards, student loans, and car payments—should not exceed 36% of your gross monthly income.
This calculator determines the maximum monthly payment allowed under both rules and uses the lower (more conservative) figure to calculate your potential loan amount.
Key Factors Impacting Your Purchase Power
1. Interest Rates
Even a small change in interest rates can significantly affect your buying power. As rates rise, the portion of your monthly payment going toward interest increases, reducing the amount available for the loan principal. This lowers the total home price you can afford.
2. Your Down Payment
A larger down payment increases your affordability in two ways: it directly adds to the purchase price (Purchase Price = Loan + Down Payment) and it lowers your Loan-to-Value (LTV) ratio, potentially securing you a better interest rate or removing the need for Private Mortgage Insurance (PMI).
3. Monthly Debts
Debts are the silent killer of mortgage affordability. A $400 car payment reduces your borrowing power by roughly $50,000 to $70,000 (depending on interest rates) because that monthly cash flow cannot be used to service a mortgage.
Improving Your Affordability
If the result from the calculator is lower than home prices in your area, consider these strategies:
- Pay down high-interest debt: Reducing monthly obligations frees up room in your back-end DTI ratio.
- Increase your down payment: Save aggressively to reduce the loan amount needed.
- Shop for lower insurance rates: Lowering property tax (by choosing a different area) or home insurance costs increases the amount available for principal and interest.