/** * Local mortgage / PITI calculator — the canonical helper reconciling * five cohort implementations. * * Surveyed implementations: * * - zillow-mcp `src/tools/mortgage.ts` `computeMortgage` — the most * complete output shape (loan_amount, down_payment, monthly_*, * monthly_total, total_interest_paid, total_paid_over_loan, * loan_term_years, interest_rate, ltv_percent as 0..100). * - redfin-mcp `src/tools/mortgage.ts` — line-for-line identical to * zillow's. * - compass-mcp `src/tools/mortgage.ts` — leaner inline shape: * `monthly_total_piti`, `total_interest_over_term`, `ltv` as a * 0..1 ratio, no `interest_rate` echo. Same math. * - homes-mcp `src/tools/mortgage.ts` — line-for-line copy of compass. * - onehome-mcp `src/tools/mortgage.ts` — copy of compass minus one * field, same math. * * Canonical policy (union over the cohort): * * 1. PMT formula: M = P * r * (1+r)^n / ((1+r)^n - 1). Guard the * zero-interest case with straight-line amortization (M = P/n) so * the formula stays finite at r = 0. * 2. Defaults: `loan_term_years = 30`, `down_payment_percent = 20` * when neither `down_payment` nor `down_payment_percent` is given. * 3. `down_payment` overrides `down_payment_percent` when both are * provided (the zillow precedence). * 4. `property_tax_annual` overrides `property_tax_rate` when both * are provided; `property_tax_rate` decomposes via `home_price`. * 5. PMI applies strictly above 80% LTV (> 80, not >=) and only when * `pmi_rate` is provided. * 6. LTV is reported as a percent (0..100), matching the zillow shape. * 7. Output shape carries the zillow union (most complete) plus * `home_price` (echoed from input, matches the compass/homes/ * onehome variant) so each cohort wrapper can map cleanly. * 8. Validation: `home_price` must be positive, `interest_rate` must * be non-negative, `loan_term_years` must be positive. */ /** * Inputs to `calculateMortgage`. Match the cohort's * `*_calculate_mortgage` tool input schema. */ export interface MortgageInput { /** Home purchase price in dollars. Must be positive. */ home_price: number; /** Down payment in dollars. Overrides `down_payment_percent`. */ down_payment?: number; /** Down payment as a percent of `home_price` (0..100). Default 20. */ down_payment_percent?: number; /** Annual interest rate as a percent (e.g. 6.5 for 6.5%). */ interest_rate: number; /** Loan term in years. Default 30. */ loan_term_years?: number; /** Annual property tax in dollars. Overrides `property_tax_rate`. */ property_tax_annual?: number; /** Property tax as a percent of `home_price` annually (0..100). */ property_tax_rate?: number; /** Annual homeowner's insurance in dollars. */ insurance_annual?: number; /** Monthly HOA dues in dollars. */ hoa_monthly?: number; /** PMI as an annual percent of the loan balance (0..100). */ pmi_rate?: number; } /** * Output of `calculateMortgage`. Carries the full PITI breakdown plus * loan-level totals. */ export interface MortgageBreakdown { /** Home purchase price (echoed from input). */ home_price: number; /** Down payment in dollars. */ down_payment: number; /** Loan principal (home_price - down_payment). */ loan_amount: number; /** Monthly P&I (principal + interest). */ monthly_principal_interest: number; /** Monthly property tax. */ monthly_property_tax: number; /** Monthly insurance. */ monthly_insurance: number; /** Monthly HOA dues. */ monthly_hoa: number; /** Monthly PMI. Zero when LTV ≤ 80% or `pmi_rate` is not provided. */ monthly_pmi: number; /** Sum of all monthly components — full PITI + HOA + PMI. */ monthly_total: number; /** Total interest paid over the life of the loan. */ total_interest_paid: number; /** Total dollars paid over the life of the loan (P&I only). */ total_paid_over_loan: number; /** Loan term in years (echoed from input or default 30). */ loan_term_years: number; /** Annual interest rate as a percent (echoed from input). */ interest_rate: number; /** Loan-to-value as a percent (0..100). */ ltv_percent: number; } /** * Compute a PITI breakdown from a mortgage scenario. Pure / deterministic * — no I/O, no dependencies. Hoisted from the realty cohort * (zillow/redfin/compass/homes/onehome). */ export declare function calculateMortgage(input: MortgageInput): MortgageBreakdown;