T-60: M1.1g — Pass 6: pure in-memory OTC delisting chain linker (same-ISIN primary venue → OTC continuation, SIVB → SIVBQ) + delist reason / Shumway terminal return
This commit is contained in:
parent
cef3adad5e
commit
19e77d68aa
2 changed files with 256 additions and 128 deletions
|
|
@ -236,6 +236,8 @@ describe('security master Pass 6 OTC delisting chain linker', () => {
|
|||
assertReconciliationAndContracts(finalResult, 2);
|
||||
|
||||
// As-of 2023-03-15: SIVB is still within 10-day grace window, and SIVBQ has not started yet -> no look-ahead link.
|
||||
// Note: delistReason 'active' is strictly a delisting status (not delisted as of asOfDate), not
|
||||
// universe membership; historical callers must filter listings by listedFrom <= asOfDate.
|
||||
const sweepHalted = linkDelistingChains(
|
||||
{ listings, otcMics: DEFAULT_OTC_MICS },
|
||||
{ asOfDate: '2023-03-15' }
|
||||
|
|
@ -245,6 +247,9 @@ describe('security master Pass 6 OTC delisting chain linker', () => {
|
|||
expect(sweepHalted.listingOutcomes.find(o => o.listingKey.tickerRoot === 'SIVB')).toMatchObject(
|
||||
{ delistReason: 'active', terminalReturn: null }
|
||||
);
|
||||
expect(
|
||||
sweepHalted.listingOutcomes.find(o => o.listingKey.tickerRoot === 'SIVBQ')
|
||||
).toMatchObject({ delistReason: 'active', terminalReturn: null });
|
||||
assertReconciliationAndContracts(sweepHalted, 2);
|
||||
|
||||
// As-of 2023-03-28: SIVB is ended (18d > 10d grace), SIVBQ starts today -> linked, SIVBQ still active.
|
||||
|
|
@ -1057,4 +1062,88 @@ describe('security master Pass 6 OTC delisting chain linker', () => {
|
|||
).toBe(TOTAL);
|
||||
assertReconciliationAndContracts(result, TOTAL);
|
||||
});
|
||||
|
||||
test('dense same-ISIN groups stay O(n log n) without edge enumeration or quadratic null-start conflicts', () => {
|
||||
const SIDE_COUNT = 5_000;
|
||||
const denseAmbiguousListings: StageBListingCandidate[] = [];
|
||||
for (let i = 0; i < SIDE_COUNT; i++) {
|
||||
denseAmbiguousListings.push(
|
||||
makeListing({
|
||||
primaryIsin: 'US9999990001',
|
||||
mic: 'XNAS',
|
||||
tickerRoot: `DP${i}`,
|
||||
listedFrom: '2015-01-02',
|
||||
listedTo: '2023-03-10',
|
||||
}),
|
||||
makeListing({
|
||||
primaryIsin: 'US9999990001',
|
||||
mic: 'OTCM',
|
||||
tickerRoot: `DO${i}`,
|
||||
listedFrom: '2023-03-20',
|
||||
listedTo: '2024-01-01',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const startAmbiguousMs = performance.now();
|
||||
const ambiguousResult = linkDelistingChains(
|
||||
{ listings: denseAmbiguousListings, otcMics: DEFAULT_OTC_MICS },
|
||||
{ asOfDate: '2025-11-27' }
|
||||
);
|
||||
const ambiguousElapsedMs = performance.now() - startAmbiguousMs;
|
||||
|
||||
process.stdout.write(
|
||||
`[benchmark] dense same-ISIN ambiguous (${SIDE_COUNT}x${SIDE_COUNT} = 25M potential edges): ${ambiguousElapsedMs.toFixed(1)} ms\n`
|
||||
);
|
||||
|
||||
expect(ambiguousElapsedMs).toBeLessThan(1000);
|
||||
expect(ambiguousResult.continuities).toEqual([]);
|
||||
expect(ambiguousResult.conflicts).toHaveLength(1);
|
||||
expect(ambiguousResult.conflicts[0]?.conflictKind).toBe('ambiguous_otc_continuation');
|
||||
expect(ambiguousResult.conflicts[0]?.detail.fromListingKeys).toHaveLength(SIDE_COUNT);
|
||||
expect(ambiguousResult.conflicts[0]?.detail.toListingKeys).toHaveLength(SIDE_COUNT);
|
||||
expect(ambiguousResult.conflicts[0]?.detail.candidateListingKeys).toHaveLength(SIDE_COUNT * 2);
|
||||
assertReconciliationAndContracts(ambiguousResult, SIDE_COUNT * 2);
|
||||
|
||||
// Dense same-ISIN group with undated OTC rows (listedFrom: null) consolidates into 1 conflict per group.
|
||||
const denseNullStartListings: StageBListingCandidate[] = [];
|
||||
for (let i = 0; i < SIDE_COUNT; i++) {
|
||||
denseNullStartListings.push(
|
||||
makeListing({
|
||||
primaryIsin: 'US9999990002',
|
||||
mic: 'XNYS',
|
||||
tickerRoot: `NP${i}`,
|
||||
listedFrom: '2015-01-02',
|
||||
listedTo: '2023-03-10',
|
||||
}),
|
||||
makeListing({
|
||||
primaryIsin: 'US9999990002',
|
||||
mic: 'OTCM',
|
||||
tickerRoot: `NO${i}`,
|
||||
listedFrom: null,
|
||||
listedTo: '2024-01-01',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const startNullMs = performance.now();
|
||||
const nullStartResult = linkDelistingChains(
|
||||
{ listings: denseNullStartListings, otcMics: DEFAULT_OTC_MICS },
|
||||
{ asOfDate: '2025-11-27' }
|
||||
);
|
||||
const nullStartElapsedMs = performance.now() - startNullMs;
|
||||
|
||||
process.stdout.write(
|
||||
`[benchmark] dense same-ISIN null-start OTC (${SIDE_COUNT}x${SIDE_COUNT}): ${nullStartElapsedMs.toFixed(1)} ms\n`
|
||||
);
|
||||
|
||||
expect(nullStartElapsedMs).toBeLessThan(1000);
|
||||
expect(nullStartResult.continuities).toEqual([]);
|
||||
expect(nullStartResult.conflicts).toHaveLength(1);
|
||||
expect(nullStartResult.conflicts[0]?.conflictKind).toBe('missing_otc_listed_from');
|
||||
expect(nullStartResult.conflicts[0]?.detail.fromListingKeys).toHaveLength(SIDE_COUNT);
|
||||
expect(nullStartResult.conflicts[0]?.detail.toListingKeys).toHaveLength(SIDE_COUNT);
|
||||
expect(nullStartResult.conflicts[0]?.detail.candidateListingKeys).toHaveLength(SIDE_COUNT * 2);
|
||||
assertReconciliationAndContracts(nullStartResult, SIDE_COUNT * 2);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue