BAZ.HFT
BAZ.HFT
The glither.hft dialect and host embryo for deterministic market-policy evaluation. BAZ.HFT owns strategy fixtures, host integration, execution controls, and signed monetary audit receipts built on the RAGBAZ stack.
BAZ.HFT is the Glither dialect and host embryo for deterministic market-policy evaluation. The compiler is shared with Glither; BAZ.HFT owns the HFT-specific strategy fixtures, transact lifecycle model, signed monetary receipt chain, and host integration boundary.
Live Indicator Suite
The indicator suite below is fully interactive. Select a timeframe and observe how RSI, Stochastic, MACD, and moving average signals update across the chart.
Architecture
.glith strategy source
│
▼
baz-hft-roux (Glither compiler facade)
│ pest PEG parse · IR lower · structural checks
▼
Codegen → no_std Rust WASM component · WIT contract
│
├── State structs — heapless ring buffers per state definition
├── Math macros — rsi(), μ(), σ(), bbands_*() single-pass, no heap
└── Dispose fns — dispose_tick(ctx) → Receipt
dispose_position(ctx) → Receipt
│
▼
BAZ.Palantir (rule storage · enrichment · subscriptions · streaming)
│
▼
BAZ.Luna (candlestick charts · backlog viewer · notebook editor)
BAZ.HFT does not carry its own compiler fork. The parser, IR, checks, and
Rust/WIT codegen live in Glither packages/roux. BAZ.HFT adds the HFT
compatibility facade (baz-hft-roux), strategy fixtures, host runtime stub,
and the signed monetary receipt chain.
Indicators
Trend Indicators
1Trend indicators track the prevailing direction of price. They are non-bounded — their values are expressed in price units and have no fixed range.
Oscillators
2Oscillators are bounded — they return values in a fixed range and are designed to identify overbought / oversold conditions and divergences.
DSL Syntax
BAZ.HFT uses the glither.hft dialect. Rules declare bounded ring-buffer state,
apply inline math macros, and emit typed transact dispositions with two-stage
fill/timeout lifecycle arms:
#pragma dialect glither.hft ; fold first-match
#pragma version 2.0-beta
state noise_rsi = bars | window = 14 | timeframe = 1m | tracks = [ close ]
state noise_bb = bars | window = 20 | timeframe = 1m | tracks = [ close, volume ]
rule rsi_oversold_reversal =
tick | rsi(noise_rsi.close) < 25.0
| tick.close < bbands_lower(noise_bb.close, dev = 2.5)
| volume(noise_bb.volume) > μ(noise_bb.volume)
=> transact market_buy
on fill into position(target = bbands_mid(noise_bb.close))
after 30s market_close_all (reason = mean_reversion_timeout)
then_log backlog
State definitions
state declares a named ring buffer. BAZ.Palantir's enricher populates it from
the BAZ.CX market-data stream for each subscribed symbol.
| Field | Purpose |
|---|---|
window = N | Ring buffer capacity (bars kept) |
timeframe = 1m | Bar resolution fed into the ring |
tracks = [close] | Fields populated per bar |
Math macros
| Macro | Description |
|---|---|
rsi(path) | RSI(14) over the ring buffer |
μ(path) | Arithmetic mean |
σ(path, m) | Standard deviation (takes pre-computed mean) |
volume(path) | Sum over window |
bbands_upper(path, dev) | Upper Bollinger Band (mean + dev·σ) |
bbands_lower(path, dev) | Lower Bollinger Band (mean − dev·σ) |
bbands_mid(path) | Middle Bollinger Band (= mean) |
Transact lifecycle
transact <order_type>
on <event> into <lifecycle_action> -- on fill
after <duration> <lifecycle_action> -- on timeout
then_log backlog -- timestamp signal to SQLite
Every transact disposition embeds a two-stage lifecycle so the host (BAZ.Palantir)
knows how to handle fill and timeout cases without any shell process or external
scheduler.
then_log backlog is a lossy diagnostic directive — it timestamps signals to the
SQLite backlog. It is not the canonical monetary audit store. Signed receipts
(Ed25519, content-addressed, append-only chain) live in the BAZ.HFT host crate
and require durable integration before order execution is enabled.
Optimizations
Incremental computation
Indicators are incremental — on each new bar, only the delta is recomputed:
| Indicator | Incremental form | Complexity |
|---|---|---|
| SMA(n) | Sum window: add new, drop oldest | O(1) |
| EMA(n) | prev_ema × (1-k) + price × k | O(1) |
| RSI(n) | Wilder smoothing on avg gain/loss | O(1) |
| Stochastic(k, d) | Sliding H/L window | O(1) amortized |
| ATR(n) | EMA of true range | O(1) |
| MACD | Three cascaded EMAs | O(1) |
Compile-time selector pushdown
The Glither compiler infers cheap selectors from crossing-guard predicates. In
the example above, | bar in trending and | rsi14 < 35 are pushed into an
indexed pre-filter before the more expensive crosses_above check — identical to
the SQL optimiser pattern in the core spec.
SIMD batch evaluation
For bulk backtesting, BAZ.HFT compiles indicator compute graphs to WASM SIMD
instructions (v128 operations). A 10-year daily bar series computes all
indicators in < 40ms on a single core.
Next steps
Current status: compiler and audit primitives implemented; live execution not enabled.
| Item | Description |
|---|---|
| Durable receipts | Append and synchronize signed receipts before any venue side effect |
| Event emission | Emit policy compilation and activation receipts |
| Lifecycle events | Connect plan, review, submit, fill, cancel, and settlement events |
| Durable storage | Append-only storage, key rotation, retention policy |
| Replay tooling | Replay tooling and redacted operator/regulator projections |
| Latency benchmark | Measure component latency and allocation under a paper feed |
Technology Stack
| Layer | Technology |
|---|---|
| Dialect | glither.hft (extends Glither packages/roux) |
| Compiler facade | baz-hft-roux re-exports shared Glither compiler API |
| Runtime codegen | #![no_std] Rust WASM component, heapless::Vec ring buffers |
| WIT contract | world hft-executor — dispose-tick, dispose-position |
| Audit receipts | Ed25519 · content-addressed IDs · SHA-256 chain · append-only |
| Orchestration | BAZ.Palantir (rule storage, subscriptions, enrichment, streaming) |
| Frontend | BAZ.Luna (candlestick charts, CodeMirror editor, backlog viewer) |
See the BAZ architecture experiment page for the full compiler pipeline, IR types, WIT world definition, and example strategies.