T-87: M1.1l — Security-type classifier: eodSymbols.Type → securityTypeByIsin for the security-master loader (no new dependencies)

This commit is contained in:
Studio 2026-11-28 04:55:34 -05:00
parent c9a4adabad
commit 2f5ac2e7e7
6 changed files with 920 additions and 7 deletions

View file

@ -95,3 +95,31 @@ bun test test/unit/security-master-source-symbol-readers.test.ts
- **Recorded baseline (`2026-11-28`, local sandbox, in-memory async cursor fake reader):**
- Workload: `368,000` synthetic docs (`300,000` `eodSymbols`, `50,000` `qmSymbols`, `18,000` `ibSymbols`) including NMFQS exclusion, country normalization, ISIN/CUSIP check-digit validation, ticker parsing, and deterministic ASCII sorting.
- Observed throughput: `754,047 docs/s` (`488.0 ms` wall time, floor `>= 25,000 docs/s`).
## EOD Security-Type Classifier (`security-type.ts`)
`apps/stock/data-pipeline/src/security-master/security-type.ts` maps raw EODHD `Type` strings into the canonical PostgreSQL `instrument.security_type` enum (`SecurityType`) and builds the `securityTypeByIsin` map required by `persistSecurityMaster` (wired automatically through `readEodSymbols` and `readSecurityMasterSources`).
- **Mapping table (`EOD_SECURITY_TYPE_MAP`, trimmed, whitespace-collapsed, case-insensitive):**
| EODHD `Type` | Canonical `SecurityType` |
| --- | --- |
| `Common Stock` | `common` |
| `Preferred Stock` | `preferred` |
| `ETF` | `etf` |
| `Unit`, `Units` | `unit` |
| `Warrant`, `Warrants` | `warrant` |
| `Right`, `Rights` | `right` |
| `CDR` | `cdr` |
| `Currency`, `Forex`, `FX` | `fx` |
- **Published-vocabulary & no-guess rule:** Because QA MongoDB is unreachable from the agent sandbox, the table is based on the published EODHD `Type` vocabulary. Non-equity-like values (`FUND`, `Mutual Fund`, `Bond`, `Notes`, `INDEX`, etc.), blanks, non-strings, and unmapped strings return `null` and are never guessed from ticker suffixes or company names. A non-string `Type` on an `eodSymbols` document does not skip the document from Stage A/B — it is counted under `securityTypeStats.missingType`.
- **Reviewing unmapped values & conflicts:** After a real security-master run, inspect `unknownSecurityTypes` (sorted by count descending, then ASCII) for any newly observed provider strings that should be added to `EOD_SECURITY_TYPE_MAP`, and inspect `securityTypeConflicts` (ISINs omitted from `securityTypeByIsin` because multiple EOD documents disagreed on their classified type; capped by `maxSecurityTypeConflicts`, default `200`, with total counts in `securityTypeStats.isinsConflicting` and `conflictsTruncated`).
- **Local synthetic benchmark:** Run the unit suite and fixed-seed 300,000-record synthetic benchmark (zero DB connections) with:
```bash
bun test test/unit/security-master-security-type.test.ts
```
- **Recorded baseline (`2026-11-28`, local sandbox, zero DB connections):**
- Workload: `300,000` synthetic EOD records (`100,000` distinct ISIN buckets, mixed mapped/unknown/missing types, and `20` conflicting ISINs exercising Pass 2 conflict collection).
- Observed throughput: `4,277,092 records/s` (`70.1 ms` wall time, floor `>= 100,000 records/s`).