T-68: Bug sweep (5 bugs: T-58, T-59, T-61, T-62, T-63)
This commit is contained in:
parent
1692aba2fc
commit
dea894695a
2 changed files with 386 additions and 44 deletions
|
|
@ -177,9 +177,14 @@ interface ListingAccumulator {
|
|||
ibPrimaryExchange: string | null;
|
||||
}
|
||||
|
||||
interface AliasBounds {
|
||||
readonly validFrom: string | null;
|
||||
readonly validTo: string;
|
||||
}
|
||||
|
||||
interface TickerLookupCandidate {
|
||||
readonly acc: ListingAccumulator;
|
||||
readonly aliasSpan: SpanDateRange | null;
|
||||
readonly aliasBounds: AliasBounds | null;
|
||||
}
|
||||
|
||||
interface ValidatedSymbolChange {
|
||||
|
|
@ -955,7 +960,7 @@ export function matchListingsStageB(
|
|||
tickerList = [];
|
||||
listingsByTickerKey.set(tickerKey, tickerList);
|
||||
}
|
||||
tickerList.push({ acc, aliasSpan: null });
|
||||
tickerList.push({ acc, aliasBounds: null });
|
||||
} else if (validSpan !== null) {
|
||||
// Associative & commutative min/max widening ensures shuffle invariance.
|
||||
if (acc.listedFrom === null || validSpan.firstBarDate < acc.listedFrom) {
|
||||
|
|
@ -996,31 +1001,18 @@ export function matchListingsStageB(
|
|||
change.oldTickerRoot,
|
||||
change.oldClassSuffix
|
||||
);
|
||||
let candidate: TickerLookupCandidate | null = null;
|
||||
if (acc.listedFrom === null || acc.listedTo === null) {
|
||||
candidate = { acc, aliasSpan: null };
|
||||
} else {
|
||||
const aliasFrom =
|
||||
change.validFrom !== null && change.validFrom > acc.listedFrom
|
||||
? change.validFrom
|
||||
: acc.listedFrom;
|
||||
const aliasTo =
|
||||
change.dayBeforeEffective < acc.listedTo ? change.dayBeforeEffective : acc.listedTo;
|
||||
if (aliasFrom <= aliasTo) {
|
||||
candidate = {
|
||||
acc,
|
||||
aliasSpan: { firstBarDate: aliasFrom, lastBarDate: aliasTo },
|
||||
};
|
||||
}
|
||||
}
|
||||
if (candidate !== null) {
|
||||
let tickerList = listingsByTickerKey.get(aliasTickerKey);
|
||||
if (tickerList === undefined) {
|
||||
tickerList = [];
|
||||
listingsByTickerKey.set(aliasTickerKey, tickerList);
|
||||
}
|
||||
tickerList.push(candidate);
|
||||
let tickerList = listingsByTickerKey.get(aliasTickerKey);
|
||||
if (tickerList === undefined) {
|
||||
tickerList = [];
|
||||
listingsByTickerKey.set(aliasTickerKey, tickerList);
|
||||
}
|
||||
tickerList.push({
|
||||
acc,
|
||||
aliasBounds: {
|
||||
validFrom: change.validFrom,
|
||||
validTo: change.dayBeforeEffective,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
for (const [sourceId, count] of eodMetadataCounts.entries()) {
|
||||
|
|
@ -1308,7 +1300,7 @@ export function matchListingsStageB(
|
|||
continue;
|
||||
}
|
||||
|
||||
const overlappingSet = new Set<ListingAccumulator>();
|
||||
const matchedSpanByAcc = new Map<ListingAccumulator, SpanDateRange>();
|
||||
const missingSpanSet = new Set<ListingAccumulator>();
|
||||
|
||||
for (let k = 0; k < candidates.length; k++) {
|
||||
|
|
@ -1316,24 +1308,70 @@ export function matchListingsStageB(
|
|||
if (cand === undefined) {
|
||||
continue;
|
||||
}
|
||||
let candSpan: SpanDateRange | null;
|
||||
if (cand.aliasSpan !== null) {
|
||||
candSpan = cand.aliasSpan;
|
||||
} else if (cand.acc.listedFrom !== null && cand.acc.listedTo !== null) {
|
||||
candSpan = { firstBarDate: cand.acc.listedFrom, lastBarDate: cand.acc.listedTo };
|
||||
} else {
|
||||
candSpan = null;
|
||||
|
||||
if (cand.aliasBounds === null) {
|
||||
if (cand.acc.listedFrom === null || cand.acc.listedTo === null) {
|
||||
missingSpanSet.add(cand.acc);
|
||||
} else {
|
||||
const listingSpan: SpanDateRange = {
|
||||
firstBarDate: cand.acc.listedFrom,
|
||||
lastBarDate: cand.acc.listedTo,
|
||||
};
|
||||
if (spansOverlap(spanCheck.span, listingSpan, overlapOptions)) {
|
||||
matchedSpanByAcc.set(cand.acc, spanCheck.span);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (candSpan === null) {
|
||||
// Explicit symbol-change alias bounds are hard limits independent of spanOverlapToleranceDays.
|
||||
const intFrom =
|
||||
cand.aliasBounds.validFrom !== null &&
|
||||
cand.aliasBounds.validFrom > spanCheck.span.firstBarDate
|
||||
? cand.aliasBounds.validFrom
|
||||
: spanCheck.span.firstBarDate;
|
||||
const intTo =
|
||||
cand.aliasBounds.validTo < spanCheck.span.lastBarDate
|
||||
? cand.aliasBounds.validTo
|
||||
: spanCheck.span.lastBarDate;
|
||||
if (intFrom > intTo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cand.acc.listedFrom === null || cand.acc.listedTo === null) {
|
||||
missingSpanSet.add(cand.acc);
|
||||
} else if (spansOverlap(spanCheck.span, candSpan, overlapOptions)) {
|
||||
overlappingSet.add(cand.acc);
|
||||
continue;
|
||||
}
|
||||
|
||||
const effFrom =
|
||||
cand.aliasBounds.validFrom !== null && cand.aliasBounds.validFrom > cand.acc.listedFrom
|
||||
? cand.aliasBounds.validFrom
|
||||
: cand.acc.listedFrom;
|
||||
const effTo =
|
||||
cand.aliasBounds.validTo < cand.acc.listedTo
|
||||
? cand.aliasBounds.validTo
|
||||
: cand.acc.listedTo;
|
||||
if (effFrom > effTo) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const clampedProviderSpan: SpanDateRange = { firstBarDate: intFrom, lastBarDate: intTo };
|
||||
const aliasListingSpan: SpanDateRange = { firstBarDate: effFrom, lastBarDate: effTo };
|
||||
if (spansOverlap(clampedProviderSpan, aliasListingSpan, overlapOptions)) {
|
||||
const existing = matchedSpanByAcc.get(cand.acc);
|
||||
if (existing === undefined) {
|
||||
matchedSpanByAcc.set(cand.acc, clampedProviderSpan);
|
||||
} else {
|
||||
matchedSpanByAcc.set(cand.acc, {
|
||||
firstBarDate: intFrom < existing.firstBarDate ? intFrom : existing.firstBarDate,
|
||||
lastBarDate: intTo > existing.lastBarDate ? intTo : existing.lastBarDate,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (overlappingSet.size > 1) {
|
||||
const candidateListingKeys = Array.from(overlappingSet, c => c.key).sort(
|
||||
if (matchedSpanByAcc.size > 1) {
|
||||
const candidateListingKeys = Array.from(matchedSpanByAcc.keys(), c => c.key).sort(
|
||||
compareListingNaturalKey
|
||||
);
|
||||
conflicts.push({
|
||||
|
|
@ -1358,16 +1396,17 @@ export function matchListingsStageB(
|
|||
primaryIsin: null,
|
||||
});
|
||||
sourceStats.unresolved += 1;
|
||||
} else if (overlappingSet.size === 1) {
|
||||
const matchedListing = overlappingSet.values().next().value;
|
||||
if (matchedListing !== undefined) {
|
||||
} else if (matchedSpanByAcc.size === 1) {
|
||||
const matchedEntry = matchedSpanByAcc.entries().next().value;
|
||||
if (matchedEntry !== undefined) {
|
||||
const [matchedListing, matchedSpan] = matchedEntry;
|
||||
providerMappings.push({
|
||||
source,
|
||||
sourceId: record.sourceId,
|
||||
listingKey: matchedListing.key,
|
||||
method: 'tier3_ticker_span',
|
||||
validFrom: spanCheck.span.firstBarDate,
|
||||
validTo: spanCheck.span.lastBarDate,
|
||||
validFrom: matchedSpan.firstBarDate,
|
||||
validTo: matchedSpan.lastBarDate,
|
||||
});
|
||||
sourceStats.matched += 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue