refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack
- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched) - Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations() - Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation - Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims - Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution - Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
This commit is contained in:
parent
ce9e2df67c
commit
4cd6038063
432 changed files with 1247 additions and 44469 deletions
|
|
@ -37,6 +37,9 @@ Actionable build tracker for turning Stock Bot into the AI algo research & IB li
|
|||
- [ ] **Purge hardcoded credentials & close `sb-research.*` holdout leak:**
|
||||
- Rotate and remove the hardcoded Webshare proxy URL in `apps/stock/data-ingestion/src/handlers/ib/shared/config.ts:19` (read from env only) and extend `scripts/audit-secrets.ts` to catch `http(s)://user:pass@` literals; also fix `fetch-symbols.action.ts:108` (`ib_symbols` → `ibSymbols`).
|
||||
- Remove `GET /api/v2/datasets/canonical/:hash/export` from `sb-research.*` permissions in `apps/stock/web-api/src/services/research-agents.service.ts:51` and scope agent `GET` routes to granted projects/templates.
|
||||
- [ ] **Pin container tags, kernel limits & `quant` RAM caps:**
|
||||
- Replace all `:latest` / floating tags in `docker-compose*.yml` with exact pinned versions (`questdb:10.2.0`, `postgres:16.9-alpine`, `mongo:7.0.21-jammy`, `dragonfly:v1.30.3`, etc.).
|
||||
- Configure `shm_size` (`2g` on `quant`, `512m` in dev) for PostgreSQL 16 parallel workers, `ulimits.nofile = 1048576` on QuestDB/MongoDB, `/etc/sysctl.d/99-stockbot.conf` (`vm.max_map_count = 1048576`) on `quant`, and hard `mem_limit` + engine caps in `docker-compose.quant.yml` (reserving `~24 GiB` of `125 GiB` for OS page cache).
|
||||
|
||||
### Exit Criteria
|
||||
1. `CARGO_BUILD_JOBS=2 bun run check` passes all 11 gates (`0` errors, `0` warnings).
|
||||
|
|
@ -57,13 +60,14 @@ Actionable build tracker for turning Stock Bot into the AI algo research & IB li
|
|||
- Implement Pass 2 normalization (fix `provider-symbol.ts` for IB `exchangeId`/`description`; ticker root/suffix parser; ISIN Luhn validator + CUSIP→ISIN derivation; precompute `[first_bar_date, last_bar_date]` per `(source, source_id)`).
|
||||
- Implement Pass 3 two-stage matching (Stage A: global ISIN/CUSIP → `instrument`; Stage B: EOD/QM venue → `listing`, IB `conid` attached at `(instrument_id, currency)`, temporal bar-span overlap required on Tier 3/4 ticker matches) + Pass 6 OTC delisting chains (`SIVB` → `SIVBQ`).
|
||||
- Implement Pass 4 batch 25-date cross-sectional price cross-check (`{ date: { $in: sampleDates } }`) and export US+CA match & conflict report + `override` seed file.
|
||||
- [ ] **Step 2 Core — Daily, Corporate Actions, FX & Events (`Parquet + DuckDB`):**
|
||||
- [ ] **Step 2 Core — Zero-Copy Rust Bulk ETL + Daily, Actions, FX & Events (`Parquet + DuckDB`):**
|
||||
- Build `tools/curate-etl` in the Cargo workspace (`mongodb::bson::RawDocumentBuf` zero-copy BSON cursors + preloaded in-RAM `provider_mapping`/`qmSplits` tables + `rayon` sharded Zstd `parquet` writer) so `846M` `eodPrices` rows (and `3.40B` `eodIntraday1M` rows in `M2`) never iterate through single-threaded JS object loops.
|
||||
- Curate `bars_1d` (un-adjusting `eodPrices.volume` via `qmSplits` and cross-checking `qmPrices.sharevolume`).
|
||||
- Curate `corporate_actions` & `adj_factors` (`qmSplits` excluding `1:1` no-ops, `qmDividends` ignoring bogus `usdFxRate: 1`, plus OTC continuation & `-30%`/`-100%` Shumway terminal delisting events).
|
||||
- Curate `fx_1d` (`CAD.FOREX` 1971–2025 + `teMarketData.USDCAD` through 2026).
|
||||
- Curate `events` (`qmFilings` UTC-converted `timefiled` + form groups; `qmEarnings` linked to `qmFilings` or lagged to `16:05 ET` when `announceTime == 'N/A'`) and `shorts` (`ceoShorts` with `+4` Canadian business-day `known_at` lag).
|
||||
- [ ] **`MarketDataStore` + Rolling 6-Month Vault + `trial_ledger`:**
|
||||
- Implement `MarketDataStore` (TS) and `stockbot.data` (Python) over DuckDB + Parquet with mandatory `known_at <= asOf` and `ts < VAULT_CUTOFF_TS` (`max_ingested_ts - 6 months`) enforcement.
|
||||
- Implement `MarketDataStore` (TS) and `stockbot.data` (Python) over DuckDB + Parquet with mandatory `known_at <= asOf`, `ts < VAULT_CUTOFF_TS` (`max_ingested_ts - 6 months`), and per-connection `SET memory_limit = '6GB'; SET threads = 4; SET temp_directory = ...` enforcement.
|
||||
- Add PostgreSQL `trial_ledger` and `vault_evaluations` tables (protected by `reject_research_evidence_mutation()`) + canonical DSR ($\hat{N}$ effective trials) in `@stock-bot/calculations` (see [VALIDATION-AND-RIGOR.md](VALIDATION-AND-RIGOR.md)).
|
||||
- [ ] **Signal Analyzer + `marimo` Workspace:**
|
||||
- Implement `analyze_signal` and `event_study` (IC, rank-IC, quantile spreads, turnover, pre/post-2023 recency split, Newey-West $t$-stat, automatic `trial_ledger` write).
|
||||
|
|
@ -88,8 +92,8 @@ Actionable build tracker for turning Stock Bot into the AI algo research & IB li
|
|||
- Materialize 2D `(period_end, known_at)` deduplicated wide snapshots + TTM features (`fundamentals_pit`).
|
||||
- Curate `ceoPosts` (`14.8M`) separating `bot == "1"` newswires from retail posts and guarding `edited != null` text timestamps; curate lagged `teData` regime series.
|
||||
- [ ] **Intraday Curation (`QuestDB 10.2.0`):**
|
||||
- Pin `questdb/questdb:10.2.0` in `docker-compose*.yml`; replace legacy `libs/data/questdb` (`LATEST BY` → `LATEST ON`, parameterized PG queries, ILP batch writer).
|
||||
- Load split-unadjusted `eodIntraday1M` (US 2003–2025), raw `qmIntraday` (CA/US 2024–2025), and `CAD.FOREX` `1m` (`5.2M` bars) into `bars_1m` and `fx_1m` (`listing_id SYMBOL CAPACITY 65536 NOCACHE`, `DEDUP UPSERT KEYS(ts, listing_id)`).
|
||||
- Replace legacy `libs/data/questdb` (`LATEST BY` → `LATEST ON`, parameterized PGWire queries, ILP v2 batch writer); verify `vm.max_map_count >= 1048576` and `ulimits.nofile = 1048576` on `quant` before bulk load.
|
||||
- Extend `tools/curate-etl` with sharded multi-socket ILP v2 writers to stream split-unadjusted `eodIntraday1M` (`3.40B` rows, US 2003–2025), raw `qmIntraday` (CA/US 2024–2025), and `CAD.FOREX` `1m` (`5.2M` bars) into **`PARTITION BY MONTH`** `bars_1m` (`270` partitions across 22.5y) and `fx_1m` (`listing_id SYMBOL CAPACITY 65536 NOCACHE`, `DEDUP UPSERT KEYS(ts, listing_id)`).
|
||||
- [ ] **Versioned Feature Library (`D04` reopened):**
|
||||
- Build declarative SQL/Polars batch runner writing versioned `(listing_id, ts, known_at, value)` columns + `register_signal(...)` SDK entrypoint.
|
||||
|
||||
|
|
@ -108,9 +112,10 @@ Actionable build tracker for turning Stock Bot into the AI algo research & IB li
|
|||
- [ ] **Tier 1 Columnar Screener:**
|
||||
- Vectorized Polars/DuckDB portfolio sweep (`signal × universe × rebalance × cost`), writing full $M_{T \times N}$ return matrices to `trial_ledger` and computing CSCV PBO ($S = 16$).
|
||||
- [ ] **Tier 2 Rust `financial/` Multi-Asset Upgrades (`apps/stock/engine/src/financial/*`):**
|
||||
- **Task 1 — Retire JSON-over-Postgres/IPC/N-API bar path (prerequisite):** Store only `(hash, manifest, parquet_paths)` in `backtest_datasets` (retiring the `255 MB`-capped `payload JSONB` blob), pass only the manifest + read-only Parquet paths through `NativeBacktestWorker` IPC and N-API so Rust `parquet`/`arrow-rs` reads columns directly with zero JS bar objects, replace per-bar JSON stdio in `candidate-sandbox.ts` with compact Arrow IPC / `Float64Array` barrier frames, remove `serde_json::Value` triple-parsing from bulk payloads in `api/canonical.rs`, and lift single-series TS gates in `native-worker.ts`.
|
||||
- **Atomic timestamp-slice marks (`F06`):** Update all marks at timestamp `t` before checking `RiskAccount` daily-loss/drawdown latches.
|
||||
- **Simultaneous `Target` sell-netting:** Credit haircut-adjusted pending `Sell` proceeds toward same-barrier `Buy` reservations in `MatchingAccount::submit`.
|
||||
- **Feature side-channel & Arrow loader:** Pass precomputed `features` into `Replay` decision barriers and `StrategyContext`; load bars/features from Parquet/Arrow paths instead of Postgres `JSONB` snapshots; remove duplicate `serde_json::Value` parse in `api/canonical.rs`; lift single-series TS gates in `native-worker.ts` and `candidate-sandbox.ts`.
|
||||
- **Feature side-channel:** Pass precomputed `features` columns into `Replay` decision barriers and `StrategyContext`.
|
||||
- **Long/short, multi-currency Margin & corporate actions:** Signed positions/targets + borrow fee accrual; `BTreeMap<Currency, Posting>` (`USD`/`CAD` cash & negative margin-loan interest + `FXCONV` sweeps + tradable FX pairs); ex-date splits, cash dividends, TSX/TSXV `100/500/1000` board-lot rounding, and OTC/Shumway delisting liquidations.
|
||||
- [ ] **Validation Suite & Engine Consolidation:**
|
||||
- Add Purged Walk-Forward & CPCV (`purge = horizon + warmup`, `embargo = max(5d, 0.01 * T)`), parameter stability surface, capacity (ADV participation), and US/CA factor exposure (`MKT`, `SMB`, `HML`, `MOM`).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue