Skip to content

Phase 2: realized volatility, volume and VWAP metrics#1

Merged
1816x merged 3 commits into
mainfrom
claude/phase-2-kickoff-icwp0s
Jul 16, 2026
Merged

Phase 2: realized volatility, volume and VWAP metrics#1
1816x merged 3 commits into
mainfrom
claude/phase-2-kickoff-icwp0s

Conversation

@1816x

@1816x 1816x commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 2 of the roadmap: extend the engine beyond order-flow imbalance to a full set of
per-window microstructure metrics, persisted to a single table and served through the API,
all covered by tests against hand-computed known data.

What changed

Engine (Rust)ofi.rsmetrics.rs

  • OfiBucketMetricsBucket, now carrying trade_count, vwap and realized_volatility
    alongside buy/sell volume.
  • A single time-ordered windowing pass computes every metric.
  • Realized volatility is continuous across window boundaries: the log return between two
    consecutive trades is attributed to the later trade's window. This means per-window
    variances sum to the whole tape's realized variance, and a single-tick window still records
    its move away from the previous trade.
  • Storage writes one wide metrics row per (bucket_start_ns, window_ns), idempotent on rerun.

Backtest (Python / FastAPI)

  • A shared _query_metrics helper reads the unified metrics table.
  • /metrics/ofi keeps its Phase 1 response contract.
  • New /metrics/volatility (realized volatility + trade count) and /metrics/volume
    (buy/sell/total volume + VWAP) endpoints.

Docs

  • Roadmap Phase 2 checked off, curl examples for the new endpoints, and design-decision
    entries for the unified table, continuous realized volatility and VWAP.

Design decisions

  • Unified metrics table instead of one table per metric — every metric shares the same
    window key and is produced in one pass, so a wide row is the natural shape.
  • Continuous cross-window realized volatility — resetting returns at each window edge would
    silently discard boundary moves and understate volatility.
  • VWAP folded into the same pass — needs only the running Σ price·size already touched
    per tick.

Verification

  • Engine: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test — 10/10.
  • Backtest: ruff check, ruff format --check, pytest — 15/15.
  • End-to-end on the synthetic tape: 5000 ticks → 501 buckets. Across all rows,
    total_volume == buy_volume + sell_volume, no negative volatility, ofi ∈ [-1, 1], and VWAP
    within the tape's price range. All three endpoints return 200 with the expected columns.

Generated by Claude Code

1816x added 3 commits July 16, 2026 16:43
Extend the windowing pass to compute more microstructure metrics
alongside order-flow imbalance and persist them to a unified table.

- rename ofi.rs -> metrics.rs; OfiBucket -> MetricsBucket now carries
  trade_count, vwap and realized_volatility
- realized volatility is continuous across window boundaries, so the
  per-window variances sum to the whole tape's realized variance and a
  single-tick window still records its move away from the prior trade
- storage writes one wide `metrics` row per (bucket_start_ns, window_ns)
- unit tests assert every field against hand-computed known data
Read the engine's unified `metrics` table through a shared
_query_metrics helper and expose one view per metric family.

- /metrics/ofi keeps its Phase 1 response contract
- /metrics/volatility returns realized_volatility and trade_count
- /metrics/volume returns buy/sell/total volume and VWAP
- tests cover projection, limit capping/validation and the
  missing/empty-database 503s across every endpoint
Check off Phase 2 in the roadmap, add curl examples for the new
volatility and volume endpoints, and document three calls: the
unified metrics table, continuous cross-window realized volatility,
and folding VWAP into the same pass.
@1816x
1816x merged commit aaccfdd into main Jul 16, 2026
2 checks passed
@1816x
1816x deleted the claude/phase-2-kickoff-icwp0s branch July 23, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant