@livefolio/sdk / fromSpec
Function: fromSpec()
fromSpec(
spec,opts):Strategy<TacticalFeatures,RuleTreeState>
Defined in: tactical/from-spec.ts:151
Hydrates a plain TacticalSpec data object into a runnable Strategy that runBacktest can drive step-by-step.
State is threaded explicitly through build via the `Strategy<F, S>.build` signature. initialState() returns an empty RuleTreeState Map; the runtime is responsible for storing and forwarding the state between calls. This design makes build a pure function of its inputs — calling it twice with identical arguments produces identical outputs, enabling snapshot/restore for preview-builds in live mode.
Validation performed at construction time:
- A
'tactical/v0'kindemits a one-time deprecation warning toconsole.warn. - Synthetic assets are checked for self-reference, symbol collisions, and missing universe entries (see internal
validateSynthetics).
Parameters
| Parameter | Type | Description |
|---|---|---|
spec | TacticalSpec | The declarative strategy spec. |
opts | FromSpecOptions | Runtime dependencies (feature backend and calendar). |
Returns
Strategy<TacticalFeatures, RuleTreeState>
A Strategy whose features method fetches indicator values and whose build method converts them to rebalance orders.
Example
import { fromSpec, MemoryFeatureCache, NYSEExchangeCalendar } from '@livefolio/sdk';
import { FeatureRuntime } from '@livefolio/sdk/features';
const calendar = new NYSEExchangeCalendar();
const cache = new MemoryFeatureCache();
const runtime = new FeatureRuntime({ feed: myDataFeed, cache });
const strategy = fromSpec(mySpec, { runtime, calendar });