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
|
|
@ -42,6 +42,13 @@ export interface DelistingContinuityCandidate {
|
||||||
kind: DelistingContinuityKind;
|
kind: DelistingContinuityKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delisting classification for a single listing as of `options.asOfDate`.
|
||||||
|
*
|
||||||
|
* Note: `delistReason: 'active'` indicates delisting status (not delisted as of `asOfDate`),
|
||||||
|
* not point-in-time universe eligibility. Historical callers must filter listings by
|
||||||
|
* `listedFrom <= asOfDate` before using outcomes for universe membership.
|
||||||
|
*/
|
||||||
export interface ListingDelistOutcome {
|
export interface ListingDelistOutcome {
|
||||||
listingKey: ListingNaturalKey;
|
listingKey: ListingNaturalKey;
|
||||||
delistReason: Pass6DelistReason;
|
delistReason: Pass6DelistReason;
|
||||||
|
|
@ -290,13 +297,40 @@ function normalizeKeyFromListing(listing: StageBListingCandidate): ListingNatura
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function lowerBoundByListedFromDay(otcs: readonly EligibleOtcRow[], targetDay: number): number {
|
interface OtcPrimaryInterval {
|
||||||
|
readonly startIdx: number;
|
||||||
|
readonly endIdx: number;
|
||||||
|
readonly otcIdx: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lowerBoundPrimaryByListedToDay(
|
||||||
|
primaries: readonly EndedPrimaryRow[],
|
||||||
|
targetDay: number
|
||||||
|
): number {
|
||||||
let lo = 0;
|
let lo = 0;
|
||||||
let hi = otcs.length;
|
let hi = primaries.length;
|
||||||
while (lo < hi) {
|
while (lo < hi) {
|
||||||
const mid = (lo + hi) >>> 1;
|
const mid = (lo + hi) >>> 1;
|
||||||
const midRow = otcs[mid];
|
const midRow = primaries[mid];
|
||||||
if (midRow !== undefined && midRow.listedFromDay < targetDay) {
|
if (midRow !== undefined && midRow.listedToDay < targetDay) {
|
||||||
|
lo = mid + 1;
|
||||||
|
} else {
|
||||||
|
hi = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
function upperBoundPrimaryByListedToDay(
|
||||||
|
primaries: readonly EndedPrimaryRow[],
|
||||||
|
targetDay: number
|
||||||
|
): number {
|
||||||
|
let lo = 0;
|
||||||
|
let hi = primaries.length;
|
||||||
|
while (lo < hi) {
|
||||||
|
const mid = (lo + hi) >>> 1;
|
||||||
|
const midRow = primaries[mid];
|
||||||
|
if (midRow !== undefined && midRow.listedToDay <= targetDay) {
|
||||||
lo = mid + 1;
|
lo = mid + 1;
|
||||||
} else {
|
} else {
|
||||||
hi = mid;
|
hi = mid;
|
||||||
|
|
@ -312,6 +346,10 @@ function lowerBoundByListedFromDay(otcs: readonly EligibleOtcRow[], targetDay: n
|
||||||
* (e.g. `SIVB` on `XNAS` -> `SIVBQ` on `OTCM`), classifies each listing's `delistReason`
|
* (e.g. `SIVB` on `XNAS` -> `SIVBQ` on `OTCM`), classifies each listing's `delistReason`
|
||||||
* and Shumway/bankruptcy `terminalReturn`, and quarantines ambiguous candidates as typed
|
* and Shumway/bankruptcy `terminalReturn`, and quarantines ambiguous candidates as typed
|
||||||
* conflicts without guessing.
|
* conflicts without guessing.
|
||||||
|
*
|
||||||
|
* Note: `delistReason: 'active'` is strictly a delisting status ("not delisted as of
|
||||||
|
* `options.asOfDate`"). Historical callers must filter listings by `listedFrom <= asOfDate`
|
||||||
|
* before using outcomes for point-in-time universe membership.
|
||||||
*/
|
*/
|
||||||
export function linkDelistingChains(
|
export function linkDelistingChains(
|
||||||
input: DelistingChainInput,
|
input: DelistingChainInput,
|
||||||
|
|
@ -515,22 +553,29 @@ export function linkDelistingChains(
|
||||||
const sortedPrimaryKeys = group.endedPrimaries
|
const sortedPrimaryKeys = group.endedPrimaries
|
||||||
.map(p => p.key)
|
.map(p => p.key)
|
||||||
.sort(compareListingNaturalKey);
|
.sort(compareListingNaturalKey);
|
||||||
for (const otc of group.missingFromOtcs) {
|
const sortedMissingOtcKeys = group.missingFromOtcs
|
||||||
const allKeys = [...sortedPrimaryKeys, otc.key].sort(compareListingNaturalKey);
|
.map(o => o.key)
|
||||||
conflicts.push({
|
.sort(compareListingNaturalKey);
|
||||||
conflictKind: 'missing_otc_listed_from',
|
const allKeys = [...sortedPrimaryKeys, ...sortedMissingOtcKeys].sort(
|
||||||
detail: {
|
compareListingNaturalKey
|
||||||
primaryIsin: group.primaryIsin,
|
);
|
||||||
currency: group.currency,
|
const singleOtc = group.missingFromOtcs.length === 1 ? group.missingFromOtcs[0] : undefined;
|
||||||
fromListingKeys: sortedPrimaryKeys.map(cloneListingKey),
|
conflicts.push({
|
||||||
toListingKeys: [cloneListingKey(otc.key)],
|
conflictKind: 'missing_otc_listed_from',
|
||||||
candidateListingKeys: allKeys.map(cloneListingKey),
|
detail: {
|
||||||
listedFrom: null,
|
primaryIsin: group.primaryIsin,
|
||||||
listedTo: otc.listedTo,
|
currency: group.currency,
|
||||||
reason: 'OTC listing has null listedFrom; cannot establish transfer window or effectiveDate',
|
fromListingKeys: sortedPrimaryKeys.map(cloneListingKey),
|
||||||
},
|
toListingKeys: sortedMissingOtcKeys.map(cloneListingKey),
|
||||||
});
|
candidateListingKeys: allKeys.map(cloneListingKey),
|
||||||
}
|
listedFrom: null,
|
||||||
|
listedTo: singleOtc !== undefined ? singleOtc.listedTo : null,
|
||||||
|
reason:
|
||||||
|
group.missingFromOtcs.length === 1
|
||||||
|
? 'OTC listing has null listedFrom; cannot establish transfer window or effectiveDate'
|
||||||
|
: `${group.missingFromOtcs.length} OTC listings have null listedFrom; cannot establish transfer window or effectiveDate`,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.eligibleOtcs.length === 0) {
|
if (group.eligibleOtcs.length === 0) {
|
||||||
|
|
@ -539,92 +584,63 @@ export function linkDelistingChains(
|
||||||
|
|
||||||
const primaries = group.endedPrimaries;
|
const primaries = group.endedPrimaries;
|
||||||
const otcs = group.eligibleOtcs;
|
const otcs = group.eligibleOtcs;
|
||||||
otcs.sort(
|
primaries.sort(
|
||||||
(a, b) => a.listedFromDay - b.listedFromDay || compareListingNaturalKey(a.key, b.key)
|
(a, b) => a.listedToDay - b.listedToDay || compareListingNaturalKey(a.key, b.key)
|
||||||
);
|
);
|
||||||
|
|
||||||
const primaryAdj: number[][] = Array.from({ length: primaries.length }, () => []);
|
// For each eligible OTC listing, its matching ended primaries form a contiguous index
|
||||||
const otcAdj: number[][] = Array.from({ length: otcs.length }, () => []);
|
// range [startIdx, endIdx] in `primaries` sorted by `listedToDay`:
|
||||||
|
// otc.listedFromDay - maxTransferGapDays <= primary.listedToDay
|
||||||
for (let pIdx = 0; pIdx < primaries.length; pIdx++) {
|
// primary.listedToDay <= min(otc.listedFromDay + overlapToleranceDays, otc.listedToDay ?? +inf)
|
||||||
const primary = primaries[pIdx];
|
// Merging overlapping intervals finds all bipartite connected components in O((P + O) log (P + O))
|
||||||
if (primary === undefined) {
|
// time and O(P + O) memory without enumerating O(P * O) candidate edges.
|
||||||
|
const intervals: OtcPrimaryInterval[] = [];
|
||||||
|
for (let oIdx = 0; oIdx < otcs.length; oIdx++) {
|
||||||
|
const otc = otcs[oIdx];
|
||||||
|
if (otc === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const minDay = primary.listedToDay - overlapToleranceDays;
|
const lowDay = otc.listedFromDay - maxTransferGapDays;
|
||||||
const maxDay = primary.listedToDay + maxTransferGapDays;
|
const maxWindowDay = otc.listedFromDay + overlapToleranceDays;
|
||||||
let oIdx = lowerBoundByListedFromDay(otcs, minDay);
|
// Reject OTC stubs that had already ended before the primary listing ended.
|
||||||
while (oIdx < otcs.length) {
|
const highDay =
|
||||||
const otc = otcs[oIdx];
|
otc.listedToDay === null || otc.listedToDay > maxWindowDay
|
||||||
if (otc === undefined || otc.listedFromDay > maxDay) {
|
? maxWindowDay
|
||||||
break;
|
: otc.listedToDay;
|
||||||
}
|
if (lowDay > highDay) {
|
||||||
// Reject OTC stubs that had already ended before the primary listing ended.
|
continue;
|
||||||
if (otc.listedToDay === null || otc.listedToDay >= primary.listedToDay) {
|
}
|
||||||
primaryAdj[pIdx]?.push(oIdx);
|
const startIdx = lowerBoundPrimaryByListedToDay(primaries, lowDay);
|
||||||
otcAdj[oIdx]?.push(pIdx);
|
const endExclusive = upperBoundPrimaryByListedToDay(primaries, highDay);
|
||||||
}
|
if (startIdx < endExclusive) {
|
||||||
oIdx += 1;
|
intervals.push({ startIdx, endIdx: endExclusive - 1, otcIdx: oIdx });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Partition bipartite candidate edges into connected components.
|
if (intervals.length === 0) {
|
||||||
const visitedPrimary = new Uint8Array(primaries.length);
|
continue;
|
||||||
const visitedOtc = new Uint8Array(otcs.length);
|
}
|
||||||
|
|
||||||
for (let startP = 0; startP < primaries.length; startP++) {
|
intervals.sort(
|
||||||
const startNeighbors = primaryAdj[startP];
|
(a, b) => a.startIdx - b.startIdx || a.endIdx - b.endIdx || a.otcIdx - b.otcIdx
|
||||||
if (visitedPrimary[startP] === 1 || startNeighbors === undefined || startNeighbors.length === 0) {
|
);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const compPrimaries: number[] = [];
|
const firstInterval = intervals[0];
|
||||||
const compOtcs: number[] = [];
|
if (firstInterval === undefined) {
|
||||||
const primaryQueue: number[] = [startP];
|
continue;
|
||||||
const otcQueue: number[] = [];
|
}
|
||||||
visitedPrimary[startP] = 1;
|
|
||||||
|
|
||||||
while (primaryQueue.length > 0 || otcQueue.length > 0) {
|
let compStart = firstInterval.startIdx;
|
||||||
while (primaryQueue.length > 0) {
|
let compEnd = firstInterval.endIdx;
|
||||||
const pIdx = primaryQueue.pop();
|
let compOtcs: number[] = [firstInterval.otcIdx];
|
||||||
if (pIdx === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
compPrimaries.push(pIdx);
|
|
||||||
const neighbors = primaryAdj[pIdx];
|
|
||||||
if (neighbors !== undefined) {
|
|
||||||
for (let k = 0; k < neighbors.length; k++) {
|
|
||||||
const oIdx = neighbors[k];
|
|
||||||
if (oIdx !== undefined && visitedOtc[oIdx] === 0) {
|
|
||||||
visitedOtc[oIdx] = 1;
|
|
||||||
otcQueue.push(oIdx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (otcQueue.length > 0) {
|
|
||||||
const oIdx = otcQueue.pop();
|
|
||||||
if (oIdx === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
compOtcs.push(oIdx);
|
|
||||||
const neighbors = otcAdj[oIdx];
|
|
||||||
if (neighbors !== undefined) {
|
|
||||||
for (let k = 0; k < neighbors.length; k++) {
|
|
||||||
const pIdx = neighbors[k];
|
|
||||||
if (pIdx !== undefined && visitedPrimary[pIdx] === 0) {
|
|
||||||
visitedPrimary[pIdx] = 1;
|
|
||||||
primaryQueue.push(pIdx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compPrimaries.length === 1 && compOtcs.length === 1) {
|
const flushComponent = (startIdx: number, endIdx: number, otcIndices: readonly number[]): void => {
|
||||||
const pIdx = compPrimaries[0];
|
const primaryCount = endIdx - startIdx + 1;
|
||||||
const oIdx = compOtcs[0];
|
const otcCount = otcIndices.length;
|
||||||
const primary = pIdx !== undefined ? primaries[pIdx] : undefined;
|
|
||||||
|
if (primaryCount === 1 && otcCount === 1) {
|
||||||
|
const primary = primaries[startIdx];
|
||||||
|
const oIdx = otcIndices[0];
|
||||||
const otc = oIdx !== undefined ? otcs[oIdx] : undefined;
|
const otc = oIdx !== undefined ? otcs[oIdx] : undefined;
|
||||||
if (primary !== undefined && otc !== undefined) {
|
if (primary !== undefined && otc !== undefined) {
|
||||||
linkedPrimaryIndices.add(primary.index);
|
linkedPrimaryIndices.add(primary.index);
|
||||||
|
|
@ -638,42 +654,63 @@ export function linkDelistingChains(
|
||||||
kind: CONTINUITY_KIND_OTC_DELIST_TRANSFER,
|
kind: CONTINUITY_KIND_OTC_DELIST_TRANSFER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromKeys: ListingNaturalKey[] = [];
|
||||||
|
for (let pIdx = startIdx; pIdx <= endIdx; pIdx++) {
|
||||||
|
const p = primaries[pIdx];
|
||||||
|
if (p !== undefined) {
|
||||||
|
fromKeys.push(p.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fromKeys.sort(compareListingNaturalKey);
|
||||||
|
|
||||||
|
const toKeys: ListingNaturalKey[] = [];
|
||||||
|
for (let k = 0; k < otcIndices.length; k++) {
|
||||||
|
const oIdx = otcIndices[k];
|
||||||
|
const o = oIdx !== undefined ? otcs[oIdx] : undefined;
|
||||||
|
if (o !== undefined) {
|
||||||
|
toKeys.push(o.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toKeys.sort(compareListingNaturalKey);
|
||||||
|
|
||||||
|
const allKeys = [...fromKeys, ...toKeys].sort(compareListingNaturalKey);
|
||||||
|
|
||||||
|
conflicts.push({
|
||||||
|
conflictKind: 'ambiguous_otc_continuation',
|
||||||
|
detail: {
|
||||||
|
primaryIsin: group.primaryIsin,
|
||||||
|
currency: group.currency,
|
||||||
|
fromListingKeys: fromKeys.map(cloneListingKey),
|
||||||
|
toListingKeys: toKeys.map(cloneListingKey),
|
||||||
|
candidateListingKeys: allKeys.map(cloneListingKey),
|
||||||
|
listedFrom: null,
|
||||||
|
listedTo: null,
|
||||||
|
reason: `Ambiguous OTC delisting continuation component (${primaryCount} primary, ${otcCount} OTC)`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 1; i < intervals.length; i++) {
|
||||||
|
const interval = intervals[i];
|
||||||
|
if (interval === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (interval.startIdx <= compEnd) {
|
||||||
|
if (interval.endIdx > compEnd) {
|
||||||
|
compEnd = interval.endIdx;
|
||||||
|
}
|
||||||
|
compOtcs.push(interval.otcIdx);
|
||||||
} else {
|
} else {
|
||||||
const fromKeys: ListingNaturalKey[] = [];
|
flushComponent(compStart, compEnd, compOtcs);
|
||||||
for (const idx of compPrimaries) {
|
compStart = interval.startIdx;
|
||||||
const p = primaries[idx];
|
compEnd = interval.endIdx;
|
||||||
if (p !== undefined) {
|
compOtcs = [interval.otcIdx];
|
||||||
fromKeys.push(p.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fromKeys.sort(compareListingNaturalKey);
|
|
||||||
|
|
||||||
const toKeys: ListingNaturalKey[] = [];
|
|
||||||
for (const idx of compOtcs) {
|
|
||||||
const o = otcs[idx];
|
|
||||||
if (o !== undefined) {
|
|
||||||
toKeys.push(o.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toKeys.sort(compareListingNaturalKey);
|
|
||||||
|
|
||||||
const allKeys = [...fromKeys, ...toKeys].sort(compareListingNaturalKey);
|
|
||||||
|
|
||||||
conflicts.push({
|
|
||||||
conflictKind: 'ambiguous_otc_continuation',
|
|
||||||
detail: {
|
|
||||||
primaryIsin: group.primaryIsin,
|
|
||||||
currency: group.currency,
|
|
||||||
fromListingKeys: fromKeys.map(cloneListingKey),
|
|
||||||
toListingKeys: toKeys.map(cloneListingKey),
|
|
||||||
candidateListingKeys: allKeys.map(cloneListingKey),
|
|
||||||
listedFrom: null,
|
|
||||||
listedTo: null,
|
|
||||||
reason: `Ambiguous OTC delisting continuation component (${compPrimaries.length} primary, ${compOtcs.length} OTC)`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
flushComponent(compStart, compEnd, compOtcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass 3: classify every valid unique listing into its delistReason and terminalReturn.
|
// Pass 3: classify every valid unique listing into its delistReason and terminalReturn.
|
||||||
|
|
@ -697,6 +734,8 @@ export function linkDelistingChains(
|
||||||
delistReason = 'moved_to_otc';
|
delistReason = 'moved_to_otc';
|
||||||
terminalReturn = null;
|
terminalReturn = null;
|
||||||
} else if (row.listedToDay === null || row.listedToDay >= activeCutoffDay) {
|
} else if (row.listedToDay === null || row.listedToDay >= activeCutoffDay) {
|
||||||
|
// 'active' is a delisting status (not delisted as of options.asOfDate), not a
|
||||||
|
// universe-membership flag; historical callers must filter by listedFrom <= asOfDate.
|
||||||
delistReason = 'active';
|
delistReason = 'active';
|
||||||
terminalReturn = null;
|
terminalReturn = null;
|
||||||
} else if (!row.isOtc) {
|
} else if (!row.isOtc) {
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,8 @@ describe('security master Pass 6 OTC delisting chain linker', () => {
|
||||||
assertReconciliationAndContracts(finalResult, 2);
|
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.
|
// 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(
|
const sweepHalted = linkDelistingChains(
|
||||||
{ listings, otcMics: DEFAULT_OTC_MICS },
|
{ listings, otcMics: DEFAULT_OTC_MICS },
|
||||||
{ asOfDate: '2023-03-15' }
|
{ 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(
|
expect(sweepHalted.listingOutcomes.find(o => o.listingKey.tickerRoot === 'SIVB')).toMatchObject(
|
||||||
{ delistReason: 'active', terminalReturn: null }
|
{ delistReason: 'active', terminalReturn: null }
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
sweepHalted.listingOutcomes.find(o => o.listingKey.tickerRoot === 'SIVBQ')
|
||||||
|
).toMatchObject({ delistReason: 'active', terminalReturn: null });
|
||||||
assertReconciliationAndContracts(sweepHalted, 2);
|
assertReconciliationAndContracts(sweepHalted, 2);
|
||||||
|
|
||||||
// As-of 2023-03-28: SIVB is ended (18d > 10d grace), SIVBQ starts today -> linked, SIVBQ still active.
|
// 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);
|
).toBe(TOTAL);
|
||||||
assertReconciliationAndContracts(result, 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