Skip to content
aman9824Public

About

Dual-engine research platform — slow model-driven analysis, fast deterministic execution. No model in the hot path. C++ risk gate via pybind11.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

YTC — Yellow Temple Capital

A decoupled two-engine trading research platform:

  • Sage — an asynchronous, Claude-driven signal engine (cognition). It turns unstructured market narrative into structured, evidence-cited signals and publishes strategy parameters out-of-band.
  • Sentinel — a deterministic execution engine with an arithmetic risk gate on the hot path. No model ever runs in the execution path.

⚠️ Sandbox / paper-trading only. No live orders. No performance or returns claims. Nothing here is investment advice. See docs/STRATEGY.md and docs/ARCHITECTURE.md.

The original "nanosecond LLM hot path / mathematical certainty" framing was re-architected to the only honest version: slow cognition decoupled from fast deterministic execution. The reasoning is in docs/ARCHITECTURE.md §1.

Status

Phase Scope State
0 Plan (ARCHITECTURE / DECISIONS / STRATEGY) ✅
1 Runnable skeleton: bus + mock Sage → Sentinel → paper fills, C++ gate + parity ✅
2 Real engines: connectors + pluggable signal provider (mock / Claude-on-Vertex), grounded citations, sliced orders + slippage ✅
3 Pluggable strategies + portfolio risk manager + backtester (same code path as live) + eval-gated signals ✅
4 Command-center API (FastAPI) + dark/gold dashboard + health/metrics, reading from the bus ✅
5 Test coverage + developer docs + real/mocked/TODO map ✅

Feature-complete per the brief. ~50 tests, all phases runnable. Docs: ARCHITECTURE · DECISIONS · STRATEGY · DEVELOPMENT · REAL vs MOCK vs TODO · PROGRESS

What is real vs mocked right now: the market feed and the narrative connectors serve deterministic fixture data; the signal provider is real code — a deterministic mock (default, offline) or Claude on Vertex when configured. The bus, strategy (with limit-aware order slicing), risk gate (Python + optional C++), paper broker (with slippage), citation grounding, and the end-to-end wiring are all real.

Sage signal provider (cognition)

Sage ingests narrative from pluggable connectors and analyzes it into evidence-cited SignalVectors through a provider seam:

  • mock (default) — a deterministic lexicon scorer. No network, no credentials; CI and the default run use it. Citations are headlines that actually contain the matched terms, so they are grounded by construction.
  • vertex — real Claude on Vertex (AnthropicVertex, forced tool call for schema-valid output, bare model id claude-opus-4-8, region global). Citations are verified against the source narrative — ungrounded quotes are dropped and confidence is discounted.
python -m ytc --provider mock      # default, offline
# Real Claude (needs GCP ADC + the optional extra):
pip install -e ".[vertex]"
gcloud auth application-default login
YTC_VERTEX_PROJECT_ID=<gcp-project> python -m ytc --provider vertex

The published StrategyParams contract is identical for both, so Sentinel never changes.

Strategies, risk, and backtesting

  • Pluggable strategies (--strategy): target_weight (trades Sage's conviction) and momentum (fast/slow MA cross, ignores cognition — proves the framework is provider-agnostic). Register more in sentinel/strategy.py::STRATEGIES.
  • Portfolio risk manager — above the per-order gate: tracks equity drawdown from the running peak and halts trading when it breaches max_drawdown_pct (latching). Consulted by both the live engine and the backtester.
  • Backtester — replays a price series through the exact same decision path as live (sentinel/trading.py::step), so a strategy that passes here behaves identically in production.
python -m ytc.backtest --bars 300 --seed 7                 # target_weight on synthetic data
python -m ytc.backtest --bars 300 --strategy momentum      # momentum
python -m ytc.backtest --bars 400 --drift -0.01            # downtrend -> watch the risk halt

Command center (API + dashboard)

A FastAPI service runs the whole platform inside its lifespan and exposes a live dark-mode/gold dashboard plus JSON endpoints. The collector reads from the same bus the engines publish on — no extra coupling.

pip install -e ".[api]"
python -m ytc.api --port 8000      # or: ytc-serve --port 8000
# open http://127.0.0.1:8000
Endpoint Returns
GET / dashboard (system stats, Sage signals + citations, execution log, positions, paper P&L)
GET /health {status, uptime_s}
GET /metrics counts (signals/ticks/orders/fills), gate decisions, equity, paper P&L, halt state
GET /state positions, last prices, metrics
GET /signals recent SignalVectors (with grounded citations)
GET /feed recent market ticks
GET /executions recent gate decisions + fills (audit log)

The core runs headless without these deps; [api] is optional.

Eval-gated signal quality (STRATEGY.md R1)

ytc/sage/eval/ scores any signal provider against labeled cases; a regression below the bar fails CI (tests/test_eval.py). Quality is a number, not a vibe — and the same harness runs against Claude when the Vertex provider is configured.

Quick start (pure Python — no compiler needed)

cd ytc
python -m venv .venv && source .venv/Scripts/activate   # Windows Git Bash
# (Linux/macOS: source .venv/bin/activate)
pip install -e ".[dev]"

python -m ytc                 # run the end-to-end loop (~15s), prints a summary
python -m ytc --seconds 5     # shorter run
python -m ytc --kill-switch   # engage the global risk kill-switch (all orders blocked)
pytest                        # run the test suite

You should see Sage emitting signals, Sentinel filling/blocking orders through the risk gate, and a final paper-trading summary. The log line risk gate backend=python confirms the fallback path is active.

Optional: build the native C++ risk gate

The gate has a fully-built C++ implementation (pybind11). The Python reference stays authoritative; the native build is a faster, parity-tested drop-in.

pip install pybind11
bash scripts/build_native.sh         # CMake; or scripts/build_native_gpp.sh (g++/clang, no CMake)
python -m ytc                        # now logs: risk gate backend=native
python -m pytest tests/test_parity.py -v  # asserts C++ == Python on 5000 + 3000 inputs

Verified with GCC 16.1.0 (MinGW-w64 UCRT). Honest benchmark (200k decisions): the per-call native path is ~0.73× (slower — pybind11 boundary overhead dwarfs the arithmetic), but the batched evaluate_batch is ~3.6× faster. C++ pays off only when the boundary is amortized — see sentinel_native/README.md. Requires a C++17 compiler (CMake optional).

Layout

ytc/
├── docs/              ARCHITECTURE · DECISIONS · STRATEGY · PROGRESS
├── src/ytc/
│   ├── common/        models (contracts), config, logging
│   ├── bus/           Bus interface + in-process asyncio impl (D10)
│   ├── sage/          async signal engine: connectors/ + analysis/ (mock + Vertex providers)
│   ├── sentinel/      feed, strategy (sliced orders), risk gate, paper broker (slippage), engine
│   ├── backtest/      replay harness (data, engine, metrics) + `python -m ytc.backtest`
│   └── api/           command center: telemetry + FastAPI server + dashboard
├── sentinel_native/   C++ risk gate (CMake + pybind11)
├── scripts/           build_native.sh
└── tests/             bus · risk gate · parity · end-to-end smoke

Configuration

All settings are env-overridable with the YTC_ prefix (see src/ytc/common/config.py), e.g.:

YTC_RUN_SECONDS=30 YTC_MAX_ORDER_QTY=50 python -m ytc

About

Dual-engine research platform — slow model-driven analysis, fast deterministic execution. No model in the hot path. C++ risk gate via pybind11.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages