T-68: Bug sweep (5 bugs: T-58, T-59, T-61, T-62, T-63)

This commit is contained in:
Studio 2026-11-27 20:27:55 -05:00
parent dea894695a
commit 99ed9bc5a9
2 changed files with 365 additions and 27 deletions

View file

@ -2237,6 +2237,271 @@ describe('security master Pass 3 Stage B listing matcher', () => {
assertReconciliationAndContracts(undatedMetaResult);
});
test('quarantines disjoint returning-ticker alias windows while merging adjacent or overlapping windows (T-59)', () => {
const instruments: StageAInstrumentCandidate[] = [
{
primaryIsin: 'US7777777777',
primaryCusip: null,
issuerCountry: 'US',
canonicalName: 'Returning Ticker Corp',
members: [{ source: 'eod', sourceId: 'CUR.US', currency: 'USD', method: 'tier1_isin' }],
},
];
const eodListings: StageBEodListingInput[] = [
{
sourceId: 'CUR.US',
ticker: 'CUR',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2010-01-04', lastBarDate: '2025-11-26' },
},
];
// Listing used OLD through 2015, changed to MID for 2016-2019, returned to OLD for 2020-2021,
// then changed to CUR on 2022-01-01. Also includes adjacent, overlapping, and 1-day-gap aliases.
const symbolChanges: StageBSymbolChangeInput[] = [
{ eodSourceId: 'CUR.US', oldTicker: 'OLD', effectiveDate: '2016-01-01' },
{
eodSourceId: 'CUR.US',
oldTicker: 'MID',
validFrom: '2016-01-01',
effectiveDate: '2020-01-01',
},
{
eodSourceId: 'CUR.US',
oldTicker: 'OLD',
validFrom: '2020-01-01',
effectiveDate: '2022-01-01',
},
// Adjacent windows: 2014-01-01..2015-12-31 and 2016-01-01..2017-12-31
{
eodSourceId: 'CUR.US',
oldTicker: 'ADJ',
validFrom: '2014-01-01',
effectiveDate: '2016-01-01',
},
{
eodSourceId: 'CUR.US',
oldTicker: 'ADJ',
validFrom: '2016-01-01',
effectiveDate: '2018-01-01',
},
// Overlapping windows: 2014-01-01..2016-06-30 and 2016-01-01..2017-12-31
{
eodSourceId: 'CUR.US',
oldTicker: 'OVL',
validFrom: '2014-01-01',
effectiveDate: '2016-07-01',
},
{
eodSourceId: 'CUR.US',
oldTicker: 'OVL',
validFrom: '2016-01-01',
effectiveDate: '2018-01-01',
},
// 1-day gap: 2014-01-01..2015-12-31 and 2016-01-02..2017-12-31 (2016-01-01 missing)
{
eodSourceId: 'CUR.US',
oldTicker: 'GAP1',
validFrom: '2014-01-01',
effectiveDate: '2016-01-01',
},
{
eodSourceId: 'CUR.US',
oldTicker: 'GAP1',
validFrom: '2016-01-02',
effectiveDate: '2018-01-01',
},
];
const tickerSources: StageBTickerSourceInput[] = [
{
source: 'qm',
sourceId: 'QM_OLD_SPANS_BOTH_WINDOWS',
ticker: 'OLD',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2015-01-02', lastBarDate: '2021-12-31' },
},
{
source: 'qm',
sourceId: 'QM_OLD_WINDOW1_ONLY',
ticker: 'OLD',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2015-01-02', lastBarDate: '2015-12-31' },
},
{
source: 'qm',
sourceId: 'QM_OLD_WINDOW2_ONLY',
ticker: 'OLD',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2020-01-02', lastBarDate: '2021-12-31' },
},
{
source: 'qm',
sourceId: 'QM_OLD_IN_MID_GAP',
ticker: 'OLD',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2016-01-04', lastBarDate: '2019-12-31' },
},
{
source: 'qm',
sourceId: 'QM_MID_2016_2019',
ticker: 'MID',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2016-01-04', lastBarDate: '2019-12-31' },
},
{
source: 'qm',
sourceId: 'QM_ADJ_MERGES',
ticker: 'ADJ',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2015-06-01', lastBarDate: '2016-06-30' },
},
{
source: 'qm',
sourceId: 'QM_OVL_MERGES',
ticker: 'OVL',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2015-06-01', lastBarDate: '2016-09-30' },
},
{
source: 'qm',
sourceId: 'QM_GAP1_QUARANTINED',
ticker: 'GAP1',
mic: 'XNAS',
role: 'primary_venue',
currency: 'USD',
span: { firstBarDate: '2015-06-01', lastBarDate: '2016-06-30' },
},
];
const baseline = matchListingsStageB({
instruments,
eodListings,
ibContracts: [],
tickerSources,
symbolChanges,
});
const curKey = {
primaryIsin: 'US7777777777',
mic: 'XNAS',
tickerRoot: 'CUR',
classSuffix: '',
currency: 'USD',
};
expect(baseline.conflicts).toEqual([
{
source: 'qm',
sourceId: 'QM_GAP1_QUARANTINED',
conflictKind: 'ambiguous_ticker_span',
detail: {
primaryIsin: null,
currency: 'USD',
ibConid: null,
competingConids: [],
candidateListingKeys: [curKey],
},
},
{
source: 'qm',
sourceId: 'QM_OLD_SPANS_BOTH_WINDOWS',
conflictKind: 'ambiguous_ticker_span',
detail: {
primaryIsin: null,
currency: 'USD',
ibConid: null,
competingConids: [],
candidateListingKeys: [curKey],
},
},
]);
expect(baseline.unresolved).toEqual([
{
source: 'qm',
sourceId: 'QM_OLD_IN_MID_GAP',
reason: 'no_span_overlap',
primaryIsin: null,
},
]);
expect(baseline.providerMappings.filter(m => m.source === 'qm')).toEqual([
{
source: 'qm',
sourceId: 'QM_ADJ_MERGES',
listingKey: curKey,
method: 'tier3_ticker_span',
validFrom: '2015-06-01',
validTo: '2016-06-30',
},
{
source: 'qm',
sourceId: 'QM_MID_2016_2019',
listingKey: curKey,
method: 'tier3_ticker_span',
validFrom: '2016-01-04',
validTo: '2019-12-31',
},
{
source: 'qm',
sourceId: 'QM_OLD_WINDOW1_ONLY',
listingKey: curKey,
method: 'tier3_ticker_span',
validFrom: '2015-01-02',
validTo: '2015-12-31',
},
{
source: 'qm',
sourceId: 'QM_OLD_WINDOW2_ONLY',
listingKey: curKey,
method: 'tier3_ticker_span',
validFrom: '2020-01-02',
validTo: '2021-12-31',
},
{
source: 'qm',
sourceId: 'QM_OVL_MERGES',
listingKey: curKey,
method: 'tier3_ticker_span',
validFrom: '2015-06-01',
validTo: '2016-09-30',
},
]);
assertReconciliationAndContracts(baseline);
// Shuffle invariance across symbolChanges and tickerSources.
const baselineJson = JSON.stringify(baseline);
for (const seed of [7, 42, 999]) {
const shuffled = matchListingsStageB({
instruments,
eodListings,
ibContracts: [],
tickerSources: shuffleWithSeed(tickerSources, seed),
symbolChanges: shuffleWithSeed(symbolChanges, seed + 1),
});
expect(JSON.stringify(shuffled)).toBe(baselineJson);
}
});
test('local scale benchmark: ~20k instruments, ~60k EOD, ~18k IB, ~40k QM/CEO complete under 5000 ms', () => {
const NUM_INSTRUMENTS = 20_000;
const instruments: StageAInstrumentCandidate[] = new Array<StageAInstrumentCandidate>(