# Refinance break-even calculator

Compare your current payment with a refinanced payment and see how long it takes to recover the closing costs.

/**
 * Calculator maths for costreference.com.
 *
 * Plain functions on `window.CRCALC`. This file is the single source of the maths: it is
 * served to the browser as the calculator bundle and it is the file the Node test
 * (scripts/test-tool-math.mjs) imports. The tests therefore exercise exactly the code users run.
 *
 * Every function validates its inputs and returns NaN rather than throwing, so a bad input
 * produces an error message instead of a broken page.
 */
(function (root) {
  "use strict";

  function isNum(v) { return typeof v === "number" && Number.isFinite(v); }

  /** Standard amortising payment. i = monthly rate, n = months. */
  function monthlyPayment(principal, annualRatePct, months) {
    if (!isNum(principal) || !isNum(annualRatePct) || !isNum(months)) return NaN;
    if (principal  balance) princ = balance;
      if (princ  1e-9) cheaper = a  0
        ? Math.abs(a - b) / Math.max(a, b) * 100 : 0 };
  }

  /** Months to clear a balance at a fixed payment, plus the effect of paying more. */
  function payoffMonths(balance, annualRatePct, payment) {
    if (!isNum(balance) || !isNum(annualRatePct) || !isNum(payment)) return null;
    if (balance

      Current monthly payment (USD)

      New monthly payment (USD)

      Closing costs and fees (USD)

      Remaining term after refinancing (months)

  Calculate break-even

Break-even is closing costs divided by the monthly saving. It answers only one
question — how long until the fees are recovered — and deliberately ignores whether a longer term
costs more in total interest. Compare the total interest of the old and new schedules before
deciding; extending a term can lower the payment while raising the total cost.

(function () {
  var C = window.CRCALC;
  function $(id) { return document.getElementById(id); }
  function num(id) { var el = $(id); if (!el) return NaN; var v = el.value === "" ? NaN : Number(el.value); return Number.isFinite(v) ? v : NaN; }
  function money(n) { return "$" + n.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: 0 }); }
  function render() {
    var cur = num("rb-current"), nw = num("rb-new"), costs = num("rb-costs"), months = num("rb-months");
    var err = $("rb-err"), out = $("rb-out");
    err.hidden = true;
    if (!Number.isFinite(cur) || cur  600) { err.hidden = false; err.textContent = "Enter the remaining term after refinancing."; out.innerHTML = ""; return; }
    var r = C.refinanceBreakEven(cur, nw, costs);
    if (!r) { err.hidden = false; err.textContent = "Those inputs cannot be calculated."; out.innerHTML = ""; return; }
    if (!r.recoverable) {
      out.innerHTML = "No break-even

The new payment is not lower than the current one, so the closing costs are never recovered by the monthly saving. A refinance on these figures costs you money every month.

";
      return;
    }
    var saved = r.saving * months - costs;
    var verdict = r.months " + Math.ceil(r.months) + " months to break even

" +
      "Monthly saving: " + money(r.saving) + ". Over " + months + " months that is " + money(r.saving * months) + " of saved payments against " + money(costs) + " of costs, a net " + money(saved) + ". " + verdict + "

" +
      "TimelinePointCumulative saving

" +
      [12, 24, 36, 60].filter(function (m) { return m After " + m + " months" + money(r.saving * m - costs) + "

";
      }).join("") +
      "After " + months + " months (end of term)" + money(saved) + "

" +
      "

";
  }
  window.__crRender = render;
  $("rb-go").addEventListener("click", render);
  ["rb-current", "rb-new", "rb-costs", "rb-months"].forEach(function (id) { $(id).addEventListener("input", render); });
  render();
})();

Source: https://costreference.com/tools/refinance-break-even-calculator/
