Housing Cost Optimization Planner

Your Current Housing Cost Snapshot

Renting Details

$
$

Rent vs. Buy Comparison

Renting Scenario

$
$

Buying Scenario

$
%
%
$
$
$
%
%
%

Mortgage Optimization Tools

Refinance Calculator

Is Refinancing Right for You?

$
%
%
$
Extra Payments Calculator

Pay Off Your Mortgage Faster!

$
%
$
Down Payment Impact Analyzer

See How Your Down Payment Changes Things

$
%
%
%

Housing Affordability Estimator

Estimate what you might comfortably afford based on common guidelines. These are estimates only.

$
$
%
%

For Home Price Estimation (Optional Advanced):

%
%
%

Download Report

Generate a PDF summary of your housing cost analyses and scenarios.

Time Saved: ${Math.floor(yearsSaved)} years and ${Math.round((yearsSaved % 1) * 12)} months

Total Interest Saved: $${totalInterestSaved.toFixed(2)}

`; extraPaymentsResultsEl.style.display = 'block'; } window.hcot_calculateDownPaymentImpact = function() { const homePrice = getNum(dpHomePriceEl); const interestRate = getNum(dpInterestRateEl); const loanTerm = getNum(dpLoanTermEl); const downPaymentPercent = getNum(dpDownPaymentPercentEl); const pmiRate = getNum(dpPMIRateEl); if (homePrice <= 0 || interestRate <= 0 || loanTerm <= 0 || downPaymentPercent < 0 || downPaymentPercent > 100) { alert("Please enter valid home price, interest rate, loan term, and down payment percentage."); return; } const downPaymentAmount = homePrice * (downPaymentPercent / 100); const loanAmount = homePrice - downPaymentAmount; const monthlyPandI = calculateMonthlyMortgage(loanAmount, interestRate, loanTerm); const monthlyPMI = calculatePMI(loanAmount, homePrice, pmiRate); const totalInterest = calculateTotalInterestPaid(loanAmount, monthlyPandI, loanTerm); downPaymentResultsEl.innerHTML = `

Down Payment Impact Analysis

For a Home Price of $${homePrice.toFixed(2)}:

