UNPKG

kestrel.markets

Version:

A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.

56 lines 3.06 kB
/** * # bus/synthetic — a seeded, deterministic synthetic session generator (public test substrate) * * A publication-safe substrate for grading, replay, and engine tests: given a seed and a few * session parameters, it emits a **full bus** — `META`, `SPOT` ticks along a seeded random * walk with **regime segments** (trend / chop / spike), an option `BOOK` around spot whose * spreads widen on velocity and that occasionally goes one-sided or dark, and `HEARTBEAT` * cadence events. It reveals no strategy and no real market data (ARCHITECTURE §7): tickers * are generic and the tape is pure PRNG. * * **Determinism (RUNTIME §0):** all randomness is a single {@link mulberry32} stream seeded * from the config; all time is derived from `date` + bar index (no wall clock). The same * config therefore yields a byte-identical bus — the same events in the same order with the * same `seq`. Feed the result through {@link ../bus/write.ts serializeBus} to get the bytes. */ import type { BusEvent } from "./types.ts"; import { type Mode } from "./types.ts"; export interface SyntheticConfig { /** Seeds the single PRNG stream — the sole source of randomness. */ readonly seed: number; /** Session calendar date, `YYYY-MM-DD`. Anchors every timestamp deterministically. */ readonly date: string; /** The underlier symbol (generic only: `SPX` / `SPY` / `QQQ` / `AAPL`). */ readonly instrument: string; /** Opening spot. */ readonly spot0: number; /** Per-bar volatility as a return fraction (e.g. `0.0008`). Scaled by the active regime. */ readonly vol: number; /** Session length in minutes. */ readonly sessionMinutes: number; /** Bar cadence in seconds — one SPOT (and one BOOK, if options) per bar. */ readonly barSeconds: number; /** Order mode stamped on META. Default `sim`. */ readonly mode?: Mode; /** Emit an option BOOK each bar. `false` ⇒ an equity-only session (SPOT tape, no legs). * Default `true`. */ readonly withOptions?: boolean; /** Strikes each side of the money (total legs = `(2·strikes + 1)·2` C+P). Default 3. */ readonly strikes?: number; /** Strike grid step. Default 1. */ readonly strikeStep?: number; /** The expiry tag stamped on each BOOK (e.g. `0dte`). Default `0dte`. */ readonly expiry?: string; /** Heartbeat cadence in seconds. Default 60. */ readonly heartbeatEverySeconds?: number; } /** A mulberry32 PRNG: 32-bit-seeded, uniform in [0,1). Pure, fast, fully reproducible — * the one randomness source on this deterministic path (no unseeded RNG, RUNTIME §0). */ export declare function mulberry32(seed: number): () => number; /** * Generate a full synthetic session as an in-order, `seq`-stamped {@link BusEvent} array. * Serialize with {@link ../bus/write.ts serializeBus} (or {@link ../bus/write.ts writeBusFile}). * Same config ⇒ byte-identical output. */ export declare function generateSession(cfg: SyntheticConfig): readonly BusEvent[]; //# sourceMappingURL=synthetic.d.ts.map