63 lines
2 KiB
TypeScript
63 lines
2 KiB
TypeScript
import { smaStrategySelectionSchema } from '../../apps/stock/orchestrator/src/contracts/builtin-strategy';
|
|
import { createDatasetV2 } from '../../apps/stock/orchestrator/src/data/historical-dataset-v2';
|
|
import { nativeReplayFixture } from './native-replay';
|
|
|
|
/** Reviewed oracle: buy ten at next open 5, sell ten at next open 2; fees 0.70. */
|
|
export function canonicalSmaFixture(
|
|
owners = ['A'],
|
|
options: {
|
|
tradeStartStep?: number;
|
|
volume?: number;
|
|
opens?: number[];
|
|
closes?: number[];
|
|
availabilitySteps?: number[];
|
|
} = {}
|
|
) {
|
|
const fixture = nativeReplayFixture(7, 1, owners);
|
|
const { calendars, series, executionSeries, bounds, universe, corporateActions } =
|
|
fixture.dataset.manifest;
|
|
const closes = options.closes ?? [3, 2, 1, 4, 5, 1, 1];
|
|
const opens = options.opens ?? [3, 3, 2, 1, 5, 5, 2];
|
|
const dataset = createDatasetV2({
|
|
metadata: {
|
|
calendars,
|
|
series,
|
|
executionSeries,
|
|
bounds: {
|
|
...bounds,
|
|
tradeStart: fixture.start + (options.tradeStartStep ?? 1) * fixture.minute,
|
|
},
|
|
universe,
|
|
corporateActions,
|
|
},
|
|
bars: fixture.dataset.bars.map((bar, index) => {
|
|
const open = opens[index]!,
|
|
close = closes[index]!;
|
|
return {
|
|
seriesId: bar.seriesId,
|
|
timestamp: bar.intervalStart,
|
|
availableAt:
|
|
fixture.start + (options.availabilitySteps?.[index] ?? index + 1) * fixture.minute,
|
|
sourceSequence: bar.sourceSequence,
|
|
open,
|
|
close,
|
|
high: Math.max(open, close),
|
|
low: Math.min(open, close),
|
|
volume: options.volume ?? 1000,
|
|
};
|
|
}),
|
|
});
|
|
const selections = owners.map(ownerId =>
|
|
smaStrategySelectionSchema.parse({
|
|
ownerId,
|
|
strategyId: 'sma',
|
|
strategyVersion: 'sma-crossover-long-only/v1',
|
|
seed: 42,
|
|
instrumentId: 'X0.US',
|
|
seriesId: 'X0.US:1m',
|
|
ownerBudget: '40',
|
|
parameters: { fastPeriod: 2, slowPeriod: 3 },
|
|
})
|
|
);
|
|
return { ...fixture, dataset, selections };
|
|
}
|