3.7 KiB
3.7 KiB
CLAUDE.md — Stock Bot Engineering & Quant Guide
Read AGENTS.md first for mandatory environment and database safety rules, then docs/README.md for the platform architecture and active milestone checklist.
1. Canonical Documentation
- AGENTS.md — Runtime commands (
bun,turbo),devvsqaport isolation, and strict QA MongoDB/PostgreSQL protection rules. - docs/PLATFORM-PLAN.md — North-star architecture and locked design decisions (
D1–D12). - docs/MILESTONES.md — Ordered implementation roadmap (
M0→M5) with file targets and falsifiable exit criteria. - docs/DATA-CONTRACTS.md — Empirical schemas and adjustment/PIT rules for all 31 QA MongoDB collections, PostgreSQL security master (
instruments,instrument_listings,corporate_actions), DuckDB/Parquet, and QuestDB10.2.0. - docs/VALIDATION-AND-RIGOR.md —
@stock-bot/calculationssingle-source metric formulas, append-onlytrial_ledger,\hat{N}Deflated Sharpe, CSCV PBO, Purged CPCV/Walk-Forward, rolling 6-month Vault + Post-2023 Recency Gate, and IBKR Margin (USD/CAD) execution rules. - docs/servers.md — Hardware & container topology (
quant10.0.0.51,9900Kexecution host,TrueNAS, local dev).
2. Non-Negotiable Architecture & Data Invariants
- Protect QA Data: Never drop, reset, or write to QA MongoDB (
27017/stock) or QA PostgreSQL (5432/trading_bot) fromdevor tests. Query QA MongoDB strictly read-only viaMONGODB_READ_URI(studio_stock_bot_read). - Tooling: Use
bun(bun run build,bun run typecheck,bun test) andturbo. Native Rust execution lives inapps/stock/engine(N-API addon). - Identity & Point-in-Time (
PIT):- Key market, fundamental, and feature records by
listing_id(instrument_listings), never bare ticker strings. - Enforce
known_at <= as_ofon every non-price join; never filter universes on currentis_activeordelisted_at IS NULL. - Respect empirical provider adjustment semantics (
eodPriceshas raw OHLC + split-adjusted volume;eodIntraday1Mhas split-adjusted OHLC;qmPriceshas raw OHLC + rawsharevolume).
- Key market, fundamental, and feature records by
- Storage Split (
D1):- DuckDB + Hive Parquet owns
1dbars, corporate actions, PIT fundamentals/earnings/shorts/macro,1dFX (CAD.FOREX), and versioned feature matrices. - QuestDB
10.2.0owns1m/5m/1hintraday and hot streaming bars (listing_id SYMBOL CAPACITY 65536 NOCACHE).
- DuckDB + Hive Parquet owns
- Single Financial Authority (
D2):- The Rust
engine(apps/stock/engine) is the sole authority for fills, fees, margin interest, corporate-action accounting, and equity curves across backtest, paper, and live. @stock-bot/calculations(libs/calculations) is the sole authority for Sharpe, Sortino, Calmar, MaxDD, turnover, IC, DSR, and PBO.
- The Rust
- Anti-Overfitting Controls:
- Every candidate evaluation writes an immutable row to PostgreSQL
trial_ledgerbefore returning metrics. - Research agents (
sb-research.*) must never access raw dataset export routes or the air-gapped rolling 6-month vault.
- Every candidate evaluation writes an immutable row to PostgreSQL
3. Working Style
- Deliver complete, production-grade code without mocks, stubs, or
TODOplaceholders. - Check actual repository files and data contracts before changing interfaces; batch independent reads, searches, and edits in parallel.
- Validate changes with
bun run typecheck,bun run audit:secrets, and targetedbun testsuites (using/home/boki/.studio/test-env/stock-bot.envfor PostgreSQL safety tests). - Keep communication direct, concise, and technical—skip basics and generic boilerplate.