demo D210
A trading book
Money units, shadow columns, a running P&L and a live feed, in one grid
createUnitType · shadow · running · statistics
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.13.0/lattice-grid.min.css">
<script src="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.13.0/lattice-grid.min.js"></script>
<div id="grid" style="height: 520px"></div>
<script>
// A money unit family: the pound, with k£ and M£ on the auto ladder.
LatticeGrid.registerUnitSystem('gbp', [
LatticeGrid.defineUnit('£', 1, ['gbp']),
LatticeGrid.defineUnit('k£', 1e3, [], { prefix: 'k' }),
LatticeGrid.defineUnit('M£', 1e6, [], { prefix: 'M' }),
]);
const money = LatticeGrid.createUnitType({ system: 'gbp', unit: '£', placement: 'prefix', decimals: 2 });
const moneyAuto = LatticeGrid.createUnitType({ system: 'gbp', unit: '£', placement: 'prefix', display: 'auto' });
const grid = LatticeGrid.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, maintained by the grid.
{ 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: 'climb', title: 'Moved', shadow: { of: 'pnl', kind: 'rankChange' }, type: 'number', format: { signed: true } },
{ 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: 'climb', dir: 'desc' }] },
rows, // trading book records
});
</script>