← Back to Pull requests

0.2.0 (6/17): Markets from the backlog #55

Merged
ramiz-rahman merged 31 files (2531 lines) on Nov 30, 2026 12:51 UTC
View on GitHub
ramiz-rahman ramiz-rahman commented on Nov 29, 2026 04:43 UTC
Author

Markets' backlog sweep.

9 commits. Part of the 0.2.0 stack: merge in order, each after the one it is based on.

Checks

  • pnpm verify passes (the full run at the top of the stack; verify --quick at this PR's own tip)

  • A change people will notice is in CHANGELOG.md (0.2.0's section, in 17/17) and in docs/MIGRATION.md where code must change

  • A changed page is in packages/jali/docs too
  • Diff: 2531 lines (+1786 / -745) across 31 files Reviewer: ramiz-rahman Review duration: 1927m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.91) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.91 · 2531 lines diff across 31 files
    0.91
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.85 · 5 substantive comment(s)
    0.85
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Self Review self_review
    0.140
    Mass File Touch mass_file_touch
    0.080
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    10 items
    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 29, 2026 04:44 UTC
    Bot

    <!-- codex-pull-request-review-summary -->
    <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f48bdae6803a336644230ff8cf9e9ee4ae4d45d9","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->

    <details>
    <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

    This comment shows the latest Codex review activity on this pull request.

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-29T04:46:13.543752Z">2026-11-29T04:46:13.543752Z</relative-time> | f48bdae | PR opened |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 29, 2026 04:46 UTC
    Reviewer

    <!-- codex-review-receipt:v1 -->

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: f48bdae680

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 29, 2026 04:46 UTC
    Code Review
    examples/markets/src/market/sim/index.ts:1
    @@ -39,163 +41,274 @@ export interface Simulator extends MarketData {
       step(count?: number): void;
       /** The market's clock, ms since the epoch. */
       now(): number;
    -  /** When today's session opened. */
    -  readonly sessionOpen: number;
    -  /** Step in real time until the returned function is called. */
    +  /** Follow the real clock until the returned function is called. */
       run(): () => void;
     }
     
    +/** Recent trades kept for a tape, and how far back one is filled when first asked for. */
     const TAPE = 200;
    +const TAPE_SLOTS = 40;
     const MAX_NEWS = 300;
     
     export function createSimulator(options: SimulatorOptions = {}): Simulator {
       const seed = options.seed ?? 1;
       const tickMs = options.tickMs ?? 250;
    +  const TICKS = SLOT_MS / tickMs;
    +  if (!Number.isInteger(TICKS)) throw new RangeError("tickMs must divide 15,000");
       const instruments = options.instruments ?? INSTRUMENTS;
    -  const r = createRandom(seed);
    -
    -  const start = options.start ?? todayAt(13, 40);
    -  const sessionOpen = new Date(start).setHours(9, 30, 0, 0);
    -  let now = sessionOpen;
    -  let tradeId = 0;
    -  let newsId = 0;
    -  const news: Headline[] = [];
    -  let freshNews: Headline[] = [];
    +  const model = createModel(seed, instruments);
    +  const dailyBar = createDailyBars(model);
     
    -  const lives = createLives(instruments, seed);
    +  const lives = new Map(instruments.map((i) => [i.symbol, createLive(i)]));
       const all = [...lives.values()];
    -  const sectors = [
    -    ...new Set(all.flatMap((l) => (l.inst.assetClass === "equity" ? l.inst.sector : []))),
    -  ];
    +  const members = all.filter((l) => l.inst.assetClass !== "index");
    +  const indices = all.filter((l) => l.inst.assetClass === "index");
    +  const price = (l: Live, level: number) => model.priceOf(l.inst, level);
     
    -  // ---------- one step of market time ----------
    +  let now = options.start ?? Date.now();
    +  let day = Number.NaN;
    +  /** Headlines out so far (newest first), those still to come today (oldest first), and those new this tick. */
    +  let news: Headline[] = [];
    +  let upcoming: Headline[] = [];
    +  let freshNews: Headline[] = [];
     
    -  function advance(dtMs: number, detailed: boolean) {
    -    const dt = dtMs / 1000;
    -    now += dtMs;
    -    const shocks = drawShocks(r, sectors);
    -    const activity = intradayShape((now - sessionOpen) / MINUTE);
    +  // ---------- a day ----------
     
    +  function setDay(d: number) {
    +    day = d;
    +    model.pin(d);
         for (const l of all) {
    +      l.day = d;
    +      l.path = model.pathOf(l.inst, d);
    +      l.cum = totals(l);
    +      l.slot = -1;
    +    }
    +    minuteBars.clear();
    +    // Yesterday's news and today's, each numbered by its day so a headline keeps its id.
    +    const numbered = (items: Dated[], of: number): Headline[] =>
    +      items.map(({ time, draft }, i) => ({ id: of * 1000 + i, time, ...draft }));
    +    const items = [
    +      ...numbered(newsOf({ model, instruments }, d - 1, false), d - 1),
    +      ...numbered(newsOf({ model, instruments }, d, true), d),
    +    ];
    +    news = items
    +      .filter((h) => h.time <= now)
    +      .reverse()
    +      .slice(0, MAX_NEWS);
    +    upcoming = items.filter((h) => h.time > now);
    +    freshNews = [...news];
    +  }
    +
    +  /** Before each slot: the day's volume, turnover, and highest and lowest price so far. */
    +  function totals(l: Live): Live["cum"] {
    +    const { at, hi, lo, volume } = l.path;
    +    const cum = {
    +      volume: new Float64Array(SLOTS + 1),
    +      turnover: new Float64Array(SLOTS + 1),
    +      high: new Float64Array(SLOTS + 1),
    +      low: new Float64Array(SLOTS + 1),
    +    };
    +    const open = price(l, at[0]!);
    +    cum.high[0] = open;
    +    cum.low[0] = open;
    +    for (let k = 0; k < SLOTS; k++) {
    +      const [low, high] = model.priceRange(l.inst, lo[k]!, hi[k]!);
    +      cum.volume[k + 1] = cum.volume[k]! + volume[k]!;
    +      cum.turnover[k + 1] = cum.turnover[k]! + volume[k]! * price(l, (at[k]! + at[k + 1]!) / 2);
    +      cum.high[k + 1] = Math.max(cum.high[k]!, high);
    +      cum.low[k + 1] = Math.min(cum.low[k]!, low);
    +    }
    +    return cum;
    +  }
    +
    +  // ---------- a slot ----------
    +
    +  /** The slot's levels, tick by tick: from its start to its end, wandering inside its range. */
    +  function microOf(l: Live, k: number): Float64Array {
    +    const { at, hi, lo } = l.path;
    +    const a = at[k]!;
    +    const b = at[k + 1]!;
    +    const r = createRandom(seedOf(seed, 31, l.h, day, k));
    +    const sd = (model.slotVol(l.inst, k, a) / Math.sqrt(TICKS)) * 0.8;
    +    const walk = new Float64Array(TICKS + 1);
    +    for (let j = 1; j <= TICKS; j++) walk[j] = walk[j - 1]! + sd * r.gauss();
    +    const micro = new Float64Array(TICKS + 1);
    +    for (let j = 0; j <= TICKS; j++) {
    +      const x = a + ((b - a) * j) / TICKS + walk[j]! - (walk[TICKS]! * j) / TICKS;
    +      micro[j] = Math.min(hi[k]!, Math.max(lo[k]!, x));
    +    }
    +    return micro;
    +  }
    +
    +  /** The slot's trades: how many as busy as the hour is, sizes adding up to its volume, leaning with its move. */
    +  function printsOf(l: Live, k: number): Print[] {
    +    if (!l.rate) return [];
    +    const r = createRandom(seedOf(seed, 32, l.h, day, k));
    +    const n = Math.min(80, r.poisson(l.rate * SHAPE[k]! * (SLOT_MS / 1000)));
    +    if (!n) return [];
    +    const weights = Array.from({ length: n }, () => Math.exp(0.9 * r.gauss() - 0.4));
    +    const sum = weights.reduce((s, w) => s + w, 0);
    +    const { at } = l.path;
    +    const rise = price(l, at[k + 1]!) - price(l, at[k]!);
    +    const lean = Math.max(-0.3, Math.min(0.3, rise / (price(l, at[k]!) * 0.0004 + 1e-12)));
    +    const ticks = Array.from({ length: n }, () => r.int(0, TICKS - 1)).sort((a, b) => a - b);
    +    return ticks.map((tick, i) => ({
    +      tick,
    +      side: r.next() < 0.5 + lean ? "buy" : "sell",
    +      size: Math.max(l.lot, Math.round((l.path.volume[k]! * weights[i]!) / sum / l.lot) * l.lot),

    <sub><sub>!P2 Badge</sub></sub> Reconcile trade sizes with the slot's historical volume

    When a slot contains trades smaller than the minimum lot, independently rounding and clamping every print makes their total exceed l.path.volume[k]. The live quote accumulates those actual sizes, but at the next slot it replaces that total with the model's volume, so today's volume decreases and completed bars disagree with the tape. Reproduced with seed 7 starting at 2026-11-19 11:45 UTC: EURUSD volume drops by about 2.7 million at 11:45:15. Allocate lot-sized prints and historical volume from a shared total so crossing a slot cannot remove previously reported volume.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 29, 2026 04:46 UTC
    Code Review
    examples/markets/src/market/sim/index.ts:1
    @@ -39,163 +41,274 @@ export interface Simulator extends MarketData {
       step(count?: number): void;
       /** The market's clock, ms since the epoch. */
       now(): number;
    -  /** When today's session opened. */
    -  readonly sessionOpen: number;
    -  /** Step in real time until the returned function is called. */
    +  /** Follow the real clock until the returned function is called. */
       run(): () => void;
     }
     
    +/** Recent trades kept for a tape, and how far back one is filled when first asked for. */
     const TAPE = 200;
    +const TAPE_SLOTS = 40;
     const MAX_NEWS = 300;
     
     export function createSimulator(options: SimulatorOptions = {}): Simulator {
       const seed = options.seed ?? 1;
       const tickMs = options.tickMs ?? 250;
    +  const TICKS = SLOT_MS / tickMs;
    +  if (!Number.isInteger(TICKS)) throw new RangeError("tickMs must divide 15,000");
       const instruments = options.instruments ?? INSTRUMENTS;
    -  const r = createRandom(seed);
    -
    -  const start = options.start ?? todayAt(13, 40);
    -  const sessionOpen = new Date(start).setHours(9, 30, 0, 0);
    -  let now = sessionOpen;
    -  let tradeId = 0;
    -  let newsId = 0;
    -  const news: Headline[] = [];
    -  let freshNews: Headline[] = [];
    +  const model = createModel(seed, instruments);
    +  const dailyBar = createDailyBars(model);
     
    -  const lives = createLives(instruments, seed);
    +  const lives = new Map(instruments.map((i) => [i.symbol, createLive(i)]));
       const all = [...lives.values()];
    -  const sectors = [
    -    ...new Set(all.flatMap((l) => (l.inst.assetClass === "equity" ? l.inst.sector : []))),
    -  ];
    +  const members = all.filter((l) => l.inst.assetClass !== "index");
    +  const indices = all.filter((l) => l.inst.assetClass === "index");
    +  const price = (l: Live, level: number) => model.priceOf(l.inst, level);
     
    -  // ---------- one step of market time ----------
    +  let now = options.start ?? Date.now();
    +  let day = Number.NaN;
    +  /** Headlines out so far (newest first), those still to come today (oldest first), and those new this tick. */
    +  let news: Headline[] = [];
    +  let upcoming: Headline[] = [];
    +  let freshNews: Headline[] = [];
     
    -  function advance(dtMs: number, detailed: boolean) {
    -    const dt = dtMs / 1000;
    -    now += dtMs;
    -    const shocks = drawShocks(r, sectors);
    -    const activity = intradayShape((now - sessionOpen) / MINUTE);
    +  // ---------- a day ----------
     
    +  function setDay(d: number) {
    +    day = d;
    +    model.pin(d);
         for (const l of all) {
    +      l.day = d;
    +      l.path = model.pathOf(l.inst, d);
    +      l.cum = totals(l);
    +      l.slot = -1;
    +    }
    +    minuteBars.clear();
    +    // Yesterday's news and today's, each numbered by its day so a headline keeps its id.
    +    const numbered = (items: Dated[], of: number): Headline[] =>
    +      items.map(({ time, draft }, i) => ({ id: of * 1000 + i, time, ...draft }));
    +    const items = [
    +      ...numbered(newsOf({ model, instruments }, d - 1, false), d - 1),
    +      ...numbered(newsOf({ model, instruments }, d, true), d),
    +    ];
    +    news = items
    +      .filter((h) => h.time <= now)
    +      .reverse()
    +      .slice(0, MAX_NEWS);
    +    upcoming = items.filter((h) => h.time > now);
    +    freshNews = [...news];
    +  }
    +
    +  /** Before each slot: the day's volume, turnover, and highest and lowest price so far. */
    +  function totals(l: Live): Live["cum"] {
    +    const { at, hi, lo, volume } = l.path;
    +    const cum = {
    +      volume: new Float64Array(SLOTS + 1),
    +      turnover: new Float64Array(SLOTS + 1),
    +      high: new Float64Array(SLOTS + 1),
    +      low: new Float64Array(SLOTS + 1),
    +    };
    +    const open = price(l, at[0]!);
    +    cum.high[0] = open;
    +    cum.low[0] = open;
    +    for (let k = 0; k < SLOTS; k++) {
    +      const [low, high] = model.priceRange(l.inst, lo[k]!, hi[k]!);
    +      cum.volume[k + 1] = cum.volume[k]! + volume[k]!;
    +      cum.turnover[k + 1] = cum.turnover[k]! + volume[k]! * price(l, (at[k]! + at[k + 1]!) / 2);
    +      cum.high[k + 1] = Math.max(cum.high[k]!, high);
    +      cum.low[k + 1] = Math.min(cum.low[k]!, low);

    <sub><sub>!P2 Badge</sub></sub> Include executable trade prices in completed-slot extrema

    For instruments whose spread extends beyond a slot's modeled mid-price range, trades can set highs or lows outside these cumulative bounds. Once the slot finishes, its actual extrema are discarded in favor of these bounds, making the day's range shrink and completed chart bars exclude trades that appeared on the tape. With seed 7 starting at midnight UTC on 2026-11-19, GOV10Y's reported high falls from 98.649 to 98.6487505187439 at 00:00:30, and its low rises at 00:01:00. Derive completed-slot extrema from the same bid/ask prints used by the live slot.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 29, 2026 04:46 UTC
    Code Review
    examples/markets/src/market/sim/index.ts:1
    @@ -39,163 +41,274 @@ export interface Simulator extends MarketData {
       step(count?: number): void;
       /** The market's clock, ms since the epoch. */
       now(): number;
    -  /** When today's session opened. */
    -  readonly sessionOpen: number;
    -  /** Step in real time until the returned function is called. */
    +  /** Follow the real clock until the returned function is called. */
       run(): () => void;
     }
     
    +/** Recent trades kept for a tape, and how far back one is filled when first asked for. */
     const TAPE = 200;
    +const TAPE_SLOTS = 40;
     const MAX_NEWS = 300;
     
     export function createSimulator(options: SimulatorOptions = {}): Simulator {
       const seed = options.seed ?? 1;
       const tickMs = options.tickMs ?? 250;
    +  const TICKS = SLOT_MS / tickMs;
    +  if (!Number.isInteger(TICKS)) throw new RangeError("tickMs must divide 15,000");
       const instruments = options.instruments ?? INSTRUMENTS;
    -  const r = createRandom(seed);
    -
    -  const start = options.start ?? todayAt(13, 40);
    -  const sessionOpen = new Date(start).setHours(9, 30, 0, 0);
    -  let now = sessionOpen;
    -  let tradeId = 0;
    -  let newsId = 0;
    -  const news: Headline[] = [];
    -  let freshNews: Headline[] = [];
    +  const model = createModel(seed, instruments);
    +  const dailyBar = createDailyBars(model);
     
    -  const lives = createLives(instruments, seed);
    +  const lives = new Map(instruments.map((i) => [i.symbol, createLive(i)]));
       const all = [...lives.values()];
    -  const sectors = [
    -    ...new Set(all.flatMap((l) => (l.inst.assetClass === "equity" ? l.inst.sector : []))),
    -  ];
    +  const members = all.filter((l) => l.inst.assetClass !== "index");
    +  const indices = all.filter((l) => l.inst.assetClass === "index");
    +  const price = (l: Live, level: number) => model.priceOf(l.inst, level);
     
    -  // ---------- one step of market time ----------
    +  let now = options.start ?? Date.now();
    +  let day = Number.NaN;
    +  /** Headlines out so far (newest first), those still to come today (oldest first), and those new this tick. */
    +  let news: Headline[] = [];
    +  let upcoming: Headline[] = [];
    +  let freshNews: Headline[] = [];
     
    -  function advance(dtMs: number, detailed: boolean) {
    -    const dt = dtMs / 1000;
    -    now += dtMs;
    -    const shocks = drawShocks(r, sectors);
    -    const activity = intradayShape((now - sessionOpen) / MINUTE);
    +  // ---------- a day ----------
     
    +  function setDay(d: number) {
    +    day = d;
    +    model.pin(d);
         for (const l of all) {
    +      l.day = d;
    +      l.path = model.pathOf(l.inst, d);
    +      l.cum = totals(l);
    +      l.slot = -1;
    +    }
    +    minuteBars.clear();
    +    // Yesterday's news and today's, each numbered by its day so a headline keeps its id.
    +    const numbered = (items: Dated[], of: number): Headline[] =>
    +      items.map(({ time, draft }, i) => ({ id: of * 1000 + i, time, ...draft }));
    +    const items = [
    +      ...numbered(newsOf({ model, instruments }, d - 1, false), d - 1),
    +      ...numbered(newsOf({ model, instruments }, d, true), d),

    <sub><sub>!P2 Badge</sub></sub> Preserve headline IDs when rebuilding yesterday's news

    At midnight, yesterday's headlines are regenerated with wraps=false, whereas they were originally numbered with wraps=true. Removing the intraday reports shifts the positional IDs of subsequent stories, so an existing ID can identify a different headline. Reproduced across midnight after 2026-11-19 with seed 7: ID 20776006 changes from “Pixelry completes a small acquisition” to the market-close report. Since panes/news.tsx stores the expanded story by h.id, a reader's open story can silently switch to unrelated content. Assign IDs independently of the filtered list, or retain the same headline list when rebuilding the previous day.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    ramiz-rahman ramiz-rahman commented on code on Nov 30, 2026 12:21 UTC
    Code Review
    examples/markets/src/market/sim/index.ts:1
    @@ -39,163 +41,274 @@ export interface Simulator extends MarketData {
       step(count?: number): void;
       /** The market's clock, ms since the epoch. */
       now(): number;
    -  /** When today's session opened. */
    -  readonly sessionOpen: number;
    -  /** Step in real time until the returned function is called. */
    +  /** Follow the real clock until the returned function is called. */
       run(): () => void;
     }
     
    +/** Recent trades kept for a tape, and how far back one is filled when first asked for. */
     const TAPE = 200;
    +const TAPE_SLOTS = 40;
     const MAX_NEWS = 300;
     
     export function createSimulator(options: SimulatorOptions = {}): Simulator {
       const seed = options.seed ?? 1;
       const tickMs = options.tickMs ?? 250;
    +  const TICKS = SLOT_MS / tickMs;
    +  if (!Number.isInteger(TICKS)) throw new RangeError("tickMs must divide 15,000");
       const instruments = options.instruments ?? INSTRUMENTS;
    -  const r = createRandom(seed);
    -
    -  const start = options.start ?? todayAt(13, 40);
    -  const sessionOpen = new Date(start).setHours(9, 30, 0, 0);
    -  let now = sessionOpen;
    -  let tradeId = 0;
    -  let newsId = 0;
    -  const news: Headline[] = [];
    -  let freshNews: Headline[] = [];
    +  const model = createModel(seed, instruments);
    +  const dailyBar = createDailyBars(model);
     
    -  const lives = createLives(instruments, seed);
    +  const lives = new Map(instruments.map((i) => [i.symbol, createLive(i)]));
       const all = [...lives.values()];
    -  const sectors = [
    -    ...new Set(all.flatMap((l) => (l.inst.assetClass === "equity" ? l.inst.sector : []))),
    -  ];
    +  const members = all.filter((l) => l.inst.assetClass !== "index");
    +  const indices = all.filter((l) => l.inst.assetClass === "index");
    +  const price = (l: Live, level: number) => model.priceOf(l.inst, level);
     
    -  // ---------- one step of market time ----------
    +  let now = options.start ?? Date.now();
    +  let day = Number.NaN;
    +  /** Headlines out so far (newest first), those still to come today (oldest first), and those new this tick. */
    +  let news: Headline[] = [];
    +  let upcoming: Headline[] = [];
    +  let freshNews: Headline[] = [];
     
    -  function advance(dtMs: number, detailed: boolean) {
    -    const dt = dtMs / 1000;
    -    now += dtMs;
    -    const shocks = drawShocks(r, sectors);
    -    const activity = intradayShape((now - sessionOpen) / MINUTE);
    +  // ---------- a day ----------
     
    +  function setDay(d: number) {
    +    day = d;
    +    model.pin(d);
         for (const l of all) {
    +      l.day = d;
    +      l.path = model.pathOf(l.inst, d);
    +      l.cum = totals(l);
    +      l.slot = -1;
    +    }
    +    minuteBars.clear();
    +    // Yesterday's news and today's, each numbered by its day so a headline keeps its id.
    +    const numbered = (items: Dated[], of: number): Headline[] =>
    +      items.map(({ time, draft }, i) => ({ id: of * 1000 + i, time, ...draft }));
    +    const items = [
    +      ...numbered(newsOf({ model, instruments }, d - 1, false), d - 1),
    +      ...numbered(newsOf({ model, instruments }, d, true), d),
    +    ];
    +    news = items
    +      .filter((h) => h.time <= now)
    +      .reverse()
    +      .slice(0, MAX_NEWS);
    +    upcoming = items.filter((h) => h.time > now);
    +    freshNews = [...news];
    +  }
    +
    +  /** Before each slot: the day's volume, turnover, and highest and lowest price so far. */
    +  function totals(l: Live): Live["cum"] {
    +    const { at, hi, lo, volume } = l.path;
    +    const cum = {
    +      volume: new Float64Array(SLOTS + 1),
    +      turnover: new Float64Array(SLOTS + 1),
    +      high: new Float64Array(SLOTS + 1),
    +      low: new Float64Array(SLOTS + 1),
    +    };
    +    const open = price(l, at[0]!);
    +    cum.high[0] = open;
    +    cum.low[0] = open;
    +    for (let k = 0; k < SLOTS; k++) {
    +      const [low, high] = model.priceRange(l.inst, lo[k]!, hi[k]!);
    +      cum.volume[k + 1] = cum.volume[k]! + volume[k]!;
    +      cum.turnover[k + 1] = cum.turnover[k]! + volume[k]! * price(l, (at[k]! + at[k + 1]!) / 2);
    +      cum.high[k + 1] = Math.max(cum.high[k]!, high);
    +      cum.low[k + 1] = Math.min(cum.low[k]!, low);
    +    }
    +    return cum;
    +  }
    +
    +  // ---------- a slot ----------
    +
    +  /** The slot's levels, tick by tick: from its start to its end, wandering inside its range. */
    +  function microOf(l: Live, k: number): Float64Array {
    +    const { at, hi, lo } = l.path;
    +    const a = at[k]!;
    +    const b = at[k + 1]!;
    +    const r = createRandom(seedOf(seed, 31, l.h, day, k));
    +    const sd = (model.slotVol(l.inst, k, a) / Math.sqrt(TICKS)) * 0.8;
    +    const walk = new Float64Array(TICKS + 1);
    +    for (let j = 1; j <= TICKS; j++) walk[j] = walk[j - 1]! + sd * r.gauss();
    +    const micro = new Float64Array(TICKS + 1);
    +    for (let j = 0; j <= TICKS; j++) {
    +      const x = a + ((b - a) * j) / TICKS + walk[j]! - (walk[TICKS]! * j) / TICKS;
    +      micro[j] = Math.min(hi[k]!, Math.max(lo[k]!, x));
    +    }
    +    return micro;
    +  }
    +
    +  /** The slot's trades: how many as busy as the hour is, sizes adding up to its volume, leaning with its move. */
    +  function printsOf(l: Live, k: number): Print[] {
    +    if (!l.rate) return [];
    +    const r = createRandom(seedOf(seed, 32, l.h, day, k));
    +    const n = Math.min(80, r.poisson(l.rate * SHAPE[k]! * (SLOT_MS / 1000)));
    +    if (!n) return [];
    +    const weights = Array.from({ length: n }, () => Math.exp(0.9 * r.gauss() - 0.4));
    +    const sum = weights.reduce((s, w) => s + w, 0);
    +    const { at } = l.path;
    +    const rise = price(l, at[k + 1]!) - price(l, at[k]!);
    +    const lean = Math.max(-0.3, Math.min(0.3, rise / (price(l, at[k]!) * 0.0004 + 1e-12)));
    +    const ticks = Array.from({ length: n }, () => r.int(0, TICKS - 1)).sort((a, b) => a - b);
    +    return ticks.map((tick, i) => ({
    +      tick,
    +      side: r.next() < 0.5 + lean ? "buy" : "sell",
    +      size: Math.max(l.lot, Math.round((l.path.volume[k]! * weights[i]!) / sum / l.lot) * l.lot),

    Confirmed, and tracked in #68 for after 0.2.0: a proper fix changes the simulator's draw order and golden snapshots.

    ramiz-rahman ramiz-rahman commented on code on Nov 30, 2026 12:21 UTC
    Code Review
    examples/markets/src/market/sim/index.ts:1
    @@ -39,163 +41,274 @@ export interface Simulator extends MarketData {
       step(count?: number): void;
       /** The market's clock, ms since the epoch. */
       now(): number;
    -  /** When today's session opened. */
    -  readonly sessionOpen: number;
    -  /** Step in real time until the returned function is called. */
    +  /** Follow the real clock until the returned function is called. */
       run(): () => void;
     }
     
    +/** Recent trades kept for a tape, and how far back one is filled when first asked for. */
     const TAPE = 200;
    +const TAPE_SLOTS = 40;
     const MAX_NEWS = 300;
     
     export function createSimulator(options: SimulatorOptions = {}): Simulator {
       const seed = options.seed ?? 1;
       const tickMs = options.tickMs ?? 250;
    +  const TICKS = SLOT_MS / tickMs;
    +  if (!Number.isInteger(TICKS)) throw new RangeError("tickMs must divide 15,000");
       const instruments = options.instruments ?? INSTRUMENTS;
    -  const r = createRandom(seed);
    -
    -  const start = options.start ?? todayAt(13, 40);
    -  const sessionOpen = new Date(start).setHours(9, 30, 0, 0);
    -  let now = sessionOpen;
    -  let tradeId = 0;
    -  let newsId = 0;
    -  const news: Headline[] = [];
    -  let freshNews: Headline[] = [];
    +  const model = createModel(seed, instruments);
    +  const dailyBar = createDailyBars(model);
     
    -  const lives = createLives(instruments, seed);
    +  const lives = new Map(instruments.map((i) => [i.symbol, createLive(i)]));
       const all = [...lives.values()];
    -  const sectors = [
    -    ...new Set(all.flatMap((l) => (l.inst.assetClass === "equity" ? l.inst.sector : []))),
    -  ];
    +  const members = all.filter((l) => l.inst.assetClass !== "index");
    +  const indices = all.filter((l) => l.inst.assetClass === "index");
    +  const price = (l: Live, level: number) => model.priceOf(l.inst, level);
     
    -  // ---------- one step of market time ----------
    +  let now = options.start ?? Date.now();
    +  let day = Number.NaN;
    +  /** Headlines out so far (newest first), those still to come today (oldest first), and those new this tick. */
    +  let news: Headline[] = [];
    +  let upcoming: Headline[] = [];
    +  let freshNews: Headline[] = [];
     
    -  function advance(dtMs: number, detailed: boolean) {
    -    const dt = dtMs / 1000;
    -    now += dtMs;
    -    const shocks = drawShocks(r, sectors);
    -    const activity = intradayShape((now - sessionOpen) / MINUTE);
    +  // ---------- a day ----------
     
    +  function setDay(d: number) {
    +    day = d;
    +    model.pin(d);
         for (const l of all) {
    +      l.day = d;
    +      l.path = model.pathOf(l.inst, d);
    +      l.cum = totals(l);
    +      l.slot = -1;
    +    }
    +    minuteBars.clear();
    +    // Yesterday's news and today's, each numbered by its day so a headline keeps its id.
    +    const numbered = (items: Dated[], of: number): Headline[] =>
    +      items.map(({ time, draft }, i) => ({ id: of * 1000 + i, time, ...draft }));
    +    const items = [
    +      ...numbered(newsOf({ model, instruments }, d - 1, false), d - 1),
    +      ...numbered(newsOf({ model, instruments }, d, true), d),
    +    ];
    +    news = items
    +      .filter((h) => h.time <= now)
    +      .reverse()
    +      .slice(0, MAX_NEWS);
    +    upcoming = items.filter((h) => h.time > now);
    +    freshNews = [...news];
    +  }
    +
    +  /** Before each slot: the day's volume, turnover, and highest and lowest price so far. */
    +  function totals(l: Live): Live["cum"] {
    +    const { at, hi, lo, volume } = l.path;
    +    const cum = {
    +      volume: new Float64Array(SLOTS + 1),
    +      turnover: new Float64Array(SLOTS + 1),
    +      high: new Float64Array(SLOTS + 1),
    +      low: new Float64Array(SLOTS + 1),
    +    };
    +    const open = price(l, at[0]!);
    +    cum.high[0] = open;
    +    cum.low[0] = open;
    +    for (let k = 0; k < SLOTS; k++) {
    +      const [low, high] = model.priceRange(l.inst, lo[k]!, hi[k]!);
    +      cum.volume[k + 1] = cum.volume[k]! + volume[k]!;
    +      cum.turnover[k + 1] = cum.turnover[k]! + volume[k]! * price(l, (at[k]! + at[k + 1]!) / 2);
    +      cum.high[k + 1] = Math.max(cum.high[k]!, high);
    +      cum.low[k + 1] = Math.min(cum.low[k]!, low);

    Confirmed, and tracked in #68 for after 0.2.0, with the other two simulator findings.

    ramiz-rahman ramiz-rahman commented on code on Nov 30, 2026 12:21 UTC
    Code Review
    examples/markets/src/market/sim/index.ts:1
    @@ -39,163 +41,274 @@ export interface Simulator extends MarketData {
       step(count?: number): void;
       /** The market's clock, ms since the epoch. */
       now(): number;
    -  /** When today's session opened. */
    -  readonly sessionOpen: number;
    -  /** Step in real time until the returned function is called. */
    +  /** Follow the real clock until the returned function is called. */
       run(): () => void;
     }
     
    +/** Recent trades kept for a tape, and how far back one is filled when first asked for. */
     const TAPE = 200;
    +const TAPE_SLOTS = 40;
     const MAX_NEWS = 300;
     
     export function createSimulator(options: SimulatorOptions = {}): Simulator {
       const seed = options.seed ?? 1;
       const tickMs = options.tickMs ?? 250;
    +  const TICKS = SLOT_MS / tickMs;
    +  if (!Number.isInteger(TICKS)) throw new RangeError("tickMs must divide 15,000");
       const instruments = options.instruments ?? INSTRUMENTS;
    -  const r = createRandom(seed);
    -
    -  const start = options.start ?? todayAt(13, 40);
    -  const sessionOpen = new Date(start).setHours(9, 30, 0, 0);
    -  let now = sessionOpen;
    -  let tradeId = 0;
    -  let newsId = 0;
    -  const news: Headline[] = [];
    -  let freshNews: Headline[] = [];
    +  const model = createModel(seed, instruments);
    +  const dailyBar = createDailyBars(model);
     
    -  const lives = createLives(instruments, seed);
    +  const lives = new Map(instruments.map((i) => [i.symbol, createLive(i)]));
       const all = [...lives.values()];
    -  const sectors = [
    -    ...new Set(all.flatMap((l) => (l.inst.assetClass === "equity" ? l.inst.sector : []))),
    -  ];
    +  const members = all.filter((l) => l.inst.assetClass !== "index");
    +  const indices = all.filter((l) => l.inst.assetClass === "index");
    +  const price = (l: Live, level: number) => model.priceOf(l.inst, level);
     
    -  // ---------- one step of market time ----------
    +  let now = options.start ?? Date.now();
    +  let day = Number.NaN;
    +  /** Headlines out so far (newest first), those still to come today (oldest first), and those new this tick. */
    +  let news: Headline[] = [];
    +  let upcoming: Headline[] = [];
    +  let freshNews: Headline[] = [];
     
    -  function advance(dtMs: number, detailed: boolean) {
    -    const dt = dtMs / 1000;
    -    now += dtMs;
    -    const shocks = drawShocks(r, sectors);
    -    const activity = intradayShape((now - sessionOpen) / MINUTE);
    +  // ---------- a day ----------
     
    +  function setDay(d: number) {
    +    day = d;
    +    model.pin(d);
         for (const l of all) {
    +      l.day = d;
    +      l.path = model.pathOf(l.inst, d);
    +      l.cum = totals(l);
    +      l.slot = -1;
    +    }
    +    minuteBars.clear();
    +    // Yesterday's news and today's, each numbered by its day so a headline keeps its id.
    +    const numbered = (items: Dated[], of: number): Headline[] =>
    +      items.map(({ time, draft }, i) => ({ id: of * 1000 + i, time, ...draft }));
    +    const items = [
    +      ...numbered(newsOf({ model, instruments }, d - 1, false), d - 1),
    +      ...numbered(newsOf({ model, instruments }, d, true), d),

    Confirmed, and tracked in #68 for after 0.2.0. Numbering each section on its own (or drawing it from its own stream) keeps the ids. Including yesterday's reports also would, but costs about 40 ms on each load.

    netlify[bot] netlify[bot] commented on Nov 30, 2026 12:38 UTC
    Bot

    <span aria-hidden="true">✅</span> Deploy Preview for jali-layout ready!

    | Name | Link |
    |:-:|------------------------|
    |<span aria-hidden="true">🔨</span> Latest commit | 43b7300da4aebdf8e233971c8ef518d02bb127f9 |
    |<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/jali-layout/deploys/6b0d6e464885e188b7e201bd |
    |<span aria-hidden="true">😎</span> Deploy Preview | https://deploy-preview-55--jali-layout.netlify.app |
    |<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />!QR Code<br /><br />_Use your smartphone camera to open QR code link._</details> |
    ---
    <!-- jali-layout Preview -->
    _To edit notification comments on pull requests, go to your Netlify project configuration._

    Reviewers
    Assignees
    ramiz-rahman ramiz-rahman
    Labels
    risk: low confidence: 81.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 90.5% (HIGH) · Higher = larger blast radius
    90.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.7% · Lower = rushed or shallow review
    81.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.6% · Safe to merge
    16.6%