T-105: M1.1 Pass 4b — data-pipeline: wire the 25-date sample-close reader into run-security-master.ts so the match report carries real price cross-check verdicts (read-only Mongo, tests + local benchmark)
This commit is contained in:
parent
6e8bf434f9
commit
2c9d26b1ca
4 changed files with 1554 additions and 19 deletions
|
|
@ -217,15 +217,19 @@ export {
|
|||
|
||||
export {
|
||||
assertSecurityMasterPersistSafety,
|
||||
buildSampleDateCalendar,
|
||||
formatRunSecurityMasterSummary,
|
||||
parseRunSecurityMasterArgs,
|
||||
RUN_SECURITY_MASTER_USAGE,
|
||||
runSecurityMaster,
|
||||
SECURITY_MASTER_OUTPUT_FILES,
|
||||
type ParsedRunSecurityMasterArgs,
|
||||
type Pass4SkippedReason,
|
||||
type RunSecurityMasterDeps,
|
||||
type RunSecurityMasterOptions,
|
||||
type RunSecurityMasterOutput,
|
||||
type RunSecurityMasterPass4Options,
|
||||
type RunSecurityMasterPass4Summary,
|
||||
type SecurityMasterPostgresHandle,
|
||||
} from './run-security-master';
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,18 @@ import {
|
|||
type SecurityMasterQueryable,
|
||||
type SecurityMasterQueryResult,
|
||||
} from './persist';
|
||||
import {
|
||||
DEFAULT_SAMPLE_DATE_COUNT,
|
||||
selectSampleDates,
|
||||
type PriceCrossCheckVerdictCounts,
|
||||
} from './price-cross-check';
|
||||
import { composeSecurityMasterRun, type ComposeSecurityMasterRunResult } from './run';
|
||||
import {
|
||||
MAX_SAMPLE_DATES,
|
||||
readSampleCloses,
|
||||
type ReadSampleClosesResult,
|
||||
type ReadSampleClosesStats,
|
||||
} from './sample-closes';
|
||||
import {
|
||||
createExchangeSourceLookup,
|
||||
createReadOnlyMongoSourceSymbolReader,
|
||||
|
|
@ -54,13 +65,15 @@ export const SECURITY_MASTER_OUTPUT_FILES = Object.freeze({
|
|||
} as const);
|
||||
|
||||
export const RUN_SECURITY_MASTER_USAGE = [
|
||||
'Usage: bun run apps/stock/data-pipeline/src/security-master/run-security-master.ts --as-of <YYYY-MM-DD> --out-dir <dir> [--persist] [--help]',
|
||||
'Usage: bun run apps/stock/data-pipeline/src/security-master/run-security-master.ts --as-of <YYYY-MM-DD> --out-dir <dir> [--persist] [--skip-price-cross-check] [--sample-dates <n>] [--help]',
|
||||
'',
|
||||
'Options:',
|
||||
' --as-of <YYYY-MM-DD> Required. Calendar reference date for Pass 6 delisting classification.',
|
||||
' --out-dir <dir> Required. Output directory for match-report.md, conflicts.csv, override-template.sql, and run-stats.json.',
|
||||
' --persist Optional. Persist security-master rows to isolated dev PostgreSQL after running safety guards (default: off).',
|
||||
' --help Show this help message and exit.',
|
||||
' --as-of <YYYY-MM-DD> Required. Calendar reference date for Pass 6 delisting classification.',
|
||||
' --out-dir <dir> Required. Output directory for match-report.md, conflicts.csv, override-template.sql, and run-stats.json.',
|
||||
' --persist Optional. Persist security-master rows to isolated dev PostgreSQL after running safety guards (default: off).',
|
||||
' --skip-price-cross-check Optional. Skip Pass 4 sample-close reads and price cross-checks (default: enabled).',
|
||||
` --sample-dates <n> Optional. Number of stratified sample dates for Pass 4 (1..${MAX_SAMPLE_DATES}, default: ${DEFAULT_SAMPLE_DATE_COUNT}).`,
|
||||
' --help Show this help message and exit.',
|
||||
].join('\n');
|
||||
|
||||
export type ParsedRunSecurityMasterArgs =
|
||||
|
|
@ -70,8 +83,27 @@ export type ParsedRunSecurityMasterArgs =
|
|||
readonly asOfDate: string;
|
||||
readonly outDir: string;
|
||||
readonly persist: boolean;
|
||||
readonly skipPriceCrossCheck: boolean;
|
||||
readonly sampleDateCount: number;
|
||||
};
|
||||
|
||||
export interface RunSecurityMasterPass4Options {
|
||||
readonly enabled?: boolean;
|
||||
readonly sampleDateCount?: number;
|
||||
}
|
||||
|
||||
export type Pass4SkippedReason = 'disabled' | 'no_sample_dates' | 'no_candidate_pairs';
|
||||
|
||||
export interface RunSecurityMasterPass4Summary {
|
||||
readonly sampleDates: readonly string[];
|
||||
readonly candidatePairs: number;
|
||||
readonly eodIdsRequested: number;
|
||||
readonly qmIdsRequested: number;
|
||||
readonly stats: ReadSampleClosesStats | null;
|
||||
readonly byVerdict: PriceCrossCheckVerdictCounts | null;
|
||||
readonly skippedReason: Pass4SkippedReason | null;
|
||||
}
|
||||
|
||||
export interface SecurityMasterPostgresHandle {
|
||||
readonly queryable: SecurityMasterQueryable;
|
||||
close(): Promise<void> | void;
|
||||
|
|
@ -88,6 +120,8 @@ export interface RunSecurityMasterDeps {
|
|||
| Promise<SecurityMasterPostgresHandle>
|
||||
| SecurityMasterPostgresHandle;
|
||||
readonly persistFn?: typeof persistSecurityMaster;
|
||||
readonly readSampleClosesFn?: typeof readSampleCloses;
|
||||
readonly composeFn?: typeof composeSecurityMasterRun;
|
||||
readonly writeFile?: (filePath: string, content: string) => Promise<void> | void;
|
||||
readonly writeStdout?: (text: string) => void;
|
||||
}
|
||||
|
|
@ -99,6 +133,7 @@ export interface RunSecurityMasterOptions {
|
|||
readonly countries?: readonly string[] | null;
|
||||
readonly batchSize?: number;
|
||||
readonly barSpans?: Omit<ComputeBarSpansOptions, 'sourceIdsBySource'>;
|
||||
readonly pass4?: RunSecurityMasterPass4Options;
|
||||
}
|
||||
|
||||
export interface RunSecurityMasterOutput {
|
||||
|
|
@ -110,6 +145,8 @@ export interface RunSecurityMasterOutput {
|
|||
readonly exchangeCountsByCollection: Readonly<Record<ExchangeSource, number>>;
|
||||
readonly sources: SecurityMasterSourcesResult;
|
||||
readonly barSpans: ComputeBarSpansResult;
|
||||
readonly sampleCloses: ReadSampleClosesResult | null;
|
||||
readonly pass4: RunSecurityMasterPass4Summary;
|
||||
readonly composed: ComposeSecurityMasterRunResult;
|
||||
readonly persistResult: PersistSecurityMasterResult | null;
|
||||
readonly runStatsJson: string;
|
||||
|
|
@ -117,6 +154,166 @@ export interface RunSecurityMasterOutput {
|
|||
}
|
||||
|
||||
const EXACT_YMD_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const STRICT_INT_PATTERN = /^-?\d+$/;
|
||||
const DAYS_IN_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] as const;
|
||||
|
||||
function isLeapYear(year: number): boolean {
|
||||
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
||||
}
|
||||
|
||||
function parseYmdComponents(value: string): { year: number; month: number; day: number } | null {
|
||||
if (!EXACT_YMD_PATTERN.test(value)) {
|
||||
return null;
|
||||
}
|
||||
const year =
|
||||
(value.charCodeAt(0) - 48) * 1000 +
|
||||
(value.charCodeAt(1) - 48) * 100 +
|
||||
(value.charCodeAt(2) - 48) * 10 +
|
||||
(value.charCodeAt(3) - 48);
|
||||
const month = (value.charCodeAt(5) - 48) * 10 + (value.charCodeAt(6) - 48);
|
||||
const day = (value.charCodeAt(8) - 48) * 10 + (value.charCodeAt(9) - 48);
|
||||
if (year < 1 || year > 9999 || month < 1 || month > 12) {
|
||||
return null;
|
||||
}
|
||||
const maxDay = month === 2 && isLeapYear(year) ? 29 : (DAYS_IN_MONTH[month] ?? 0);
|
||||
if (day < 1 || day > maxDay) {
|
||||
return null;
|
||||
}
|
||||
return { year, month, day };
|
||||
}
|
||||
|
||||
function daysFromCivil(year: number, month: number, day: number): number {
|
||||
const y = month <= 2 ? year - 1 : year;
|
||||
const era = Math.floor(y / 400);
|
||||
const yoe = y - era * 400;
|
||||
const doy = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;
|
||||
const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
|
||||
return era * 146097 + doe - 719468;
|
||||
}
|
||||
|
||||
function civilFromDays(daysSinceEpoch: number): { year: number; month: number; day: number } {
|
||||
const shifted = daysSinceEpoch + 719468;
|
||||
const era = Math.floor(shifted / 146097);
|
||||
const doe = shifted - era * 146097;
|
||||
const yoe = Math.floor(
|
||||
(doe - Math.floor(doe / 1460) + Math.floor(doe / 36524) - Math.floor(doe / 146096)) / 365
|
||||
);
|
||||
const y = yoe + era * 400;
|
||||
const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
|
||||
const mp = Math.floor((5 * doy + 2) / 153);
|
||||
const day = doy - Math.floor((153 * mp + 2) / 5) + 1;
|
||||
const month = mp + (mp < 10 ? 3 : -9);
|
||||
const year = y + (month <= 2 ? 1 : 0);
|
||||
return { year, month, day };
|
||||
}
|
||||
|
||||
function formatUtcYmd(year: number, month: number, day: number): string {
|
||||
const y = String(year).padStart(4, '0');
|
||||
const m = month < 10 ? `0${String(month)}` : String(month);
|
||||
const d = day < 10 ? `0${String(day)}` : String(day);
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a deterministic ascending Mon-Fri YYYY-MM-DD calendar over the overlapping
|
||||
* date window where both EOD and QM have observed bars, clamped to `asOfDate`.
|
||||
*/
|
||||
export function buildSampleDateCalendar(
|
||||
barSpans: Pick<ComputeBarSpansResult, 'index'>,
|
||||
asOfDate: string
|
||||
): string[] {
|
||||
if (!barSpans || !barSpans.index || !isValidAsOfDate(asOfDate)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let minEodFirst: string | null = null;
|
||||
let maxEodLast: string | null = null;
|
||||
let minQmFirst: string | null = null;
|
||||
let maxQmLast: string | null = null;
|
||||
|
||||
for (const span of barSpans.index) {
|
||||
if (
|
||||
!span ||
|
||||
typeof span.barCount !== 'number' ||
|
||||
!Number.isFinite(span.barCount) ||
|
||||
span.barCount <= 0
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (span.source !== 'eod' && span.source !== 'qm') {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
parseYmdComponents(span.firstBarDate) === null ||
|
||||
parseYmdComponents(span.lastBarDate) === null ||
|
||||
span.firstBarDate > span.lastBarDate
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (span.source === 'eod') {
|
||||
if (minEodFirst === null || span.firstBarDate < minEodFirst) {
|
||||
minEodFirst = span.firstBarDate;
|
||||
}
|
||||
if (maxEodLast === null || span.lastBarDate > maxEodLast) {
|
||||
maxEodLast = span.lastBarDate;
|
||||
}
|
||||
} else {
|
||||
if (minQmFirst === null || span.firstBarDate < minQmFirst) {
|
||||
minQmFirst = span.firstBarDate;
|
||||
}
|
||||
if (maxQmLast === null || span.lastBarDate > maxQmLast) {
|
||||
maxQmLast = span.lastBarDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (minEodFirst === null || maxEodLast === null || minQmFirst === null || maxQmLast === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const start = minEodFirst > minQmFirst ? minEodFirst : minQmFirst;
|
||||
const overlapEnd = maxEodLast < maxQmLast ? maxEodLast : maxQmLast;
|
||||
const end = overlapEnd < asOfDate ? overlapEnd : asOfDate;
|
||||
|
||||
if (start > end) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const startParts = parseYmdComponents(start);
|
||||
const endParts = parseYmdComponents(end);
|
||||
if (startParts === null || endParts === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const startDay = daysFromCivil(startParts.year, startParts.month, startParts.day);
|
||||
const endDay = daysFromCivil(endParts.year, endParts.month, endParts.day);
|
||||
const calendar: string[] = [];
|
||||
|
||||
for (let dayNum = startDay; dayNum <= endDay; dayNum++) {
|
||||
const dow = (((dayNum + 4) % 7) + 7) % 7;
|
||||
if (dow >= 1 && dow <= 5) {
|
||||
const civil = civilFromDays(dayNum);
|
||||
calendar.push(formatUtcYmd(civil.year, civil.month, civil.day));
|
||||
}
|
||||
}
|
||||
|
||||
return calendar;
|
||||
}
|
||||
|
||||
function parseSampleDateCountArg(raw: string): number {
|
||||
if (!STRICT_INT_PATTERN.test(raw)) {
|
||||
throw usageError(
|
||||
`Invalid --sample-dates value "${raw}": expected an integer between 1 and ${MAX_SAMPLE_DATES}`
|
||||
);
|
||||
}
|
||||
const parsed = Number(raw);
|
||||
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > MAX_SAMPLE_DATES) {
|
||||
throw usageError(
|
||||
`Invalid --sample-dates value "${raw}": expected an integer between 1 and ${MAX_SAMPLE_DATES}`
|
||||
);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function isValidAsOfDate(value: string): boolean {
|
||||
return EXACT_YMD_PATTERN.test(value) && normalizeBarDate(value) === value;
|
||||
|
|
@ -152,6 +349,8 @@ export function parseRunSecurityMasterArgs(argv: readonly string[]): ParsedRunSe
|
|||
let asOfDate: string | undefined;
|
||||
let outDir: string | undefined;
|
||||
let persist = false;
|
||||
let skipPriceCrossCheck = false;
|
||||
let sampleDateCount = DEFAULT_SAMPLE_DATE_COUNT;
|
||||
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
const arg = argv[i];
|
||||
|
|
@ -163,6 +362,27 @@ export function parseRunSecurityMasterArgs(argv: readonly string[]): ParsedRunSe
|
|||
persist = true;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--skip-price-cross-check') {
|
||||
skipPriceCrossCheck = true;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--sample-dates') {
|
||||
const value = argv[i + 1];
|
||||
if (!value || value.trim().length === 0 || value.startsWith('--')) {
|
||||
throw usageError('Missing value for --sample-dates');
|
||||
}
|
||||
sampleDateCount = parseSampleDateCountArg(value);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg?.startsWith('--sample-dates=')) {
|
||||
const value = arg.slice('--sample-dates='.length);
|
||||
if (value.trim().length === 0) {
|
||||
throw usageError('Missing value for --sample-dates');
|
||||
}
|
||||
sampleDateCount = parseSampleDateCountArg(value);
|
||||
continue;
|
||||
}
|
||||
if (arg === '--as-of') {
|
||||
const value = argv[i + 1];
|
||||
if (!value || value.trim().length === 0 || value.startsWith('--')) {
|
||||
|
|
@ -221,6 +441,8 @@ export function parseRunSecurityMasterArgs(argv: readonly string[]): ParsedRunSe
|
|||
asOfDate,
|
||||
outDir,
|
||||
persist,
|
||||
skipPriceCrossCheck,
|
||||
sampleDateCount,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -262,9 +484,9 @@ export function formatRunSecurityMasterSummary(
|
|||
params: Pick<
|
||||
RunSecurityMasterOutput,
|
||||
'asOfDate' | 'outDir' | 'persist' | 'filesWritten' | 'composed'
|
||||
>
|
||||
> & { readonly pass4?: RunSecurityMasterPass4Summary }
|
||||
): string {
|
||||
const { asOfDate, outDir, persist, composed } = params;
|
||||
const { asOfDate, outDir, persist, composed, pass4 } = params;
|
||||
const resolutionParts = composed.report.resolutionBySource.map(row => {
|
||||
const pct =
|
||||
row.eligibleResolvedPct === null
|
||||
|
|
@ -280,11 +502,25 @@ export function formatRunSecurityMasterSummary(
|
|||
SECURITY_MASTER_OUTPUT_FILES.runStatsJson,
|
||||
];
|
||||
|
||||
const pass4StatusLabel =
|
||||
composed.stats.pass4.status === 'skipped' && pass4?.skippedReason
|
||||
? `skipped (${pass4.skippedReason})`
|
||||
: composed.stats.pass4.status;
|
||||
const pass4DateCount = pass4?.sampleDates.length ?? 0;
|
||||
const byVerdict = composed.pass4?.stats.byVerdict ?? pass4?.byVerdict ?? null;
|
||||
const pass4Line =
|
||||
` Pass 4 price cross-check: ${pass4StatusLabel} ` +
|
||||
`(dates=${pass4DateCount}, ` +
|
||||
`confirmed=${byVerdict?.confirmed ?? 0}, ` +
|
||||
`ratio_mismatch=${byVerdict?.ratio_mismatch ?? 0}, ` +
|
||||
`low_correlation=${byVerdict?.low_correlation ?? 0}, ` +
|
||||
`insufficient_data=${byVerdict?.insufficient_data ?? 0})`;
|
||||
|
||||
const lines = [
|
||||
`Security master run complete (as-of ${asOfDate})`,
|
||||
` Instruments: ${composed.stageA.instruments.length} | Listings: ${composed.stageB.listings.length} | Conflicts: ${composed.report.conflicts.length}`,
|
||||
` Resolution (eligible): ${resolutionParts.length > 0 ? resolutionParts.join(', ') : 'none'}`,
|
||||
` Pass 4 price cross-check: ${composed.stats.pass4.status} (sample closes not yet wired)`,
|
||||
pass4Line,
|
||||
` Files written (${outDir}): ${fileNames.join(', ')}`,
|
||||
` Persisted: ${persist ? 'yes' : 'no (dry-run)'}`,
|
||||
];
|
||||
|
|
@ -313,6 +549,37 @@ export async function runSecurityMaster(
|
|||
throw wrapStepError('validate-options', new Error('outDir must be a non-empty string'));
|
||||
}
|
||||
|
||||
let pass4Enabled = true;
|
||||
let sampleDateCount = DEFAULT_SAMPLE_DATE_COUNT;
|
||||
if (options.pass4 !== undefined) {
|
||||
if (options.pass4 === null || typeof options.pass4 !== 'object') {
|
||||
throw wrapStepError('validate-options', new Error('pass4 options must be an object'));
|
||||
}
|
||||
if (options.pass4.enabled !== undefined) {
|
||||
if (typeof options.pass4.enabled !== 'boolean') {
|
||||
throw wrapStepError('validate-options', new Error('pass4.enabled must be a boolean'));
|
||||
}
|
||||
pass4Enabled = options.pass4.enabled;
|
||||
}
|
||||
if (options.pass4.sampleDateCount !== undefined) {
|
||||
const count = options.pass4.sampleDateCount;
|
||||
if (
|
||||
typeof count !== 'number' ||
|
||||
!Number.isSafeInteger(count) ||
|
||||
count < 1 ||
|
||||
count > MAX_SAMPLE_DATES
|
||||
) {
|
||||
throw wrapStepError(
|
||||
'validate-options',
|
||||
new Error(
|
||||
`Invalid pass4.sampleDateCount "${String(count)}": expected a positive safe integer <= ${MAX_SAMPLE_DATES}`
|
||||
)
|
||||
);
|
||||
}
|
||||
sampleDateCount = count;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1: Environment safety check before opening PostgreSQL or reading Mongo when --persist is requested.
|
||||
if (persist) {
|
||||
try {
|
||||
|
|
@ -405,10 +672,11 @@ export async function runSecurityMaster(
|
|||
throw wrapStepError('compute-bar-spans', error);
|
||||
}
|
||||
|
||||
// Step 5: Compose Stage A -> Stage B -> Pass 6 -> Report + PersistInput (Pass 4 omitted).
|
||||
// Step 5: Compose Stage A -> Stage B -> Pass 6 -> candidate Pass 4 pairs.
|
||||
const composeFn = deps.composeFn ?? composeSecurityMasterRun;
|
||||
let composed: ComposeSecurityMasterRunResult;
|
||||
try {
|
||||
composed = composeSecurityMasterRun(
|
||||
composed = composeFn(
|
||||
{
|
||||
sources,
|
||||
barSpans,
|
||||
|
|
@ -422,10 +690,100 @@ export async function runSecurityMaster(
|
|||
throw wrapStepError('compose', error);
|
||||
}
|
||||
|
||||
// Step 5b: Read targeted sample closes + USD/CAD FX and re-compose with Pass 4 when applicable.
|
||||
let pass4Wired = false;
|
||||
let sampleCloses: ReadSampleClosesResult | null = null;
|
||||
let pass4SampleDates: string[] = [];
|
||||
let pass4EodIds: string[] = [];
|
||||
let pass4QmIds: string[] = [];
|
||||
let pass4SkippedReason: Pass4SkippedReason | null = null;
|
||||
const candidatePairsCount = composed.pass4CandidatePairs.length;
|
||||
|
||||
if (!pass4Enabled) {
|
||||
pass4SkippedReason = 'disabled';
|
||||
} else {
|
||||
const calendar = buildSampleDateCalendar(barSpans, options.asOfDate);
|
||||
pass4SampleDates =
|
||||
calendar.length > 0 ? selectSampleDates(calendar, { count: sampleDateCount }) : [];
|
||||
|
||||
if (pass4SampleDates.length === 0) {
|
||||
pass4SkippedReason = 'no_sample_dates';
|
||||
} else {
|
||||
const eodRawIds: string[] = [];
|
||||
const qmRawIds: string[] = [];
|
||||
for (let i = 0; i < composed.pass4CandidatePairs.length; i++) {
|
||||
const pair = composed.pass4CandidatePairs[i];
|
||||
if (!pair) {
|
||||
continue;
|
||||
}
|
||||
if (pair.left.source === 'eod') {
|
||||
eodRawIds.push(pair.left.sourceId);
|
||||
} else if (pair.left.source === 'qm') {
|
||||
qmRawIds.push(pair.left.sourceId);
|
||||
}
|
||||
if (pair.right.source === 'eod') {
|
||||
eodRawIds.push(pair.right.sourceId);
|
||||
} else if (pair.right.source === 'qm') {
|
||||
qmRawIds.push(pair.right.sourceId);
|
||||
}
|
||||
}
|
||||
pass4EodIds = collectSortedUniqueIds(eodRawIds);
|
||||
pass4QmIds = collectSortedUniqueIds(qmRawIds);
|
||||
|
||||
if (candidatePairsCount === 0 || (pass4EodIds.length === 0 && pass4QmIds.length === 0)) {
|
||||
pass4SkippedReason = 'no_candidate_pairs';
|
||||
} else {
|
||||
const readSampleClosesFn = deps.readSampleClosesFn ?? readSampleCloses;
|
||||
try {
|
||||
sampleCloses = await readSampleClosesFn(sourceReader, {
|
||||
sampleDates: pass4SampleDates,
|
||||
sourceIdsBySource: {
|
||||
eod: pass4EodIds,
|
||||
qm: pass4QmIds,
|
||||
},
|
||||
includeFx: true,
|
||||
...(options.batchSize !== undefined ? { batchSize: options.batchSize } : {}),
|
||||
});
|
||||
pass4Wired = true;
|
||||
} catch (error) {
|
||||
throw wrapStepError('read-sample-closes', error);
|
||||
}
|
||||
|
||||
try {
|
||||
composed = composeFn(
|
||||
{
|
||||
sources,
|
||||
barSpans,
|
||||
exchanges,
|
||||
sampleCloses: sampleCloses.closes,
|
||||
fxRates: sampleCloses.fxRates,
|
||||
},
|
||||
{
|
||||
asOfDate: options.asOfDate,
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
throw wrapStepError('compose', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const pass4Summary: RunSecurityMasterPass4Summary = {
|
||||
sampleDates: pass4SampleDates,
|
||||
candidatePairs: candidatePairsCount,
|
||||
eodIdsRequested: pass4EodIds.length,
|
||||
qmIdsRequested: pass4QmIds.length,
|
||||
stats: sampleCloses?.stats ?? null,
|
||||
byVerdict: composed.pass4?.stats.byVerdict ?? null,
|
||||
skippedReason: pass4SkippedReason,
|
||||
};
|
||||
|
||||
// Step 6: Write deterministic artifacts into outDir.
|
||||
const statsArtifact = {
|
||||
asOfDate: options.asOfDate,
|
||||
pass4Wired: false,
|
||||
pass4Wired,
|
||||
pass4: pass4Summary,
|
||||
exchanges: {
|
||||
countsByCollection: exchangeCountsByCollection,
|
||||
mapped: exchanges.mapped.length,
|
||||
|
|
@ -516,6 +874,7 @@ export async function runSecurityMaster(
|
|||
persist,
|
||||
filesWritten,
|
||||
composed,
|
||||
pass4: pass4Summary,
|
||||
});
|
||||
|
||||
output = {
|
||||
|
|
@ -527,6 +886,8 @@ export async function runSecurityMaster(
|
|||
exchangeCountsByCollection,
|
||||
sources,
|
||||
barSpans,
|
||||
sampleCloses,
|
||||
pass4: pass4Summary,
|
||||
composed,
|
||||
persistResult,
|
||||
runStatsJson,
|
||||
|
|
@ -664,6 +1025,10 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
|
|||
asOfDate: parsed.asOfDate,
|
||||
outDir: parsed.outDir,
|
||||
persist: parsed.persist,
|
||||
pass4: {
|
||||
enabled: !parsed.skipPriceCrossCheck,
|
||||
sampleDateCount: parsed.sampleDateCount,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue