Data room / The current model

Story inputs

Code, 709 words

model/stories.js Open the file as written

// Equity Flow: the five homeowner stories, as model inputs.
//
// Nothing here is a number that appears on the page. The page's stat boxes and
// prose figures are rendered by scripts/build_site.js from computeStories(),
// which refuses any story whose committed schedule fails a constraint.
// tests/drift.test.js fails when the rendered HTML no longer matches.
//
// Each story is an illustrative composite. Ages are measured from
// CONFIG.as_of; a story's borrower turns the stated age in the as_of month.

import * as EF from './equity_flow.js';
import { CONFIG } from './config.js';

export const STORIES = Object.freeze([
  {
    id: 'maria',
    name: 'Maria',
    age: 55,
    tag: 'The bridge to 62',
    homeValue: 650000,
    lien: { origLoan: 200000, rate: 0.0375, termYears: 30, origYear: 2012 },
    schedule: { deposit: 800, months: 84 },
    exit: { type: 'hecm_refi_at_62' },
    alternative: { type: 'sale', year: 8, label: 'sells at 63' }
  },
  {
    id: 'henry',
    name: 'Henry',
    age: 49,
    tag: 'The newly equity-rich',
    homeValue: 1950000,
    purchasePrice: 1375000,
    lien: { origLoan: 205000, rate: 0.045, termYears: 30, origYear: 2022 },
    schedule: { deposit: 2000, months: 36, stopAtMonth: 14 },
    exit: { type: 'payoff', year: 3 }
  },
  {
    id: 'diane',
    name: 'Diane',
    age: 57,
    tag: 'The carrying-cost squeeze',
    homeValue: 650000,
    lien: { origLoan: 320000, rate: 0.06, termYears: 30, origYear: 2007 },
    schedule: { deposit: 850, months: 60 },
    billShield: true,
    exit: { type: 'hecm_refi_at_62' },
    alternative: { type: 'sale', year: 13, label: 'downsizes at 70' }
  },
  {
    id: 'renee',
    name: 'Renee',
    age: 47,
    tag: 'The payment is the danger',
    homeValue: 1000000,
    lien: { origLoan: 220000, rate: 0.0325, termYears: 30, origYear: 2021 },
    schedule: { deposit: 850, months: 60 },
    exit: { type: 'sale', year: 6 }
  },
  {
    id: 'dan',
    name: 'Dan',
    age: 51,
    tag: 'The HELOC said no',
    homeValue: 700000,
    lien: { origLoan: 120000, rate: 0.035, termYears: 30, origYear: 2020 },
    schedule: { deposit: 700, months: 84 },
    exit: { type: 'sale', year: 10 }
  }
]);

// Interest a matched-draw HELOC would charge: the borrower pays interest
// monthly on whatever has been drawn so far, at the illustrative HELOC rate.
export function helocInterestOnSchedule(schedule, throughMonth, cfg = CONFIG) {
  let bal = 0, interest = 0;
  const D = Math.min(schedule.months, schedule.stopAtMonth ?? schedule.months);
  for (let m = 1; m <= throughMonth; m++) {
    interest += bal * cfg.heloc_rate / 12;
    if (m <= D) bal += schedule.deposit;
  }
  return interest;
}

export function computeStory(spec, cfg = CONFIG) {
  const asOf = cfg.as_of;
  const inputs = { homeValue: spec.homeValue, lien: spec.lien, dob: EF.dobForAge(spec.age, asOf), asOf };
  const committed = { deposit: spec.schedule.deposit, months: spec.schedule.months };
  const check = EF.evaluate(inputs, committed, cfg);
  const elig = EF.eligibility(inputs, cfg);
  const fee = EF.originationFee(committed.deposit * committed.months, cfg);
  const maxDep = EF.maxDeposit(inputs, committed.months, cfg);
  const out = {
    spec, inputs, committed, check, eligibility: elig, fee, maxDeposit: maxDep,
    commitment: committed.deposit * committed.months,
    seniorNow: elig.senior,
    startCltv: elig.startCltv,
    at62: EF.hecmAt62(inputs, committed, cfg)
  };
  const D = spec.schedule.stopAtMonth ?? spec.schedule.months;
  out.received = EF.depositsMade(spec.schedule, 10000);
  out.depositMonths = D;

  if (spec.exit.type === 'hecm_refi_at_62') {
    const m62 = out.at62.monthsTo62;
    out.exitMonth = m62;
    out.balanceAtExit = EF.efBalanceAt(spec.schedule, m62, cfg);
    out.costAtExit = out.balanceAtExit - out.received;
    out.exitYears = m62 / 12;
  } else if (spec.exit.type === 'payoff') {
    const m = spec.exit.year * 12;
    out.exitMonth = m;
    out.balanceAtExit = EF.efBalanceAt(spec.schedule, m, cfg);
    out.costAtExit = out.balanceAtExit - out.received;
    out.exitYears = spec.exit.year;
  } else if (spec.exit.type === 'sale') {
    const m = spec.exit.year * 12;
    out.exitMonth = m;
    out.sale = EF.projectSale(inputs, spec.schedule, m, cfg.hpi_base, cfg);
    out.saleFlat = EF.projectSale(inputs, spec.schedule, m, 0, cfg);
    out.balanceAtExit = out.sale.balance;
    out.costAtExit = out.sale.trueCost;
    out.exitYears = spec.exit.year;
  }
  if (spec.alternative && spec.alternative.type === 'sale') {
    const m = spec.alternative.year * 12;
    out.alternative = { ...spec.alternative, ...EF.projectSale(inputs, spec.schedule, m, cfg.hpi_base, cfg) };
    out.alternative.appreciation = out.alternative.homeValue - spec.homeValue;
  }
  if (spec.id === 'renee') {
    out.helocInterest = helocInterestOnSchedule(spec.schedule, out.exitMonth, cfg);
    out.helocPayments = out.exitMonth;
    out.helocCheaperBy = out.costAtExit - out.helocInterest;
  }
  if (spec.id === 'dan') {
    out.refiToll = EF.refiToll(spec.lien, asOf, out.exitMonth, cfg);
  }
  if (spec.id === 'henry') {
    out.boom = spec.homeValue - spec.purchasePrice;
  }
  return out;
}

export function computeStories(cfg = CONFIG) {
  const results = STORIES.map(s => computeStory(s, cfg));
  const bad = results.filter(r => !r.check.ok || !r.eligibility.ok);
  if (bad.length) {
    const why = bad.map(r => `${r.spec.name}: ${[...r.eligibility.reasons, ...r.check.failed].join(', ')}`).join('; ');
    throw new Error(`Story fails the model: ${why}`);
  }
  return results;
}