feat(research): prepare stored data by declared sessions (RP03)
This commit is contained in:
parent
302ba60e53
commit
d2b78eacdf
10 changed files with 805 additions and 72 deletions
|
|
@ -2351,6 +2351,127 @@ test('browser_catalog_version_parameters_clone_and_saved_draft', async () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('declared_session_source_browser_captures_two_windows_and_retains_without_requery', async () => {
|
||||
const f = await fixture();
|
||||
try {
|
||||
await f.login();
|
||||
const { id, dataset } = await createCanonicalInBrowser(f, 'Declared session preparation');
|
||||
const { calendars, series, executionSeries, bounds, universe, corporateActions } =
|
||||
dataset.manifest;
|
||||
const start = bounds.warmupStart;
|
||||
const end = dataset.bars.at(-1)!.intervalEnd;
|
||||
const day = 86_400_000;
|
||||
const metadata = {
|
||||
calendars: calendars.map(calendar => ({
|
||||
...calendar,
|
||||
endDate: new Date(end + 2 * day).toISOString().slice(0, 10),
|
||||
sessions: [
|
||||
{ date: new Date(start).toISOString().slice(0, 10), open: start, close: end },
|
||||
{
|
||||
date: new Date(start + day).toISOString().slice(0, 10),
|
||||
open: start + day,
|
||||
close: end + day,
|
||||
},
|
||||
],
|
||||
})),
|
||||
series: series.map(value => ({
|
||||
...value,
|
||||
source: { provider: 'eod', revision: 'declared-two-session-browser-fixture' },
|
||||
availability: 'interval-end-assumption',
|
||||
})),
|
||||
executionSeries,
|
||||
bounds: { ...bounds, tradeEnd: end + day },
|
||||
universe,
|
||||
corporateActions: corporateActions.map(value => ({ ...value, end: end + day })),
|
||||
};
|
||||
const firstRows = dataset.bars.map(bar => ({
|
||||
eodSearchCode: 'X0.US',
|
||||
symbol: 'X0',
|
||||
exchange: 'US',
|
||||
timestamp: bar.intervalStart / 1000,
|
||||
open: bar.open,
|
||||
high: bar.high,
|
||||
low: bar.low,
|
||||
close: bar.close,
|
||||
volume: bar.volume,
|
||||
}));
|
||||
f.setStoredEodBars('eodIntraday1M', [
|
||||
...firstRows,
|
||||
{ ...firstRows[0]!, timestamp: end / 1000, volume: -1 },
|
||||
...firstRows.map(row => ({ ...row, timestamp: row.timestamp + day / 1000 })),
|
||||
]);
|
||||
const before = await f.request(`/api/v2/backtests/${id}`);
|
||||
await f.page.getByRole('button', { name: 'Settings', exact: true }).click();
|
||||
await f.page.getByText('Prepare dataset from source export', { exact: true }).click();
|
||||
await f.page.getByLabel('Dataset input', { exact: true }).selectOption('stored-eod-sessions');
|
||||
await f.page.getByLabel('Source metadata JSON', { exact: true }).setInputFiles({
|
||||
name: 'two-declared-sessions.json',
|
||||
mimeType: 'application/json',
|
||||
buffer: Buffer.from(JSON.stringify(metadata)),
|
||||
});
|
||||
const windows = f.page.getByRole('list', { name: 'Declared UTC query windows', exact: true });
|
||||
await windows.waitFor({ state: 'visible' });
|
||||
expect(await windows.getByRole('listitem').count()).toBe(2);
|
||||
for (const offset of [0, day]) {
|
||||
expect(await windows.textContent()).toContain(new Date(start + offset).toISOString());
|
||||
expect(await windows.textContent()).toContain(new Date(end + offset).toISOString());
|
||||
}
|
||||
const previewing = f.page.waitForResponse(response =>
|
||||
response.url().endsWith('/api/v2/datasets/canonical/stored-source')
|
||||
);
|
||||
await f.page.getByRole('button', { name: 'Preview dataset', exact: true }).click();
|
||||
const response = await previewing;
|
||||
expect(response.status()).toBe(200);
|
||||
expect(response.request().postDataJSON()).toEqual({ metadata, selection: 'declared-sessions' });
|
||||
const captured = (await response.json()) as CanonicalStoredSourcePreparation;
|
||||
expect(captured.selection).toBe('declared-sessions');
|
||||
expect(captured.input.bars).toHaveLength(2 * firstRows.length);
|
||||
expect(f.storedSourceReads).toEqual(
|
||||
[start, start + day].map(windowStart => ({
|
||||
collection: 'eodIntraday1M',
|
||||
filter: {
|
||||
eodSearchCode: 'X0.US',
|
||||
timestamp: { $gte: windowStart / 1000, $lt: (windowStart + end - start) / 1000 },
|
||||
},
|
||||
}))
|
||||
);
|
||||
await visible(f.page, `Dataset hash: ${captured.preparation.hash}`);
|
||||
f.setStoredEodBars('eodIntraday1M', []);
|
||||
const retaining = f.page.waitForResponse(result =>
|
||||
result.url().endsWith('/api/v2/datasets/canonical/retain')
|
||||
);
|
||||
await f.page.getByRole('button', { name: 'Retain dataset', exact: true }).click();
|
||||
const retained = await retaining;
|
||||
expect(retained.status()).toBe(200);
|
||||
expect(retained.request().postDataJSON()).toEqual({
|
||||
input: captured.input,
|
||||
expectedHash: captured.preparation.hash,
|
||||
});
|
||||
await until(
|
||||
async () =>
|
||||
(await f.page.getByLabel('Canonical dataset', { exact: true }).inputValue()) ===
|
||||
captured.preparation.hash,
|
||||
'declared-session snapshot selection'
|
||||
);
|
||||
expect(f.storedSourceReads).toHaveLength(2);
|
||||
expect(
|
||||
(
|
||||
await f.pool.query('SELECT payload FROM backtest_datasets WHERE hash=$1', [
|
||||
captured.preparation.hash,
|
||||
])
|
||||
).rows[0].payload
|
||||
).toEqual(createDatasetV2(captured.input));
|
||||
expect(await f.request(`/api/v2/backtests/${id}`)).toEqual(before);
|
||||
expect((await f.pool.query('SELECT count(*)::int AS n FROM runs')).rows[0].n).toBe(0);
|
||||
expect((await f.pool.query('SELECT count(*)::int AS n FROM backtest_dispatch')).rows[0].n).toBe(
|
||||
0
|
||||
);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('stored_source_inspection_browser_keeps_utc_scope_and_research_state_unchanged', async () => {
|
||||
const f = await fixture();
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue