47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
/** Local, deterministic workload; no native engine, database, network or trading credentials. */
|
|
import { defaultRiskLimits, type Account } from '../apps/stock/orchestrator/src/execution/model';
|
|
import { BacktestExecutionRepository } from '../apps/stock/orchestrator/src/execution/BacktestExecutionRepository';
|
|
|
|
const account: Account = {
|
|
initialCapital: 10000,
|
|
cash: 10000,
|
|
realizedPnl: 0,
|
|
dailyPnl: 0,
|
|
day: '2024-01-01',
|
|
commission: 0.001,
|
|
slippage: 0,
|
|
limits: { ...defaultRiskLimits },
|
|
maxQuoteAgeMs: 60000,
|
|
positions: {},
|
|
quotes: {},
|
|
strategyPositions: {},
|
|
};
|
|
|
|
for (const history of [0, 1000, 10000]) {
|
|
const repository = new BacktestExecutionRepository();
|
|
await repository.initialize('benchmark', account);
|
|
await repository.transact('benchmark', async tx => {
|
|
for (let i = 0; i < history; i++) {
|
|
await tx.appendJournal({
|
|
kind: 'market',
|
|
market: {
|
|
type: 'trade',
|
|
eventId: String(i),
|
|
data: { symbol: 'A.US', price: 100, size: 1, side: 'buy', timestamp: i },
|
|
},
|
|
recipients: [],
|
|
account,
|
|
});
|
|
}
|
|
});
|
|
const start = performance.now();
|
|
for (let i = 0; i < 200; i++) {
|
|
await repository.transact('benchmark', async tx => ({
|
|
cash: tx.account.cash,
|
|
next: await tx.nextJournal(history),
|
|
}));
|
|
}
|
|
process.stdout.write(
|
|
`${history} journal events: ${((performance.now() - start) / 200).toFixed(3)} ms/transaction\n`
|
|
);
|
|
}
|