Automated trading strategy generation system using LLM-powered analysis and backtest-kit framework.
Demonstrates AI-driven strategy optimization capabilities for:
Multi-Timeframe Analysis: 4 data sources with different granularity levels
LLM Integration: Ollama-powered strategy generation (gpt-oss:20b)
Training/Testing Split: 7-day training period → 1-day validation
Walker Framework: Automatic strategy comparison and ranking
Progress Monitoring: Real-time optimization tracking
Rich Indicators: 50+ technical indicators across all timeframes
demo/optimization/
├── src/
│ └── index.mjs # Main optimizer configuration
├── generated/ # AI-generated strategy code (output)
├── package.json # Dependencies and scripts
└── README.md # This file
# Navigate to project directory
cd demo/optimization
# Install dependencies
npm install
# Set environment variables
export OLLAMA_API_KEY=your_ollama_api_key
# Run optimizer
npm start
Create a .env file or set environment variables:
OLLAMA_API_KEY=your_ollama_api_key
CCXT_DUMPER_URL=node-ccxt-dumper-instance
The optimizer is pre-configured for BTCUSDT with:
Run the optimizer to generate strategies:
npm start
Output:
Progress: 14.285714285714286%
Progress: 28.571428571428573%
Progress: 42.857142857142854%
Progress: 57.14285714285714%
Progress: 71.42857142857143%
Progress: 85.71428571428571%
Progress: 100%
Generated file: ./generated/btc-optimizer_BTCUSDT.mjs
After generation, execute the strategy comparison:
node ./generated/btc-optimizer_BTCUSDT.mjs
This will:
Modify src/index.mjs to analyze different cryptocurrencies:
await Optimizer.dump(
"ETHUSDT", // Change symbol
{
optimizerName: "btc-optimizer",
},
"./generated"
);
Edit training/testing periods in src/index.mjs:
const TRAIN_RANGE = [
{
note: "Custom period 1",
startDate: new Date("2025-01-01T00:00:00Z"),
endDate: new Date("2025-01-01T23:59:59Z"),
},
// Add more training periods...
];
const TEST_RANGE = {
note: "Validation period",
startDate: new Date("2025-01-08T00:00:00Z"),
endDate: new Date("2025-01-08T23:59:59Z"),
};
For each training period (7 days):
For each training period:
.mjs fileGenerated code runs Walker to:
The system uses strategic prompting for better strategy generation:
// System prompt
"В ответ напиши торговую стратегию где нет ничего лишнего,
только отчёт готовый для копипасты целиком
**ВАЖНО**: Не здоровайся, не говори что делаешь - только отчёт!"
// User prompt
`На каких условиях мне купить ${symbol}?
Дай анализ рынка на основе поддержки/сопротивления, точек входа в LONG/SHORT позиции.
Какой RR ставить для позиций?
Предпочтительны LONG или SHORT позиции?
Сделай не сухой технический, а фундаментальный анализ,
содержащий стратигическую рекомендацию, например, покупать на низу боковика`
This encourages:
Generated strategies are evaluated by:
SOURCE_LIST.push({
name: "custom-indicators",
fetch: async ({ symbol, startDate, endDate, limit, offset }) => {
// Fetch custom data
return data.rows;
},
user: (symbol, data) => str.newline(
"=== CUSTOM INDICATORS ===",
JSON.stringify(data)
),
assistant: () => "Custom data received"
});
const response = await ollama.chat({
model: "llama3:70b", // Use different model
messages: [...]
});
addOptimizer({
optimizerName: "btc-optimizer",
// ... existing config
callbacks: {
onSourceData: (symbol, sourceName, data) => {
console.log(`✓ Fetched ${data.length} rows from ${sourceName}`);
},
onData: (symbol, strategies) => {
console.log(`✓ Generated ${strategies.length} strategies`);
},
onCode: (symbol, code) => {
console.log(`✓ Code generated: ${code.length} bytes`);
}
}
});
MIT © tripolskypetr