demo D182
Correlation and weighted averages
Two-column figures from the API, over the filtered rows
grid.statistics.correlation(a, b)
Loading a live grid…
The configuration
<script>
import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.esm.min.js';
import createLatticeAction from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/svelte.esm.min.js';
const lattice = createLatticeAction({ createGrid });
let out = '';
const config = {
rowKey: 'id',
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number' },
{ field: 'bid', title: 'Bid', type: 'number' },
{ field: 'volume', title: 'Volume', type: 'number' },
{ field: 'notional', title: 'Notional', type: 'number',
format: { style: 'currency', currency: 'USD' }, total: 'sum' },
],
rows,
// onGrid hands over the live grid the moment it is created. Correlation,
// regression and a volume-weighted average are read straight from the grid
// and follow the filters: narrow to one desk and every figure moves.
onGrid: (grid) => {
const report = () => {
out = JSON.stringify({
correlation: grid.statistics.correlation('price', 'bid'),
regression: grid.statistics.regression('price', 'bid'),
weighted: grid.statistics.weightedAverage('price', 'volume'),
}, null, 2);
};
grid.on('filter:changed', report); // every figure follows the filters
report();
},
};
</script>
<svelte:head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">
</svelte:head>
<div use:lattice={config} style="height: 460px"></div>
<pre style="margin-top: 12px">{out}</pre>