Lattice Grid Buy a licence

demo D183

Statistical values in a column

A column's median, deviation and percentile, read into computed columns

value.compute

Building…
Loading a live grid…

The configuration

import * as ng from '@angular/core';
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import createLatticeGrid from '@toclocoinc/lattice-grid/modules/angular';

const { LatticeGridComponent } = createLatticeGrid({ ng, createGrid });

const rows = [/* instrument records, each with a price */];

// A column's median, mean, standard deviation and 90th percentile, computed
// once and read into computed columns that sort and filter. The figures match
// the totals row by the same R type 7 percentile definition.
const prices = rows.map((r) => r.price).sort((a, b) => a - b);
const n = prices.length;
const median = n % 2 ? prices[(n - 1) / 2] : (prices[n / 2 - 1] + prices[n / 2]) / 2;
const mean = prices.reduce((s, x) => s + x, 0) / n;
const sd = Math.sqrt(prices.reduce((s, x) => s + (x - mean) ** 2, 0) / n) || 1;
const p90 = prices[Math.floor(0.9 * (n - 1))];

const columns = [
  { field: 'symbol', title: 'Symbol', layout: { pin: 'start', width: 120 } },
  { field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
  { id: 'vsMedian', title: 'vs median', type: 'number', format: { decimals: 4, signed: true },
    value: { deps: ['price'], pure: true, compute: (d) => Math.round((d.price - median) * 1e4) / 1e4 } },
  { id: 'z', title: 'Z-score', type: 'number', format: { decimals: 2, signed: true },
    value: { deps: ['price'], pure: true, compute: (d) => Math.round(((d.price - mean) / sd) * 100) / 100 } },
  { id: 'p90', title: 'over 90th percentile', type: 'boolean',
    value: { deps: ['price'], pure: true, compute: (d) => d.price > p90 } },
];



@Component({
  selector: 'app-root',
  standalone: true,
  imports: [LatticeGridComponent],
  template: '<lattice-grid [config]="grid" style="display:block;height:540px"></lattice-grid>',
})
export class AppComponent {
  grid = {
    rowKey: 'id',
    columns: columns,
    rows: rows,
  };
}

bootstrapApplication(AppComponent);