Rasveda Labs Case study · Portfolio

Market State Operating System

The language of markets, not trading signals.

Not a bot. Not signals. Not a GPT wrapper over candles. Quantara analyses market behaviour through causal, explainable events — answering what is happening, why, and what is likely next, with a traceable chain all the way down to raw OHLCV bars.

Role
Product owner + architect
Stack
Next.js 14 · TypeScript · Anthropic SDK · SQLite / IndexedDB
Status
Pipeline runs end-to-end
What it is

A different question than “buy or sell.”

Every output can be unrolled backwards: scenario → transitions → supporting events → L2 patterns → L1 detections → specific candles. No black box, no GPT hallucinating in the analyser’s seat — the model writes narratives on top of state, it never invents the state.

scenario transitions events L2 patterns L1 detections raw candles
Architecture

A 5-layer event-sourced pipeline.

L1Detection
Atomic events from OHLCV — EMA crossings, ATR compression / expansion, wick rejections, swings, breakout attempts, RSI thresholds.
L2Composition
Composite patternsfake_breakout, liquidity_sweep, absorption, stop_run, rejection_at_level, trend_pullback_complete, RSI divergences.
L3Structure
Market regime — bullish / bearish structure active, range active, trend exhaustion — derived from the sequence of swings.
L4Scenarios
Hypotheses with confidence — evidence accumulation, decay and kill causes: reversal_watch, breakout_watch, mean_reversion, continuation, range_test.
AINarrative
Streaming narratives via the Anthropic SDK — running on top of state, not replacing it.
Key decisions

Engineering the determinism.

Full determinism

Event and transition IDs are computed from the input. Identical candles → identical event log → identical scenario births. No hidden randomness, no wall-clock leakage.

Event sourcing

Append-only journal of events and transitions; state is derived as a left fold — you can rewind to any point in history.

Streaming state compute

Not batch — a five-phase per-event pipeline (decay → evidence → invalidation → births → structure), so a scenario can be born, weakened, killed and reborn within a single run.

Timeframe isolation

Each timeframe is computed independently; multi-timeframe composition is a separate layer with explicit conflict resolution.

Dictionary discipline

Every term has exactly one canonical, versioned definition. Changing a detector requires bumping the dictionary entry, which propagates as automatic cache invalidation via fingerprint.

Persistence-agnostic

A unified PersistenceAdapter backs IndexedDB (browser) and better-sqlite3 (server, WAL mode). Cross-shard journal with deduplication.

End-to-end cancellation

An AbortController propagates React → fetch → Next API route → Anthropic SDK. The Stop button actually stops the LLM within milliseconds.

NDJSON streaming

Event stream from LLM to UI with proper back-pressure and graceful degradation on 503.

Validation infrastructure

Honest measurement, not pretty numbers.

A separate track focused on results that are statistically defensible, not just “looks nice.”

Backtest runner

A full matrix — 5 symbols × 3 timeframes × 3 lookback periods = 45 runs in one command.

Cross-report aggregator

Guarded against Simpson’s paradox: rates are recomputed from summed numerators and denominators, not averaged from per-report rates.

Edge analytics dashboard

Leaderboard, confidence trajectory, cross-market consistency, regime split (trend / range / exhaustion / neutral) and failure analysis with dominant kill cause.

Null hypothesis test

A geometric Brownian motion baseline that establishes the noise floor for interpreting confirm rates.

Pre-matrix audit

Found and documented two structural biases (L1 swing look-ahead, target-before-stop in the outcome evaluator) with quantified magnitude before running real data.

9 + 8
L1 detectors + L2 composers audited line-by-line
0
real-data runs before the audit
2
structural biases surfaced & measured

Most statistical pipelines aren’t audited for look-ahead bias before the first backtest — teams run the matrix, celebrate the pretty numbers, and hit the bugs only when the numbers refuse to reproduce. Here, every detector and the outcome evaluator were audited line by line, a null test established the noise floor, and two biases were surfaced, measured and documented inline. Only then does the matrix run.

The build

Stack.

Frontend
  • Next.js 14 App Router
  • TypeScript (strict)
  • React 18
  • Tailwind CSS 3.4
Charts
  • lightweight-charts 4.2
  • custom event markers
  • MTF composition
AI
  • Anthropic SDK 0.32.1
  • prompt caching
  • streaming
  • aggressive cancellation
Persistence
  • IndexedDB (client)
  • better-sqlite3 (server, WAL)
Testing
  • 80+ smoke assertions
  • determinism
  • causality
  • timeframe isolation
  • cache-invalidation invariants
Status
Pipeline runs end-to-end

From candles to narrative.

The full pipeline runs end-to-end, from candles to narrative. The /trading/analytics dashboard exposes ~30 metrics per scenario type with cross-report consolidation. Validation infrastructure is built and verified; awaiting the full matrix pass on real market data.

Role — Product owner + architect. Built in partnership with an AI engineer through iterative collaboration: product direction and invariants set by me, implementation and calibration push-back from the partner.

// what · why · next

Read the market’s state, not its noise.

Back to the portfolio