feat(research): cut over canonical runtime and enforce agent budgets
This commit is contained in:
parent
ab08db82fd
commit
bbf0dd4453
103 changed files with 6138 additions and 3112 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { createHash } from 'node:crypto';
|
||||
import { BacktestEngine } from '@stock-bot/engine';
|
||||
import type { StrategyProgram } from '../contracts/canonical-strategy';
|
||||
import type { StrategyReplayResult } from '../contracts/strategy-replay';
|
||||
import {
|
||||
|
|
@ -10,7 +9,6 @@ import { freeze } from '../strategies/strategy-decision';
|
|||
import { verifyCanonicalWorkerBuild } from './canonical-build';
|
||||
import { buildCanonicalBacktestReport } from './canonical-result';
|
||||
import { executeReplayTrace, prepareReplayLoad } from './native-replay';
|
||||
import { resolveNativeStrategies } from './native-strategies';
|
||||
import {
|
||||
nativeWorkerRequestSchema,
|
||||
type NativeWorkerMessage,
|
||||
|
|
@ -138,34 +136,11 @@ process.once('message', async (input: unknown) => {
|
|||
if (request.type === 'runReplayTrace') {
|
||||
await send({ type: 'progress', progress: 0, message: 'Canonical replay trace started' });
|
||||
// One load and a local pull loop; no per-observation IPC. The supervisor
|
||||
// can still SIGKILL native work, exactly as for the legacy one-shot path.
|
||||
// can still SIGKILL native work, without changing financial execution semantics.
|
||||
const { result } = executeReplayTrace(request);
|
||||
await send({ type: 'result', result: JSON.stringify(result) });
|
||||
return;
|
||||
}
|
||||
const { config, data } = request;
|
||||
const engine = new BacktestEngine({
|
||||
name: config.name ?? 'Backtest',
|
||||
strategy: config.strategy,
|
||||
symbols: config.symbols,
|
||||
startDate: config.startDate,
|
||||
endDate: config.endDate,
|
||||
initialCapital: config.initialCapital,
|
||||
commission: config.commission ?? 0.001,
|
||||
slippage: config.slippage ?? 0.0001,
|
||||
dataFrequency: config.dataFrequency,
|
||||
});
|
||||
if (config.riskLimits) {
|
||||
engine.updateRiskLimits(config.riskLimits);
|
||||
}
|
||||
for (const { strategy, name, id, parameters } of resolveNativeStrategies(config)) {
|
||||
engine.addNativeStrategy(strategy, name, id, parameters);
|
||||
}
|
||||
data.sort((a, b) => a.timestamp - b.timestamp);
|
||||
engine.loadMarketData(data);
|
||||
await send({ type: 'progress', progress: 0, message: 'Native execution started' });
|
||||
// This synchronous call is deliberately confined to the child process.
|
||||
await send({ type: 'result', result: engine.run() });
|
||||
} catch (error) {
|
||||
await send({ type: 'error', message: error instanceof Error ? error.message : String(error) });
|
||||
process.exitCode = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue