How dulyhao/alphaforge works
Main Components
a. Data Collection & Preparation:
• Data Collection: Represent the "data_collection" directory. Note that users execute scripts like fetch_baostock_data.py and qlib_dump_bin.py to fetch and prepare raw stock data.
• Data Storage & Qlib Integration: Indicate the integration with Qlib (external dependency) and point out that paths in gan/utils/data.py need to point to the local Qlib data.
b. Alpha Factor Mining and Generation:
• Alphagen Module: Include the alphagen directory, which contains:
• Configurations (config.py),
• Data processing (calculator.py, expression.py, tokens.py, tree.py),
• Model components for alpha pool and general factor modeling (models/alpha_pool.py, models/model.py).
• Generic and Qlib Specific Modules: Outline alphagen_generic and alphagen_qlib directories to show how they extend or modify factor mining functionality.
c. Reinforcement Learning (RL) and Policy:
• RL Environment: Show the alphagen/rl directory with its “env” (core.py, wrapper.py) and policy (policy.py) files, indicating reinforcement learning environment and policy selection used during training.
d. Deep Search Optimization (DSO):
• DSO Module: Represent the “dso” folder that contains various submodules for configuration, core logic (core.py, execute.py), policy and policy optimizers (policy, policy_optimizer), regression tasks (regression), and training utilities. These files indicate another method for alpha factor generation or evaluation using different approaches.
e. Generative Adversarial Networks (GAN):
f. Genetic Programming (gplearn):
• GP Module: Illustrate the gplearn directory containing the core program, genetic operations (fitness.py, functions.py, genetic.py) and its test suite.
g. Training and Experiment Scripts:
• High-level Scripts: At the top-level, include scripts such as train_AFF.py, train_DSO.py, train_GP.py, train_RL.py that orchestrate training for different models.
Relationships and Data Flows
• That the training scripts (train_AFF.py, train_DSO.py, etc.) use the data from the prepared sources, and their outputs (mined alpha factors) are later combined or evaluated (through combine_AFF.py and experiment notebooks).
• Interdependency between the generic modules (alphagen_generic) and the core modules (alphagen, alphagen_qlib): these extend functionality or offer additional operators and features.
• For the RL components, show that the RL environment interacts with the policy modules to adjust the factor generation based on dynamic market data.
Architecturally Important Patterns and Principles
• Multi-Stage Pipeline: Emphasize the three-stage process (mining, combining, evaluation) with clear separation between each stage.
• Modularity: Each directory (alphagen, dso, gan, gplearn) represents a distinct experimental setup or modeling approach, following modular design principles.
• Extensibility: The presence of similar patterns (e.g., policy optimizers in DSO, testing suites in gplearn) indicates that the project is designed to allow plugging in alternative models.
Technologies, Frameworks, and External Dependencies
• External tools and libraries: Qlib for data management; baostock as a data source; Python libraries such as PyTorch (noted in pytorch_utils.py) and possibly scikit-learn (used in regression via sklearn.py).
• Cython components (e.g., dso/cyfunc.pyx) that offer performance optimizations.