In this tutorial, we optimize GPT-4.1 Mini's Chain of Thought (dspy.ChainOfThought) for generating profitable trading strategies using the dspy.GEPA optimizer! We demonstrate how to evolve prompts for different strategy themes (momentum, mean reversion, breakout, arbitrage, volume) with proper risk management.
This implementation realizes Kagen Atkinson's vision of an autonomous LLM-powered trading system with:
- Theme-based Specialization:
--theme
flag for different strategy types (as Kagen intended) - Offline Research Loop (
test_gepa_enhanced.py
): GEPA evolves theme-specific prompts through reflective optimization - Deterministic Execution (
run_gepa_trading.py
): Uses evolved prompts for strategy generation and backtesting