.
├── CFG-Syn/ # Syntax-validity processing engine
├── CFG-Sem/ # + Semantic-validity processing engine
├── CFG-Sem-k/ # + Constraint-optimized processing engine
├── RPN/ # Reverse Polish Notation calculator
├── ML/ # Baseline methods that directly use machine learning techniques to predict stock returns
├── requirements.txt # Project dependencies
└── README.md # Project documentation
• Python 3.8–3.11 (Python 3.9 or 3.10 recommended)
• pip (Python package manager)
-
Clone the repository:
git clone <your-repo-url> cd alpha-discovery-via-grammar-guided-learning-and-search
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS # or .\venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Verify the installation:
python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'CUDA available: {torch.cuda.is_available()}')"
You can obtain the required stock data using one of the following approaches.
Run the built-in script of AlphaGen to automatically fetch and preprocess data using Baostock:
python alphagen/data_collection/fetch_baostock_data.pyAlternatively, you may leverage qlib for more flexible and large-scale financial data handling.
To execute the integrated module pool, just enter the folder directory of different projects. For example:
cd CFG-Sem-kand run:
python run_pool.pyThis project includes several representative baseline methods for comparison.
-
AlphaGen: AlphaGen
-
AlphaQCM: AlphaQCM
-
ML: Pure machine learning baselines that directly predict stock returns without explicit symbolic alpha construction.
To run these baselines, execute:cd ML python main.py
The result of backtest is shown below. 
• Installation may take some time — ensure a stable network connection.
• The project depends on large libraries such as PyTorch and TensorFlow — ensure sufficient disk space.
• For CUDA-related issues, please verify GPU driver and CUDA version compatibility.
If you encounter any issues, please submit an issue on GitHub or contact the development team.
