Lattice Grid

blog

The subprime crisis rebuilt in a data grid, from 100,000 loans up

Most data-heavy screens have the same hidden problem: a number on the top table is computed from a table below it, which is computed from another table below that. Somebody writes the code that copies the numbers upward. Somebody else writes the refresh. Then an input changes and half the screen is stale.

In 2007 the bonds rated AAA lost most of their value, and the mechanism was exactly this shape. Loans were pooled into deals. Deals were cut into tranches. The risky tranches were pooled again into CDOs, and the tranches of those were pooled again into a CDO-squared. Each layer is a table computed from the one below. That is what a data grid with derived grids does, so we rebuilt the whole stack, live, in the browser. Two demos, both plain JavaScript with the grid loaded from the CDN.

The desk: move a slider, every layer follows

The structured-credit desk holds 100,000 synthetic mortgages in 25 deals, 13 tranches per deal, three mezzanine CDOs and a CDO-squared. There are sliders for the house-price fall, the default rate and default correlation. While you drag, every tranche shows its expected loss and implied rating. When you let go, the 100,000 loans recompute and the change flows up through every layer, the charts and the KPI tiles.

Two presets tell the story in numbers. Under the rating-agency assumptions (a 2% fall, half the base default rate, low correlation) the CDO’s Senior AAA loses nothing. At what happened, the real 27% fall in house prices at a calibrated correlation, it loses about 92% of its value over the loans’ lifetime.

There is also a “one loss, six layers” box. Type a pool loss of 12% on every deal and the same waterfall levers it up: the BBB bonds are wiped out, the CDO loses 67% of its collateral, and the loss still reaches the AAA tranches.

Why correlation moves AAA more than anything

A senior tranche is safe only if the loans fail independently. If each one has a 5% chance of defaulting and they fail separately, the pool loss is steady and close to 5%, and the senior layers never see it. If the loans fail together, because the same house-price fall hits all of them, the pool is either fine or in deep trouble, and the deep trouble is large enough to reach the top. Averaged over every possible market, correlation hardly changes the pool’s expected loss. It changes how often the bad case arrives, and the bad case is the only one a senior tranche cares about.

The desk’s 27% house-price fall is that bad case. With correlation at 0 the loans ignore it: the pool loses 5.7% and the Senior AAA is untouched. At the calibrated 0.15 the pool loses 25% and the Senior AAA loses about 92%. Drag the slider between the two and watch the top of the stack go from safe to gone.

The replay: 2006 to 2009, one month at a time

The replay runs the same structure over a live feed. Press Play and one month arrives at a time. Loans fall behind and default, and ratings begin to fall from July 2007, BBB first. Scrub back to any month and every number shows that month.

By December 2009 the three CDOs’ Senior AAA tranches are written down 69% to 71%, close to the published average of 67% for 2006 deals.

The two demos give different numbers for a plain reason. The replay counts the losses realised by December 2009. The desk counts the losses the loans will incur over their whole life, so it shows more.

How it is built, part one: derived grids

The desk has exactly one place where data comes in, the loans grid, fed through a Data Router. Every layer above it is a derived grid: a grid whose rows are computed from other grids and which recomputes when they change.

const loans = LatticeGrid.createGrid(el, { rowKey: 'id', columns: loanColumns, rows: [] });
const router = LatticeGridDataRouter.createDataRouter({ key: 'kind', rowKey: 'id' });
router.attach(loans, 'loan');
router.addSource('loan').load(allLoans);          // 100,000 rows

const deals = LatticeGrid.createGrid(el, {
  source: { mode: 'derived', from: loans, follow: 'all', groupBy: 'deal',
    select: { poolBal: { of: 'origBal', fn: 'sum' }, poolLoss: { of: 'loss', fn: 'sum' } } },
  columns: [/* deal, pool, loss ... */],
});

const rmbsTranches = LatticeGrid.createGrid(el, {
  source: { mode: 'derived', from: trancheTerms, follow: 'all',
    join: { with: deals, on: { left: 'deal', right: 'deal' }, type: 'left',
            select: ['poolBal', 'poolLoss'] } },
  columns: [
    { id: 'lossPct', title: 'Loss %', type: 'number',
      value: { deps: ['poolLoss', 'poolBal', 'attach', 'detach'],
               compute: (d) => 100 * trancheLoss(100 * d.poolLoss / d.poolBal, d.attach, d.detach) } },
  ],
});

A deal is a groupBy over its loans. A tranche is a term sheet joined to its deal, with the waterfall in a computed column. The waterfall is one line: a tranche that attaches at A and detaches at D loses min(max(L - A, 0), D - A) / (D - A) of its size, where L is the loss of the pool beneath it.

Upwards, the same two moves repeat. A join to the tranches gives the bonds each CDO holds, a groupBy gives the CDO, a join gives its tranches, and again for the CDO-squared. A join’s select can read a computed column from the grid it joins to, which is how one tranche’s loss becomes the next layer’s bond loss. When a slider is released the page sends the changed loans to the router as partial rows, and the router merges them into the stored loans:

router.apply(changed.map((k) => ({ op: 'upsert',
  row: { id: loanId(k), kind: 'loan', defaulted: def[k], loss: loss[k] } })));

How it is built, part two: join sources in the router

The replay puts the layers inside the router instead. Each layer is a join source: an aggregate over many rows, or a join function over one.

const sum = (field) => ({ fn: 'sum', field });
router.addSource('loan');
router.addSource('deal', { join: { from: 'loan', foreignKey: 'deal', many: true,
  aggregate: { poolBal: sum('issuedBal'), poolLoss: sum('loss') } } });

router.addSource('tranche', { join: { from: 'deal', localKey: 'deal', foreignKey: 'id',
  fields: (deal, tranche) => {
    const L = 100 * deal.poolLoss / deal.poolBal;
    const f = trancheLoss(L, tranche.attach, tranche.detach);
    return { lossPct: 100 * f };
  } } });

The same two moves build everything above: holdings, CDOs, CDO tranches and the CDO-squared. Then a month is one call:

socket.onmessage = (ev) => router.apply(JSON.parse(ev.data).changes);

What the page does not contain

There is no code that copies numbers between tables, and no refresh logic. The page sends changed loans in; the layers recompute themselves. The drill-down from a CDO tranche to its bonds to their loans is master-detail, nested three levels deep. The charts are bound to grids, so the FICO and loan-to-value histograms follow the loans grid’s filter when you pick a tranche. The KPI tiles read single cells of the tranche grids.

Where else this shape appears

Any roll-up of a roll-up.

  • Funds. Positions roll up to a portfolio, portfolios to a fund, funds to a fund of funds.
  • Manufacturing. Parts roll up to assemblies and assemblies to products, so a bill of materials gets a cost at every level.
  • Logistics. Shipments roll up to routes and routes to regions.
  • Finance teams. Cost centres roll up to divisions, and divisions to the group.

In each, the lower table changes and every table above it should change with it, without anyone writing the copy.

About the data

The loans and deals are synthetic and seeded, calibrated to published research, mainly Ashcraft and Schuermann (2008) and Cordell, Huang and Williams (2012). The house prices are the real Case-Shiller series. The CDO structures are illustrative, with only two attachment points taken from the research. The demos are for illustration and are not investment advice.

Try it

Open the desk and drag the correlation slider, then the replay and scrub back to July 2007. The code is in two repos: the desk and the replay. To read more, see the Data Router and the derived grids guide.

Read next

All posts RSS