34 lines
3.7 KiB
Markdown
34 lines
3.7 KiB
Markdown
# CLAUDE.md — Stock Bot Engineering & Quant Guide
|
||
|
||
Read [AGENTS.md](./AGENTS.md) first for mandatory environment and database safety rules, then [docs/README.md](./docs/README.md) for the platform architecture and active milestone checklist.
|
||
|
||
## 1. Canonical Documentation
|
||
- [AGENTS.md](./AGENTS.md) — Runtime commands (`bun`, `turbo`), `dev` vs `qa` port isolation, and strict QA MongoDB/PostgreSQL protection rules.
|
||
- [docs/PLATFORM-PLAN.md](./docs/PLATFORM-PLAN.md) — North-star architecture and locked design decisions (`D1`–`D12`).
|
||
- [docs/MILESTONES.md](./docs/MILESTONES.md) — Ordered implementation roadmap (`M0` → `M5`) with file targets and falsifiable exit criteria.
|
||
- [docs/DATA-CONTRACTS.md](./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 QuestDB `10.2.0`.
|
||
- [docs/VALIDATION-AND-RIGOR.md](./docs/VALIDATION-AND-RIGOR.md) — `@stock-bot/calculations` single-source metric formulas, append-only `trial_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](./docs/servers.md) — Hardware & container topology (`quant` `10.0.0.51`, `9900K` execution host, `TrueNAS`, local dev).
|
||
|
||
## 2. Non-Negotiable Architecture & Data Invariants
|
||
1. **Protect QA Data:** Never drop, reset, or write to QA MongoDB (`27017/stock`) or QA PostgreSQL (`5432/trading_bot`) from `dev` or tests. Query QA MongoDB strictly read-only via `MONGODB_READ_URI` (`studio_stock_bot_read`).
|
||
2. **Tooling:** Use `bun` (`bun run build`, `bun run typecheck`, `bun test`) and `turbo`. Native Rust execution lives in `apps/stock/engine` (N-API addon).
|
||
3. **Identity & Point-in-Time (`PIT`):**
|
||
- Key market, fundamental, and feature records by `listing_id` (`instrument_listings`), never bare ticker strings.
|
||
- Enforce `known_at <= as_of` on every non-price join; never filter universes on current `is_active` or `delisted_at IS NULL`.
|
||
- Respect empirical provider adjustment semantics (`eodPrices` has raw OHLC + **split-adjusted volume**; `eodIntraday1M` has **split-adjusted OHLC**; `qmPrices` has raw OHLC + raw `sharevolume`).
|
||
4. **Storage Split (`D1`):**
|
||
- **DuckDB + Hive Parquet** owns `1d` bars, corporate actions, PIT fundamentals/earnings/shorts/macro, `1d` FX (`CAD.FOREX`), and versioned feature matrices.
|
||
- **QuestDB `10.2.0`** owns `1m`/`5m`/`1h` intraday and hot streaming bars (`listing_id SYMBOL CAPACITY 65536 NOCACHE`).
|
||
5. **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.
|
||
6. **Anti-Overfitting Controls:**
|
||
- Every candidate evaluation writes an immutable row to PostgreSQL `trial_ledger` *before* returning metrics.
|
||
- Research agents (`sb-research.*`) must never access raw dataset export routes or the air-gapped rolling 6-month vault.
|
||
|
||
## 3. Working Style
|
||
- Deliver complete, production-grade code without mocks, stubs, or `TODO` placeholders.
|
||
- 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 targeted `bun test` suites (using `/home/boki/.studio/test-env/stock-bot.env` for PostgreSQL safety tests).
|
||
- Keep communication direct, concise, and technical—skip basics and generic boilerplate.
|