Lattice Grid Buy a licence

demo D210

A trading book

Money units, shadow columns, a running P&L and a live feed, in one grid

createUnitType · shadow · running · statistics

Building…
Loading a live grid…

The configuration

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">

<div id="grid" style="height: 520px"></div>

<script type="module">
  import { createGrid, registerUnitSystem, defineUnit, createUnitType } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/htmx.esm.js';

  // A money unit family: the pound, with thousands and millions on the auto ladder.
  registerUnitSystem('gbp', [
    defineUnit('£',  1,   ['gbp']),
    defineUnit('k£', 1e3, [], { prefix: 'k' }),
    defineUnit('M£', 1e6, [], { prefix: 'M' }),
  ]);
  const money     = createUnitType({ system: 'gbp', unit: '£', placement: 'prefix', decimals: 2 });
  const moneyAuto = createUnitType({ system: 'gbp', unit: '£', placement: 'prefix', display: 'auto' });

  const grid = createGrid(document.getElementById('grid'), {
    rowKey: 'id',
    highlightOnChange: { duration: 500 },
    dataTypes: { money, moneyAuto },
    toolPanel: { side: 'left', panels: ['columns', 'filters', 'statistics'] },
    columns: [
      { field: 'instrument', title: 'Instrument', layout: { pin: 'start', width: 120 } },
      { field: 'desk', title: 'Desk', filter: { type: 'set' } },
      { field: 'notional', title: 'Notional', type: 'moneyAuto', total: 'sum' },
      { field: 'price', title: 'Price', type: 'money' },
      { field: 'spread', title: 'Spread', type: 'number', format: { decimals: 1, suffix: ' bp' }, total: 'median' },
      { field: 'pnl', title: 'P&L', type: 'money', total: 'sum' },
      // Shadow and running columns, kept up to date by the grid: the move since
      // the last price, the rank by P&L, each book's share of the total, and a
      // running P&L down the sorted rows.
      { id: 'moved', title: 'Change', shadow: { of: 'price', kind: 'delta' }, type: 'number', format: { signed: true } },
      { id: 'rank',  title: 'Rank', shadow: { of: 'pnl', kind: 'rank' }, type: 'number' },
      { id: 'share', title: 'Share %', shadow: { of: 'notional', kind: 'shareOfTotal' }, type: 'number', format: { style: 'percent', decimals: 1 } },
      { id: 'cum',   title: 'Cum. P&L', running: { of: 'pnl', kind: 'total' }, type: 'money' },
    ],
    formatting: {
      pnl: [{ when: { op: 'lt', value: 0 }, style: { color: '#a4262c' } }],
    },
    state: { sort: [{ col: 'pnl', dir: 'desc' }] },
    rows,  // trading book records
  });
</script>