This calculator helps you estimate how much house you can afford based on your income,
debts, and desired mortgage terms. It's a crucial tool for first-time homebuyers and
anyone looking to understand their borrowing capacity before seriously house hunting.
By inputting key financial details, you can get a clearer picture of your budget and
avoid overextending yourself financially.
Understanding Mortgage Affordability
Mortgage affordability is determined by several factors, primarily your income and your existing debts. Lenders use metrics like the debt-to-income ratio (DTI) to assess your ability to manage monthly mortgage payments.
Annual Household Income: This is the total gross income of all borrowers combined, before taxes.
Total Monthly Debt Payments: This includes minimum payments on credit cards, auto loans, student loans, and any other recurring debts. It does NOT include utilities, groceries, or other living expenses.
Down Payment: The upfront cash you pay towards the purchase price of the home. A larger down payment reduces the loan amount needed.
Estimated Annual Interest Rate: The interest rate you anticipate for your mortgage. This significantly impacts your monthly payment.
Loan Term: The length of time you have to repay the mortgage, typically 15 or 30 years.
Maximum Recommended Debt-to-Income Ratio: Lenders generally prefer a DTI ratio below 43%, though this can vary. This ratio compares your total monthly debt payments (including the proposed mortgage) to your gross monthly income.
This calculator provides an estimate. Actual loan approval amounts will depend on the lender's specific criteria, your credit score, property value, and other factors. It's always advisable to speak with a mortgage professional for personalized advice.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.input-section {
margin-bottom: 20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
align-items: center;
}
.input-section label {
font-weight: bold;
color: #555;
text-align: right;
padding-right: 10px;
}
.input-section input[type="number"] {
width: calc(100% – 20px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-container button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-bottom: 20px;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.result-section {
background-color: #e9ecef;
padding: 15px;
border-radius: 4px;
text-align: center;
font-size: 1.1em;
font-weight: bold;
color: #333;
margin-top: 20px;
}
.explanation-section {
margin-top: 30px;
border-top: 1px solid #eee;
padding-top: 20px;
}
.explanation-section h3 {
color: #333;
margin-bottom: 10px;
}
.explanation-section ul {
list-style: disc;
margin-left: 20px;
}
.explanation-section li {
margin-bottom: 8px;
color: #555;
}
.explanation-section strong {
color: #007bff;
}
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 maxDebtToIncomeRatio = parseFloat(document.getElementById("maxDebtToIncomeRatio").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Validate inputs
if (isNaN(annualIncome) || annualIncome <= 0 ||
isNaN(monthlyDebt) || monthlyDebt < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTerm) || loanTerm <= 0 ||
isNaN(maxDebtToIncomeRatio) || maxDebtToIncomeRatio 100) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
var monthlyIncome = annualIncome / 12;
var maxMonthlyPaymentAllowed = monthlyIncome * (maxDebtToIncomeRatio / 100);
var maxTotalMonthlyDebt = maxMonthlyPaymentAllowed; // This includes proposed mortgage payment
// Calculate the maximum allowable mortgage payment
var maxMortgagePayment = maxTotalMonthlyDebt – monthlyDebt;
if (maxMortgagePayment <= 0) {
resultDiv.innerHTML = "Based on your income and existing debts, you may not qualify for a mortgage that fits within the specified DTI ratio.";
return;
}
// Now, we need to find the maximum loan amount that results in this maxMortgagePayment.
// The formula for monthly mortgage payment (M) is:
// M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// Where:
// P = Principal loan amount
// i = Monthly interest rate (annual rate / 12)
// n = Total number of payments (loan term in years * 12)
// We need to solve for P:
// P = M [ (1 + i)^n – 1] / [ i(1 + i)^n ]
var monthlyInterestRate = (interestRate / 100) / 12;
var numberOfPayments = loanTerm * 12;
// Check for division by zero or invalid calculations if monthlyInterestRate is 0 or numberOfPayments is 0
if (monthlyInterestRate === 0 || numberOfPayments === 0) {
resultDiv.innerHTML = "Invalid interest rate or loan term for calculation.";
return;
}
var numerator = Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1;
var denominator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments);
if (denominator === 0) {
resultDiv.innerHTML = "Calculation error: Denominator is zero.";
return;
}
var maxLoanAmount = maxMortgagePayment * (numerator / denominator);
// The maximum home price affordable is the max loan amount plus the down payment
var maxHomePrice = maxLoanAmount + downPayment;
// Format the results
var formattedMaxHomePrice = "$" + maxHomePrice.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var formattedMaxLoanAmount = "$" + maxLoanAmount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var formattedMaxMortgagePayment = "$" + maxMortgagePayment.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var formattedMonthlyIncome = "$" + monthlyIncome.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var formattedMonthlyDebt = "$" + monthlyDebt.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var actualDti = ((maxMortgagePayment + monthlyDebt) / (monthlyIncome)) * 100;
var formattedActualDti = actualDti.toFixed(2) + "%";
var formattedMaxRecommendedDti = maxDebtToIncomeRatio.toFixed(2) + "%";
resultDiv.innerHTML =
"