English | 中文
LLM-Driven Boolean Rule Evolution for Stock Selection
100% Local. Zero API calls. Your data, your models, your alpha. No leakage, ever.
Evolved Rule:
(((high + low) / 2) - close) > ((((high + low) / 2) - close).rolling_std(10))
| Metric | Train (1899 days) | Test (664 days) |
|---|---|---|
| Sharpe | 1.44 | 1.16 |
| Total Return | 600.8% | 145.0% |
| Max Drawdown | -74.5% | -44.8% |
| Win Rate | 52.4% | 50.6% |
pip install -r requirements.txtInstall and run a local LLM server using LM Studio or Ollama.
Recommended GGUF models (4GB+ VRAM):
-
Thinker (reasoning/analysis):
Qwen3-4B-Instruct-2507-Gemini-3-Pro-Preview-Distill-GGUF or Falcon-H1R-7B-GGUF -
Summarizer (final output):
Qwen3-4B-Instruct-2507-GGUF
Edit config.json to set key parameters:
| Parameter | Description |
|---|---|
generations |
Number of evolution cycles |
attempts |
Rule mutations per generation |
amount_rank_n |
Stock pool size (e.g., 5-20) |
return_type |
o2c, o2o, c2c, or c2o |
transaction_fee |
Default: 0.0007 |
train_test_ratio |
Train/test data split |
streamlit run app.py-
Configure parameters in the left sidebar:
- Stock Selection: Data source and prefix filters
- LLM Configuration: Choose local LLM service and models
- Evolution Settings: Generations, attempts, return type
- Data Filter: Optional amount ranker for stock pool size
- Date Range: Select backtest period
- Train/Test Split: Set ratio for validation
-
Run Evolution tab: Click "Run Evolution" to start the genetic algorithm
-
Results tab: View top performing rules, plots, and performance metrics
-
Stock Selector tab: Test boolean conditions on specific dates
BoolQuant evolves human-readable boolean rules to select stocks based on LLM generated indicators from basic ohlcv:
((close - low) / (high - low) * volume) > ((close - low) / (high - low) * volume).shift(1)
- LLM generates rule mutations based on backtest feedback
- Rules are evaluated on historical train data
- Top performers are selected and mutated
- Process repeats for N generations
- Best rules are tested on held-out test data
Unlike traditional portfolio optimization methods that may output hundreds of candidates, BoolQuant's Stock Pool Ranker is designed to produce a small, focused list (typically 5-20 stocks) for research analysis.
This compact approach enables:
- In-depth review of each candidate's characteristics
- Manageable scope for technical or fundamental analysis
- Clear interpretability of what the rules are selecting
The system ranks stocks by trading volume and applies evolved boolean rules to filter the pool. Always follow the provided selection hint (e.g., "select from the first 5 stocks whose open price is between 0.97× and 0.99× preclose") to ensure:
- No lookahead bias: Uses only information available at decision time
- Reproducible methodology: Deterministic, rules-based selection
- Research discipline: Prevents arbitrary cherry-picking
This focused output is designed for research and educational exploration, not as trading recommendations.
- Python 3.10+
- Local LLM server (Ollama or LM Studio)
BoolQuant is a personal research project for educational purposes only.
- Not intended for production trading or investment decisions
- No warranties or guarantees of any kind
- Past backtest performance does not predict future results
- Use at your own risk for research purposes only
Personal Open Research License. See LICENSE file for details.


