T-87: M1.1l — Security-type classifier: eodSymbols.Type → securityTypeByIsin for the security-master loader (no new dependencies)
This commit is contained in:
parent
2f5ac2e7e7
commit
a368e8a47a
6 changed files with 285 additions and 4 deletions
|
|
@ -6,6 +6,8 @@ import { BarSpanIndex } from '../../apps/stock/data-pipeline/src/normalization/b
|
|||
import { cusipToIsin } from '../../apps/stock/data-pipeline/src/normalization/identifiers';
|
||||
import { parseTickerDetailed } from '../../apps/stock/data-pipeline/src/normalization/ticker';
|
||||
import {
|
||||
buildSecurityTypeByIsin,
|
||||
buildSecurityTypeByIsinForStageA,
|
||||
CEO_SYMBOLS_PROJECTION,
|
||||
classifySourceExchanges,
|
||||
compareAscii,
|
||||
|
|
@ -1600,6 +1602,130 @@ describe('security-master source-symbol-readers', () => {
|
|||
expect(sources.securityTypeByIsin.has('CA82509L1076')).toBe(false);
|
||||
});
|
||||
|
||||
test('regression: Stage A-quarantined EOD rows cannot veto a valid member type or supply a type, while raw emitted rows remain available for vocabulary diagnostics', async () => {
|
||||
const exchangeLookup = createPass1ExchangeLookup();
|
||||
|
||||
const reader = new FakeSourceSymbolReader(
|
||||
{
|
||||
eodSymbols: [
|
||||
// Valid EOD Common Stock row for AAPL (matching ISIN + CUSIP)
|
||||
{
|
||||
eodSearchCode: 'AAPL.US',
|
||||
Code: 'AAPL',
|
||||
Exchange: 'NASDAQ',
|
||||
Country: 'USA',
|
||||
Currency: 'USD',
|
||||
Isin: 'US0378331005',
|
||||
Cusip: '037833100',
|
||||
Name: 'Apple Inc.',
|
||||
Type: 'Common Stock',
|
||||
},
|
||||
// Stale EOD ETF row sharing AAPL's valid ISIN but carrying SPY's valid CUSIP ->
|
||||
// Stage A quarantines as `isin_cusip_mismatch`. Must NOT veto AAPL's 'common' type.
|
||||
{
|
||||
eodSearchCode: 'AAPL_STALE.US',
|
||||
Code: 'AAPL',
|
||||
Exchange: 'NYSE',
|
||||
Country: 'USA',
|
||||
Currency: 'USD',
|
||||
Isin: 'US0378331005',
|
||||
Cusip: '78462F103',
|
||||
Name: 'Stale Apple ETF Row',
|
||||
Type: 'ETF',
|
||||
},
|
||||
// Quarantined-only EOD row with an unmapped raw Type -> must NOT supply a type,
|
||||
// but its raw Type must stay available in `securityTypeRecords` for vocabulary diagnostics.
|
||||
{
|
||||
eodSearchCode: 'BAD_ONLY.US',
|
||||
Code: 'BADO',
|
||||
Exchange: 'NASDAQ',
|
||||
Country: 'USA',
|
||||
Currency: 'USD',
|
||||
Isin: 'US30303M1027',
|
||||
Cusip: '037833100',
|
||||
Name: 'Mismatched Meta Row',
|
||||
Type: 'Structured Note',
|
||||
},
|
||||
// Duplicate EOD sourceId -> Stage A quarantines both as `duplicate_source_id`.
|
||||
// Must NOT supply a type for CA7800871021.
|
||||
{
|
||||
eodSearchCode: 'DUP.TO',
|
||||
Code: 'RY',
|
||||
Exchange: 'TO',
|
||||
Country: 'Canada',
|
||||
Currency: 'CAD',
|
||||
Isin: 'CA7800871021',
|
||||
Name: 'Royal Bank Dup 1',
|
||||
Type: 'Preferred Stock',
|
||||
},
|
||||
{
|
||||
eodSearchCode: 'DUP.TO',
|
||||
Code: 'RY',
|
||||
Exchange: 'TO',
|
||||
Country: 'Canada',
|
||||
Currency: 'CAD',
|
||||
Isin: 'CA7800871021',
|
||||
Name: 'Royal Bank Dup 2',
|
||||
Type: 'Preferred Stock',
|
||||
},
|
||||
],
|
||||
ibSymbols: [],
|
||||
qmSymbols: [],
|
||||
ceoSymbols: [],
|
||||
eodSymbolChange: [],
|
||||
},
|
||||
{ readOnly: true, applyFilterAndProjection: true }
|
||||
);
|
||||
|
||||
const sources = await readSecurityMasterSources(reader, { exchangeLookup });
|
||||
assertStatsConservation(sources.stats.eodSymbols);
|
||||
expect(sources.stats.eodSymbols.docsRead).toBe(5);
|
||||
expect(sources.stats.eodSymbols.emitted).toBe(5);
|
||||
|
||||
const stageA = matchInstrumentsStageA(sources.stageARecords);
|
||||
expect(stageA.instruments.map(i => i.primaryIsin)).toEqual(['US0378331005']);
|
||||
expect(stageA.instruments[0]?.members.map(m => m.sourceId)).toEqual(['AAPL.US']);
|
||||
expect(
|
||||
stageA.conflicts.map(c => `${c.sourceId}:${c.conflictKind}`).sort(compareAscii)
|
||||
).toEqual([
|
||||
'AAPL_STALE.US:isin_cusip_mismatch',
|
||||
'BAD_ONLY.US:isin_cusip_mismatch',
|
||||
'DUP.TO:duplicate_source_id',
|
||||
'DUP.TO:duplicate_source_id',
|
||||
]);
|
||||
|
||||
// Loader-facing map contains ONLY the Stage A-accepted member's type ('common'), with zero conflicts.
|
||||
expect([...sources.securityTypeByIsin.entries()]).toEqual([['US0378331005', 'common']]);
|
||||
expect(sources.securityTypeConflicts).toEqual([]);
|
||||
expect(sources.securityTypeByIsin.has('US30303M1027')).toBe(false);
|
||||
expect(sources.securityTypeByIsin.has('CA7800871021')).toBe(false);
|
||||
expect(sources.securityTypeStats).toEqual({
|
||||
recordsIn: 1,
|
||||
classified: 1,
|
||||
missingIsin: 0,
|
||||
missingType: 0,
|
||||
unknownType: 0,
|
||||
distinctClassifiedIsins: 1,
|
||||
isinsMapped: 1,
|
||||
isinsConflicting: 0,
|
||||
conflictsTruncated: 0,
|
||||
});
|
||||
|
||||
// Helper produces the identical loader-facing map when called explicitly after Stage A.
|
||||
const explicitStageAMap = buildSecurityTypeByIsinForStageA(
|
||||
sources.securityTypeRecords,
|
||||
stageA.instruments
|
||||
);
|
||||
expect([...explicitStageAMap.securityTypeByIsin.entries()]).toEqual([
|
||||
...sources.securityTypeByIsin.entries(),
|
||||
]);
|
||||
|
||||
// All 5 emitted EOD rows remain available in `securityTypeRecords` for raw vocabulary diagnostics.
|
||||
expect(sources.securityTypeRecords.length).toBe(5);
|
||||
const rawDiagnostics = buildSecurityTypeByIsin(sources.securityTypeRecords);
|
||||
expect(rawDiagnostics.unknownRawTypes).toEqual([{ rawType: 'Structured Note', count: 1 }]);
|
||||
});
|
||||
|
||||
test('local benchmark: >= 368k synthetic docs (300k eod + 50k qm + 18k ib) sustain >= 25,000 docs/s', async () => {
|
||||
const EOD_COUNT = 300_000;
|
||||
const QM_COUNT = 50_000;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue