work on strategy-engine
This commit is contained in:
parent
fc4cf71a70
commit
eee6135867
7 changed files with 572 additions and 33 deletions
|
|
@ -8,8 +8,8 @@ import { program } from 'commander';
|
|||
import { createLogger } from '@stock-bot/logger';
|
||||
import { createEventBus } from '@stock-bot/event-bus';
|
||||
import { BacktestContext } from '../framework/execution-mode';
|
||||
import LiveMode from '../backtesting/modes/live-mode';
|
||||
import EventMode from '../backtesting/modes/event-mode';
|
||||
import { LiveMode } from '../backtesting/modes/live-mode';
|
||||
import { EventMode } from '../backtesting/modes/event-mode';
|
||||
import VectorizedMode from '../backtesting/modes/vectorized-mode';
|
||||
import HybridMode from '../backtesting/modes/hybrid-mode';
|
||||
|
||||
|
|
@ -17,6 +17,7 @@ const logger = createLogger('strategy-cli');
|
|||
|
||||
interface CLIBacktestConfig {
|
||||
strategy: string;
|
||||
strategies: string;
|
||||
symbol: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
|
|
@ -102,7 +103,6 @@ async function runBacktest(options: CLIBacktestConfig): Promise<void> {
|
|||
|
||||
} catch (error) {
|
||||
logger.error('Backtest failed', { error });
|
||||
console.error('Backtest failed:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ async function loadConfig(configPath: string): Promise<any> {
|
|||
}
|
||||
} catch (error) {
|
||||
logger.error('Failed to load config', { configPath, error });
|
||||
throw new Error(`Failed to load config from ${configPath}: ${error.message}`);
|
||||
throw new Error(`Failed to load config from ${configPath}: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,10 +167,9 @@ async function saveResults(result: any, outputPath: string): Promise<void> {
|
|||
await Bun.write(outputPath + '.json', JSON.stringify(result, null, 2));
|
||||
}
|
||||
|
||||
console.log(`\nResults saved to: ${outputPath}`);
|
||||
logger.info(`\nResults saved to: ${outputPath}`);
|
||||
} catch (error) {
|
||||
logger.error('Failed to save results', { outputPath, error });
|
||||
console.error(`Failed to save results: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,18 +230,8 @@ program
|
|||
.option('--config <path>', 'Configuration file path')
|
||||
.option('-o, --output <path>', 'Output file path')
|
||||
.option('-v, --verbose', 'Verbose output')
|
||||
.action(async (options) => {
|
||||
await runBacktest({
|
||||
strategy: options.strategy,
|
||||
symbol: options.symbol,
|
||||
startDate: options.startDate,
|
||||
endDate: options.endDate,
|
||||
mode: options.mode,
|
||||
initialCapital: parseFloat(options.initialCapital),
|
||||
config: options.config,
|
||||
output: options.output,
|
||||
verbose: options.verbose
|
||||
});
|
||||
.action(async (options: CLIBacktestConfig) => {
|
||||
await runBacktest(options);
|
||||
});
|
||||
|
||||
program
|
||||
|
|
@ -254,7 +243,7 @@ program
|
|||
.command('validate')
|
||||
.description('Validate a strategy')
|
||||
.requiredOption('-s, --strategy <strategy>', 'Strategy to validate')
|
||||
.action(async (options) => {
|
||||
.action(async (options: CLIBacktestConfig) => {
|
||||
await validateStrategy(options.strategy);
|
||||
});
|
||||
|
||||
|
|
@ -268,7 +257,7 @@ program
|
|||
.option('-m, --mode <mode>', 'Execution mode', 'vectorized')
|
||||
.option('-c, --initial-capital <amount>', 'Initial capital', '10000')
|
||||
.option('-o, --output <path>', 'Output directory')
|
||||
.action(async (options) => {
|
||||
.action(async (options: CLIBacktestConfig) => {
|
||||
const strategies = options.strategies.split(',').map((s: string) => s.trim());
|
||||
console.log(`Comparing strategies: ${strategies.join(', ')}`);
|
||||
|
||||
|
|
@ -278,16 +267,12 @@ program
|
|||
console.log(`\nRunning ${strategy}...`);
|
||||
try {
|
||||
await runBacktest({
|
||||
...options,
|
||||
strategy,
|
||||
symbol: options.symbol,
|
||||
startDate: options.startDate,
|
||||
endDate: options.endDate,
|
||||
mode: options.mode,
|
||||
initialCapital: parseFloat(options.initialCapital),
|
||||
output: options.output ? `${options.output}/${strategy}.json` : undefined
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Failed to run ${strategy}:`, error.message);
|
||||
console.error(`Failed to run ${strategy}:`, (error as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue