Separate backtest execution settings from strategy parameters

This commit is contained in:
Boki 2026-10-22 00:19:19 -04:00
parent 420c47704e
commit e4925ecdfe
9 changed files with 283 additions and 48 deletions

View file

@ -1,6 +1,6 @@
import { normalizeBacktestStrategyConfig } from '@stock-bot/stock-config/backtest';
import {
nativeParameters,
strategyParameters,
typescriptMeanReversionParameters,
typescriptSmaParameters,
} from '../contracts/strategies';
@ -18,12 +18,19 @@ export function backtestStrategies(config: BacktestConfig, backend: 'native' | '
.map((entry, index) => {
const kind = builtinStrategy(entry.name);
const merged = { ...config.config, ...entry.config };
// Custom TypeScript factories own their parameter contract; do not strip their extension fields.
const parameters = kind ? strategyParameters(merged, backend) : structuredClone(merged);
// Built-ins cross the shared execution/parameter boundary once, after merging defaults.
// Custom TypeScript factories retain their historical, factory-owned extension contract.
const input = kind
? normalizeBacktestStrategyConfig(merged)
: { parameters: structuredClone(merged) };
const { parameters } = input;
if (backend === 'native') {
if (!kind) {
throw new Error(`Unknown native strategy: ${entry.name}`);
}
if (input.useTypeScriptImplementation) {
throw new Error('The native engine does not execute TypeScript strategy callbacks');
}
const parsed = nativeParameters(kind, parameters);
if (
kind === 'pairs_trading' &&