Lattice Grid Buy a licence

demo D182

Correlation and weighted averages

Two-column figures from the API, over the filtered rows

grid.statistics.correlation(a, b)

Building…
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: 460px"></div>
<pre id="out" style="margin-top: 12px"></pre>

<script>
  const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
    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,
  });

  const out = document.getElementById('out');
  const report = () => {
    out.textContent = 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>