T-212: M2.3t — Add --qm-financials-old merge and Option B --from-mongo streaming for M2 collections in curate-etl
This commit is contained in:
parent
60ab228207
commit
f082aac436
12 changed files with 518 additions and 131 deletions
|
|
@ -1650,6 +1650,69 @@ describe('macroAsOf and crossSection point-in-time edge cases via real DuckDB (Q
|
|||
}
|
||||
});
|
||||
|
||||
test('crossSection caps universe membership at end-of-date when asOf is later, while returning revised features', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'stockbot-duckdb-xsec-late-bar-'));
|
||||
tempDirs.push(root);
|
||||
const curatedRoot = join(root, 'curated');
|
||||
const duckTempDir = join(root, 'duckdb-tmp');
|
||||
await mkdir(join(curatedRoot, 'bars_1d', 'year=2025'), { recursive: true });
|
||||
await mkdir(join(curatedRoot, 'features', 'rev_feat', 'v1', 'year=2025'), { recursive: true });
|
||||
await mkdir(duckTempDir, { recursive: true });
|
||||
|
||||
const vaultCutoffTs = Date.UTC(2025, 5, 20, 0, 0, 0, 0); // 2025-06-20T00:00:00Z
|
||||
const writer = await createNodeDuckDbExecutor();
|
||||
try {
|
||||
// Listing 401: June 7 bar known on June 7 -> member of June 7 universe.
|
||||
// Listing 402: only qualifying June 7 bar was first known on June 10 -> must NOT enter June 7 universe even when asOf is June 10.
|
||||
await writer.run(`
|
||||
COPY (
|
||||
SELECT * FROM (VALUES
|
||||
(401::INTEGER, DATE '2025-06-07', TIMESTAMPTZ '2025-06-07 20:00:00+00', 10.0::DOUBLE, 10.5::DOUBLE, 9.5::DOUBLE, 10.2::DOUBLE, 1000.0::DOUBLE, NULL::DOUBLE, 'USD'::VARCHAR, TIMESTAMPTZ '2025-06-07 20:00:00+00'),
|
||||
(402::INTEGER, DATE '2025-06-07', TIMESTAMPTZ '2025-06-07 20:00:00+00', 20.0::DOUBLE, 20.5::DOUBLE, 19.5::DOUBLE, 20.2::DOUBLE, 1000.0::DOUBLE, NULL::DOUBLE, 'USD'::VARCHAR, TIMESTAMPTZ '2025-06-10 12:00:00+00')
|
||||
) AS t(listing_id, session_date, ts, open, high, low, close, volume, vwap, currency, known_at)
|
||||
) TO '${join(curatedRoot, 'bars_1d', 'year=2025', 'part.parquet')}' (FORMAT PARQUET)
|
||||
`);
|
||||
|
||||
// rev_feat@v1: listing 401 has original (1.0 on June 7) and revision (2.5 on June 10);
|
||||
// listing 402 also has a feature row on June 7/10, but must stay excluded from the universe.
|
||||
await writer.run(`
|
||||
COPY (
|
||||
SELECT * FROM (VALUES
|
||||
(401::INTEGER, TIMESTAMPTZ '2025-06-07 20:00:00+00', TIMESTAMPTZ '2025-06-07 20:00:00+00', 1.0::DOUBLE),
|
||||
(401::INTEGER, TIMESTAMPTZ '2025-06-07 20:00:00+00', TIMESTAMPTZ '2025-06-10 12:00:00+00', 2.5::DOUBLE),
|
||||
(402::INTEGER, TIMESTAMPTZ '2025-06-07 20:00:00+00', TIMESTAMPTZ '2025-06-10 12:00:00+00', 9.9::DOUBLE)
|
||||
) AS t(listing_id, ts, known_at, value)
|
||||
) TO '${join(curatedRoot, 'features', 'rev_feat', 'v1', 'year=2025', 'part.parquet')}' (FORMAT PARQUET)
|
||||
`);
|
||||
} finally {
|
||||
await writer.close();
|
||||
}
|
||||
|
||||
const opened = await openDuckDbMarketDataStore({
|
||||
curatedRoot,
|
||||
vaultCutoffTs,
|
||||
env: budgetEnv(duckTempDir),
|
||||
});
|
||||
try {
|
||||
const sameDay = await opened.store.crossSection({
|
||||
features: ['rev_feat@v1'],
|
||||
date: '2025-06-07',
|
||||
universe: 'US_EQ',
|
||||
});
|
||||
expect(sameDay.rows).toEqual([{ listing_id: 401, 'rev_feat@v1': 1.0 }]);
|
||||
|
||||
const laterAsOf = await opened.store.crossSection({
|
||||
features: ['rev_feat@v1'],
|
||||
date: '2025-06-07',
|
||||
universe: 'US_EQ',
|
||||
asOf: '2025-06-10',
|
||||
});
|
||||
expect(laterAsOf.rows).toEqual([{ listing_id: 401, 'rev_feat@v1': 2.5 }]);
|
||||
} finally {
|
||||
await opened.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('macroAsOf treats known_at == asOf as visible and honours the period_date from bound and country filter', async () => {
|
||||
// Arrange
|
||||
const root = await mkdtemp(join(tmpdir(), 'stockbot-duckdb-macro-pit-'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue