@livefolio/sdk / defineFeature
Function: defineFeature()
defineFeature<
K>(kind,compute):void
Defined in: features/spec.ts:82
Registers a compute function for a new or existing feature kind.
Throws if kind is already registered. Call this once at module initialisation time (top-level) to extend the built-in feature registry with custom indicators. The compute function receives the raw price Series and the full typed spec object for that kind; it must return a Series of the same or shorter length.
Type Parameters
| Type Parameter |
|---|
K extends "price" | "sma" | "ema" | "rsi" | "return" | "volatility" | "drawdown" |
Parameters
| Parameter | Type | Description |
|---|---|---|
kind | K | The FeatureKind string that identifies this indicator. |
compute | (series, spec) => Series | Pure function that transforms a price series according to spec. The spec argument is narrowed to Extract<FeatureSpec, { kind: K }> so TypeScript enforces that only the correct parameter shape is accessed. |
Returns
void
void. Registration is a side-effectful, one-time operation.
Example
ts
import { defineFeature } from '@livefolio/sdk';
// Register a custom 'zscore' feature kind
defineFeature('sma', (series, spec) => {
// Already built-in; this would throw due to duplicate registration.
// Shown here for illustration only.
return series;
});