With a ${downPaymentPercent}% Down Payment ($${downPaymentAmount.toFixed(2)}):

  • Loan Amount: $${loanAmount.toFixed(2)}
  • Estimated Monthly P&I: $${monthlyPandI.toFixed(2)}
  • ${monthlyPMI > 0 ? `
  • Estimated Monthly PMI: $${monthlyPMI.toFixed(2)}
  • ` : '
  • No PMI expected (with 20%+ down)
  • '}
  • Total Monthly P&I + PMI: $${(monthlyPandI + monthlyPMI).toFixed(2)}
  • Total Interest Paid Over Loan Life: $${totalInterest.toFixed(2)}

Try different down payment percentages to see how it affects your loan and payments.

`; downPaymentResultsEl.style.display = 'block'; } // --- Tab 4: Affordability & Export --- window.hcot_calculateAffordability = function() { const grossAnnualIncome = getNum(affordGrossIncomeEl); const monthlyDebts = getNum(affordMonthlyDebtsEl); const housingRatio = getNum(affordHousingRatioEl, 28) / 100; const dtiRatio = getNum(affordDTIRatioEl, 36) / 100; const estInterestRate = getNum(affordEstInterestRateEl, 0); const estLoanTerm = getNum(affordEstLoanTermEl, 30); const estPropTaxRatePercent = getNum(affordEstPropTaxRateEl, 0); const estHomeInsRatePercent = getNum(affordEstHomeInsRateEl, 0); if (grossAnnualIncome <= 0) { alert("Please enter a valid gross annual income."); return; } const grossMonthlyIncome = grossAnnualIncome / 12; const affordableHousingPayment_frontEnd = grossMonthlyIncome * housingRatio; const affordableHousingPayment_backEnd = (grossMonthlyIncome * dtiRatio) - monthlyDebts; const finalAffordableMonthlyPITI = Math.min(affordableHousingPayment_frontEnd, affordableHousingPayment_backEnd); let resultsHtml = `

Housing Affordability Estimation

Gross Monthly Income: $${grossMonthlyIncome.toFixed(2)}

Affordable Monthly Housing Cost (PITI) based on ${housingRatio*100}% Front-End Ratio: $${affordableHousingPayment_frontEnd.toFixed(2)}

Affordable Monthly Housing Cost (PITI) based on ${dtiRatio*100}% Back-End DTI (after $${monthlyDebts.toFixed(2)} other debts): $${affordableHousingPayment_backEnd.toFixed(2)}

Recommended Max Monthly Housing Payment (PITI): $${finalAffordableMonthlyPITI.toFixed(2)}

`; // Estimate affordable home price (simplified) if (estInterestRate > 0 && estLoanTerm > 0 && estPropTaxRatePercent > 0 && estHomeInsRatePercent > 0 && finalAffordableMonthlyPITI > 0) { // PITI = P&I + T + I // P&I = PITI - T - I // For estimation, assume T and I are % of home price (HP) // T_monthly = (HP * estPropTaxRatePercent/100) / 12 // I_monthly = (HP * estHomeInsRatePercent/100) / 12 // P&I_monthly = M_factor * HP * (1 - assumed_dp_percent) // This gets complex to solve for HP directly. Simpler: iterate or provide a range. // Iterative approach: let lowHP = 10000, highHP = 2000000, midHP = 0, estPITI = 0; let affordableHomePrice = 0; const assumedDownPaymentPercentForAffordability = 0.10; // Assume 10% DP for this estimation for (let i = 0; i < 20; i++) { // Max 20 iterations for binary search midHP = (lowHP + highHP) / 2; if(midHP <=0) break; const estLoan = midHP * (1 - assumedDownPaymentPercentForAffordability); const estPandI = calculateMonthlyMortgage(estLoan, estInterestRate, estLoanTerm); const estTaxesMonthly = (midHP * (estPropTaxRatePercent / 100)) / 12; const estInsuranceMonthly = (midHP * (estHomeInsRatePercent / 100)) / 12; // Simplified PMI estimate if DP is less than 20% (always true for 10% assumed DP) const estPMIMonthly = calculatePMI(estLoan, midHP, getNum(dpPMIRateEl, 0.58)); estPITI = estPandI + estTaxesMonthly + estInsuranceMonthly + estPMIMonthly; if (estPITI > finalAffordableMonthlyPITI) { highHP = midHP; } else { affordableHomePrice = midHP; // Potential match lowHP = midHP; } if (highHP - lowHP < 1000) break; // Converged enough } if(affordableHomePrice > 0){ resultsHtml += `

Estimated Affordable Home Price Range (with ~10% down, assuming provided rates for tax/ins/mortgage): ~$${Math.floor(affordableHomePrice / 1000) * 1000}

`; resultsHtml += `

This home price estimate is very rough and depends heavily on your down payment, actual tax/insurance rates, and current mortgage rates. Use as a general guideline.

`; } else { resultsHtml += `

Could not estimate affordable home price with the given parameters. Ensure all rates for estimation are filled in.

`; } } else { resultsHtml += `

To estimate affordable home price, please fill in assumed mortgage rate, term, property tax rate, and home insurance rate under "For Home Price Estimation".

`; } affordabilityResultsEl.innerHTML = resultsHtml; affordabilityResultsEl.style.display = 'block'; } // --- Sub-section Toggling --- window.hcot_toggleSubSection = function(toggleButton, sectionId) { const sectionContent = document.getElementById(sectionId); const icon = toggleButton.querySelector('i'); if (sectionContent) { if (sectionContent.classList.contains('active')) { sectionContent.classList.remove('active'); if(icon) icon.classList.replace('fa-chevron-up', 'fa-chevron-down'); } else { sectionContent.classList.add('active'); if(icon) icon.classList.replace('fa-chevron-down', 'fa-chevron-up'); } } } // --- PDF Download --- if (downloadPdfButton) { downloadPdfButton.addEventListener('click', function() { let pdfHtml = `
`; pdfHtml += `

Housing Cost Optimization Report

`; pdfHtml += `

Generated on: ${new Date().toLocaleDateString()}

`; // Section 1: Current Housing Costs if (currentCostsResultsEl && currentCostsResultsEl.style.display !== 'none' && currentCostsResultsEl.innerHTML.length > 20) { pdfHtml += `

My Current Housing Snapshot

`; pdfHtml += `

Current Situation: ${currentSituationRentingEl.checked ? 'Renting' : 'Owning'}

`; // Add inputs here... e.g., Rent: $value, P&I: $value etc. if(currentSituationRentingEl.checked){ pdfHtml += `

Monthly Rent: $${getNum(currentRentEl).toFixed(2)}

`; pdfHtml += `

Renter's Insurance: $${getNum(currentRentersInsuranceEl).toFixed(2)}

`; } else { pdfHtml += `

P&I: $${getNum(currentPandIEl).toFixed(2)}

`; pdfHtml += `

Property Taxes: $${getNum(currentPropertyTaxesEl).toFixed(2)}

`; pdfHtml += `

Home Insurance: $${getNum(currentHomeInsuranceEl).toFixed(2)}

`; pdfHtml += `

HOA: $${getNum(currentHOAEl).toFixed(2)}

`; pdfHtml += `

PMI: $${getNum(currentPMIEl).toFixed(2)}

`; pdfHtml += `

Maintenance: $${getNum(currentMaintenanceEl).toFixed(2)}

`; } pdfHtml += `
`; pdfHtml += `
${currentCostsResultsEl.innerHTML}
`; } // Section 2: Rent vs. Buy if (rentVsBuyResultsEl && rentVsBuyResultsEl.style.display !== 'none' && rentVsBuyResultsEl.innerHTML.length > 20) { pdfHtml += `

Rent vs. Buy Analyzer

`; // Add inputs... pdfHtml += `

Inputs:

Rent: $${getNum(rvbRentEl).toFixed(2)}, Renters Ins: $${getNum(rvbRentersInsEl).toFixed(2)}

Home Price: $${getNum(rvbHomePriceEl).toFixed(2)}, DP: ${getNum(rvbDownPaymentPercentEl)}%, Rate: ${getNum(rvbInterestRateEl)}%, Term: ${getVal(rvbLoanTermEl)} yrs

Taxes: $${getNum(rvbPropertyTaxEl).toFixed(2)}/yr, Home Ins: $${getNum(rvbHomeInsEl).toFixed(2)}/yr, HOA: $${getNum(rvbHOAEl).toFixed(2)}/mo

PMI Rate: ${getNum(rvbPMIRateEl)}%/yr, Maintenance: ${getNum(rvbMaintenanceEl)}%/yr, Closing: ${getNum(rvbClosingCostsEl)}%

`; pdfHtml += `
${rentVsBuyResultsEl.innerHTML}
`; } // Section 3: Mortgage Optimizer (Refinance, Extra Payments, Down Payment) if (refinanceResultsEl && refinanceResultsEl.style.display !== 'none' && refinanceResultsEl.innerHTML.length > 20) { pdfHtml += `

Refinance Analysis

`; pdfHtml += `

Inputs:

Current Balance: $${getNum(refiCurrentBalanceEl).toFixed(2)}, Rate: ${getNum(refiCurrentRateEl)}%, Term: ${getNum(refiRemainingTermEl)} yrs

New Rate: ${getNum(refiNewRateEl)}%, New Term: ${getNum(refiNewTermEl)} yrs, Costs: $${getNum(refiCostsEl).toFixed(2)}

`; pdfHtml += `
${refinanceResultsEl.innerHTML}
`; } if (extraPaymentsResultsEl && extraPaymentsResultsEl.style.display !== 'none' && extraPaymentsResultsEl.innerHTML.length > 20) { pdfHtml += `

Extra Payments Analysis

`; pdfHtml += `

Inputs:

Balance: $${getNum(epLoanBalanceEl).toFixed(2)}, Rate: ${getNum(epInterestRateEl)}%, Term: ${getNum(epRemainingTermEl)} yrs, Extra: $${getNum(epExtraPaymentEl).toFixed(2)}/mo

`; pdfHtml += `
${extraPaymentsResultsEl.innerHTML}
`; } if (downPaymentResultsEl && downPaymentResultsEl.style.display !== 'none' && downPaymentResultsEl.innerHTML.length > 20) { pdfHtml += `

Down Payment Impact

`; pdfHtml += `

Inputs:

Home Price: $${getNum(dpHomePriceEl).toFixed(2)}, Rate: ${getNum(dpInterestRateEl)}%, Term: ${getVal(dpLoanTermEl)} yrs, DP: ${getNum(dpDownPaymentPercentEl)}%

`; pdfHtml += `
${downPaymentResultsEl.innerHTML}
`; } // Section 4: Affordability if (affordabilityResultsEl && affordabilityResultsEl.style.display !== 'none' && affordabilityResultsEl.innerHTML.length > 20) { pdfHtml += `

Housing Affordability Estimation

`; pdfHtml += `

Inputs:

Income: $${getNum(affordGrossIncomeEl).toFixed(2)}/yr, Monthly Debts: $${getNum(affordMonthlyDebtsEl).toFixed(2)}

Housing Ratio: ${getNum(affordHousingRatioEl)}%, DTI Ratio: ${getNum(affordDTIRatioEl)}%

`; pdfHtml += `
${affordabilityResultsEl.innerHTML}
`; } pdfHtml += `
`; // Close hcot-pdf-output pdfOutputEl.innerHTML = pdfHtml; const opt = { margin: [0.5, 0.4, 0.5, 0.4], filename: `Housing_Cost_Optimization_Report_${new Date().toISOString().slice(0,10)}.pdf`, image: { type: 'jpeg', quality: 0.95 }, html2canvas: { scale: 2, useCORS: true, logging: false, scrollX: 0, scrollY: 0, windowWidth: pdfOutputEl.scrollWidth, windowHeight: pdfOutputEl.scrollHeight + 50}, jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }, pagebreak: { mode: ['css', 'avoid-all', 'legacy'] } // 'css' or 'avoid-all' can be good }; if (html2pdf && pdfOutputEl) { html2pdf().from(pdfOutputEl).set(opt).save() .catch(err => { console.error("PDF generation failed:", err); alert("PDF generation failed. See console for details."); }); } else { alert("PDF generation library or output element not ready."); } }); } // --- Tab Navigation --- window.hcot_openTab = function(evt, tabName) { tabs.forEach(tab => { if(tab) tab.style.display = 'none'; }); tabLinks.forEach(link => { if(link) link.classList.remove('active'); }); const activeTabContent = toolContainer.querySelector('#' + tabName); if(activeTabContent) activeTabContent.style.display = 'block'; else { console.error(`Tab content for ${tabName} not found.`); return; } let clickedIndex = -1; if (evt && evt.currentTarget) { evt.currentTarget.classList.add('active'); clickedIndex = tabLinks.indexOf(evt.currentTarget); } else { clickedIndex = tabLinks.findIndex(link => { const onclickAttr = link.getAttribute('onclick'); return onclickAttr && onclickAttr.includes(tabName); }); if (clickedIndex !== -1 && tabLinks[clickedIndex]) tabLinks[clickedIndex].classList.add('active'); } currentTabIndex = clickedIndex !== -1 ? clickedIndex : 0; hcot_updateNavButtons(); } window.hcot_navigateTab = function(direction) { let newIndex = currentTabIndex; if (direction === 'next' && currentTabIndex < tabs.length - 1) newIndex++; else if (direction === 'prev' && currentTabIndex > 0) newIndex--; if (tabLinks[newIndex] && newIndex !== currentTabIndex) tabLinks[newIndex].click(); } function hcot_updateNavButtons() { if(prevButton) prevButton.disabled = currentTabIndex === 0; if(nextButton) nextButton.disabled = currentTabIndex >= tabs.length - 1; } // --- Initialization --- function initializeTool() { // Check for Font Awesome (if icons are desired and not globally available) // if (typeof FontAwesome === 'undefined') { /* Potentially load FA or inform user */ } // Default values if elements exist if(currentSituationRentingEl) currentSituationRentingEl.checked = true; hcot_toggleCurrentSituationForms(); // Set initial form visibility const today = new Date(); // Not used here but good practice if date inputs needed default hcot_openTab(null, 'hcot-tab1'); // Open first tab } // Check if html2pdf is loaded (it's from CDN) let attempts = 0; function checkLibrariesAndInit_hcot() { if (typeof html2pdf !== 'undefined') { initializeTool(); } else if (attempts < 20) { // Try for 2 seconds attempts++; setTimeout(checkLibrariesAndInit_hcot, 100); } else { alert("Error: PDF generation library (html2pdf.js) could not be loaded. PDF export will not work."); initializeTool(); // Initialize anyway } } checkLibrariesAndInit_hcot(); })();
Scroll to Top