Optimizer configuration object
Schema configuration for optimizer registration. Defines how to collect data, generate strategies, and create executable code.
Optionalcallbacks?: Partial<IOptimizerCallbacks>Optional lifecycle callbacks for monitoring.
Function to generate strategy prompt from conversation history. Called after all sources are processed for each training range.
Optionalnote?: stringOptional description of this optimizer configuration.
Unique identifier for this optimizer. Used to retrieve optimizer instance from registry.
Testing time range for strategy validation. Used in generated Walker to evaluate strategy performance.
Array of training time ranges. Each range generates a separate strategy variant for comparison.
Array of data sources for strategy generation. Each source contributes to the LLM conversation context.
Optionaltemplate?: Partial<IOptimizerTemplate>Optional custom template overrides. If not provided, uses defaults from OptimizerTemplateService.
// Basic optimizer with single data source
addOptimizer({
optimizerName: "llm-strategy-generator",
rangeTrain: [
{
note: "Bull market period",
startDate: new Date("2024-01-01"),
endDate: new Date("2024-01-31"),
},
{
note: "Bear market period",
startDate: new Date("2024-02-01"),
endDate: new Date("2024-02-28"),
},
],
rangeTest: {
note: "Validation period",
startDate: new Date("2024-03-01"),
endDate: new Date("2024-03-31"),
},
source: [
{
name: "historical-backtests",
fetch: async ({ symbol, startDate, endDate, limit, offset }) => {
// Fetch historical backtest results from database
return await db.backtests.find({
symbol,
date: { $gte: startDate, $lte: endDate },
})
.skip(offset)
.limit(limit);
},
user: async (symbol, data, name) => {
return `Analyze these ${data.length} backtest results for ${symbol}:\n${JSON.stringify(data)}`;
},
assistant: async (symbol, data, name) => {
return "Historical data analyzed successfully";
},
},
],
getPrompt: async (symbol, messages) => {
// Generate strategy prompt from conversation
return `"Analyze ${symbol} using RSI and MACD. Enter LONG when RSI < 30 and MACD crosses above signal."`;
},
callbacks: {
onData: (symbol, strategyData) => {
console.log(`Generated ${strategyData.length} strategies for ${symbol}`);
},
onCode: (symbol, code) => {
console.log(`Generated ${code.length} characters of code for ${symbol}`);
},
onDump: (symbol, filepath) => {
console.log(`Saved strategy to ${filepath}`);
},
onSourceData: (symbol, sourceName, data, startDate, endDate) => {
console.log(`Fetched ${data.length} rows from ${sourceName} for ${symbol}`);
},
},
});
Registers an optimizer configuration in the framework.
The optimizer generates trading strategies by:
The optimizer produces a complete .mjs file containing: