Refactor execution boundaries and add durable strategy recovery
This commit is contained in:
parent
d6b09eb635
commit
694c48bbdb
36 changed files with 3077 additions and 491 deletions
47
scripts/benchmark-execution.ts
Normal file
47
scripts/benchmark-execution.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/** 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`
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue