This repository contains a reproduction of the ProFiT framework as described in the research paper "ProFiT: Program Search for Financial Trading".
ProFiT is an LLM-driven evolutionary search algorithm that autonomously discovers and improves algorithmic trading strategies. It uses a closed feedback loop where an LLM analyzes strategy performance on backtests and proposes code-level improvements.
- LLM-Driven Evolution: Uses Large Language Models (e.g., GPT-4) to act as both "Analyst" and "Developer" to mutate trading strategies.
- Code-Level Search: Strategies are represented as executable Python code, not abstract parameters.
- Self-Repair: Includes a repair loop where the LLM fixes syntax or runtime errors based on tracebacks.
- Walk-Forward Validation: Implements the specific 5-fold time-series split described in the paper.
- Robust Backtesting: Uses
backtesting.py(vialucit-backtesting) with realistic constraints ( 0.2% commission, exclusive orders).
This project is managed with uv.
-
Install dependencies:
uv sync
-
Set up Environment: If using the OpenAI client, set your API key:
export OPENAI_API_KEY="sk-..."
Edit config.yaml to control the experiment parameters:
data:
path: "tests/data/Bitcoin_historical_data_coinmarketcap.csv"
ga:
generations: 15 # Number of evolutionary steps
llm:
client: "openai" # "openai" or "mock"
model: "gpt-4o"To run the standard experiment (Seed: Bollinger, Fold: 0):
python main.pyResults will be saved to runs/reproduction_run, including the generated strategy code and fitness plots.
profit/optimizer.py: The core ProFiT evolutionary loop (Algorithm 1).profit/llm/client.py: LLM interaction logic (Analysis, Improvement, Repair prompts).profit/seed_strategies.py: The 5 initial seed strategies and baselines.profit/backtester/lucit_adapter.py: Adapter for the backtesting engine.profit/strategy.py: Definition of the code-based Chromosome.
- This implementation currently runs on a single Fold per execution (configurable in
main.py). - Default config uses a Mock LLM for safety; switch to "openai" for real reproduction.
MIT