demo D194
Variation along an ordering in Angular
Volatility, growth and drawdown, from rows loaded out of order
grid.statistics.series(col, { by })
This grid computes volatility, growth and drawdown along an ordering, even from rows loaded out of order. It reads a series' behaviour over its own sequence, so trend and swings surface without the data arriving pre-sorted.
This is the Angular version. A standalone component takes the whole configuration through one config input, surfaces grid events as outputs, and exposes the live grid on a getter for anything the inputs do not cover.
The configuration
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';
const columns = [
{ field: 'date', title: 'Date', type: 'dateString', layout: { pin: 'start', width: 150 } },
{ field: 'price', title: 'Price', type: 'number' },
];
@Component({
selector: 'app-root',
standalone: true,
imports: [LatticeGridComponent],
template:
'<lattice-grid [config]="grid" (filter-changed)="report()" style="display:block;height:460px"></lattice-grid>' +
'<pre style="margin-top:12px">{{ out }}</pre>',
})
export class AppComponent implements AfterViewInit {
@ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;
out = '';
grid = {
rowKey: 'id',
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns,
rows: [/* a dated price series */],
};
// by is required: the series reads rows as loaded, not in the grid's sort.
// Every figure is over the filtered rows, so narrowing the range moves them.
report() {
const grid = this.gridRef && this.gridRef.grid;
if (!grid) return;
this.out = JSON.stringify(grid.statistics.series('price', { by: 'date', periodsPerYear: 252 }), null, 2);
}
ngAfterViewInit() { this.report(); }
}
bootstrapApplication(AppComponent, {
providers: [provideLattice({ createGrid })],
});