Generating sets of formulaic alpha (predictive) stock factors via reinforcement learning.
Python
1,272
98 commits
updated Jun 4, 2026
Automatic formulaic alpha generation with reinforcement learning.
This repository contains the code for our paper Generating Synergistic Formulaic Alpha Collections via Reinforcement Learning accepted by KDD 2023, Applied Data Science (ADS) track, publically available on ACM DL. Some extensions upon this work are also included in this repo.
/alphagen contains the basic data structures and the essential modules for starting an alpha mining pipeline;/alphagen_qlib contains the qlib-specific APIs for data preparation;/alphagen_generic contains data structures and utils designed for our baselines, which basically follow gplearn APIs, but with modifications for quant pipeline;/alphagen_llm contains LLM client abstractions and a set of prompts useful for LLM-based alpha generation, and also provides some LLM-based automatic iterative alpha-generation routines./gplearn and /dso contains modified versions of our baselines;/scripts contains several scripts for running the experiments.Note that you can either use our builtin alpha calculation pipeline (see Choice 1), or implement an adapter to your own pipeline (see Choice 2).
Builtin pipeline requires Qlib library and local-storaged stock data.
data_collection/fetch_baostock_data.py. The newly downloaded data is saved into ~/.qlib/qlib_data/cn_data_baostock_fwdadj by default. This path can be customized to fit your specific needs, but make sure to use the correct path when loading the data (In alphagen_qlib/stock_data.py, function StockData._init_qlib, the path should be passed to qlib with qlib.init(provider_uri=path)).Maybe you have better implements of alpha calculation, you can implement an adapter of alphagen.data.calculator.AlphaCalculator. The interface is defined as follows:
class AlphaCalculator(metaclass=ABCMeta):
@abstractmethod
def calc_single_IC_ret(self, expr: Expression) -> float:
'Calculate IC between a single alpha and a predefined target.'
@abstractmethod
def calc_single_rIC_ret(self, expr: Expression) -> float:
'Calculate Rank IC between a single alpha and a predefined target.'
@abstractmethod
def calc_single_all_ret(self, expr: Expression) -> Tuple[float, float]:
'Calculate both IC and Rank IC between a single alpha and a predefined target.'
@abstractmethod
def calc_mutual_IC(self, expr1: Expression, expr2: Expression) -> float:
'Calculate IC between two alphas.'
@abstractmethod
def calc_pool_IC_ret(self, exprs: List[Expression], weights: List[float]) -> float:
'First combine the alphas linearly,'
'then Calculate IC between the linear combination and a predefined target.'
@abstractmethod
def calc_pool_rIC_ret(self, exprs: List[Expression], weights: List[float]) -> float:
'First combine the alphas linearly,'
'then Calculate Rank IC between the linear combination and a predefined target.'
@abstractmethod
def calc_pool_all_ret(self, exprs: List[Expression], weights: List[float]) -> Tuple[float, float]:
'First combine the alphas linearly,'
'then Calculate both IC and Rank IC between the linear combination and a predefined target.'
Reminder: the values evaluated from different alphas may have drastically different scales, we recommend that you should normalize them before combination.
All principle components of our expriment are located in train_maskable_ppo.py.
These parameters may help you build an AlphaCalculator:
These parameters will define a RL run:
Please run the individual scripts at the root directory of this project as modules, i.e. python -m scripts.NAME ARGS....
Use python -m scripts.NAME -h for information on the arguments.
scripts/rl.py: Main experiments of AlphaGen/HARLAscripts/llm_only.py: Alpha generator based solely on iterative interactions with an LLM.scripts/llm_test_validity.py: Tests on how the system prompt affects the valid alpha rate of an LLM.save_path;
tensorboard_log.gplearn implements Genetic Programming, a commonly used method for symbolic regression. We maintained a modified version of gplearn to make it compatiable with our task. The corresponding experiment scipt is gp.py
DSO is a mature deep learning framework for symbolic optimization tasks. We maintained a minimal version of DSO to make it compatiable with our task. The corresponding experiment scipt is dso.py
We implemented some trading strategies based on Qlib. See backtest.py and trade_decision.py for demos.
@inproceedings{alphagen,
author = {Yu, Shuo and Xue, Hongyan and Ao, Xiang and Pan, Feiyang and He, Jia and Tu, Dandan and He, Qing},
title = {Generating Synergistic Formulaic Alpha Collections via Reinforcement Learning},
year = {2023},
doi = {10.1145/3580305.3599831},
booktitle = {Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
}
@article{HARLA,
author = {Yu, Shuo and Xue, Hongyan and Ao, Xiang and He, Qing},
title = {A hybrid approach to formulaic alpha discovery with large language model assistance},
journal = {Frontiers of Computer Science},
volume = {20},
number = {2},
pages = {2002316},
year = {2026},
doi = {10.1007/S11704-025-41061-5},
}
Feel free to submit Issues or Pull requests.
This work is maintained by the MLDM research group, IIP, ICT, CAS.
Maintainers include:
Thanks to the following contributors:
Thanks to the following in-depth research on our project:
764 followers · starred Apr 2024
820 followers · starred Jun 2025
49 followers · starred Oct 2026
40 followers · starred May 2025
Generating sets of formulaic alpha (predictive) stock factors via reinforcement learning.
Python
1,272
98 commits
updated Jun 4, 2026
Automatic formulaic alpha generation with reinforcement learning.
This repository contains the code for our paper Generating Synergistic Formulaic Alpha Collections via Reinforcement Learning accepted by KDD 2023, Applied Data Science (ADS) track, publically available on ACM DL. Some extensions upon this work are also included in this repo.
/alphagen contains the basic data structures and the essential modules for starting an alpha mining pipeline;/alphagen_qlib contains the qlib-specific APIs for data preparation;/alphagen_generic contains data structures and utils designed for our baselines, which basically follow gplearn APIs, but with modifications for quant pipeline;/alphagen_llm contains LLM client abstractions and a set of prompts useful for LLM-based alpha generation, and also provides some LLM-based automatic iterative alpha-generation routines./gplearn and /dso contains modified versions of our baselines;/scripts contains several scripts for running the experiments.Note that you can either use our builtin alpha calculation pipeline (see Choice 1), or implement an adapter to your own pipeline (see Choice 2).
Builtin pipeline requires Qlib library and local-storaged stock data.
data_collection/fetch_baostock_data.py. The newly downloaded data is saved into ~/.qlib/qlib_data/cn_data_baostock_fwdadj by default. This path can be customized to fit your specific needs, but make sure to use the correct path when loading the data (In alphagen_qlib/stock_data.py, function StockData._init_qlib, the path should be passed to qlib with qlib.init(provider_uri=path)).Maybe you have better implements of alpha calculation, you can implement an adapter of alphagen.data.calculator.AlphaCalculator. The interface is defined as follows:
class AlphaCalculator(metaclass=ABCMeta):
@abstractmethod
def calc_single_IC_ret(self, expr: Expression) -> float:
'Calculate IC between a single alpha and a predefined target.'
@abstractmethod
def calc_single_rIC_ret(self, expr: Expression) -> float:
'Calculate Rank IC between a single alpha and a predefined target.'
@abstractmethod
def calc_single_all_ret(self, expr: Expression) -> Tuple[float, float]:
'Calculate both IC and Rank IC between a single alpha and a predefined target.'
@abstractmethod
def calc_mutual_IC(self, expr1: Expression, expr2: Expression) -> float:
'Calculate IC between two alphas.'
@abstractmethod
def calc_pool_IC_ret(self, exprs: List[Expression], weights: List[float]) -> float:
'First combine the alphas linearly,'
'then Calculate IC between the linear combination and a predefined target.'
@abstractmethod
def calc_pool_rIC_ret(self, exprs: List[Expression], weights: List[float]) -> float:
'First combine the alphas linearly,'
'then Calculate Rank IC between the linear combination and a predefined target.'
@abstractmethod
def calc_pool_all_ret(self, exprs: List[Expression], weights: List[float]) -> Tuple[float, float]:
'First combine the alphas linearly,'
'then Calculate both IC and Rank IC between the linear combination and a predefined target.'
Reminder: the values evaluated from different alphas may have drastically different scales, we recommend that you should normalize them before combination.
All principle components of our expriment are located in train_maskable_ppo.py.
These parameters may help you build an AlphaCalculator:
These parameters will define a RL run:
Please run the individual scripts at the root directory of this project as modules, i.e. python -m scripts.NAME ARGS....
Use python -m scripts.NAME -h for information on the arguments.
scripts/rl.py: Main experiments of AlphaGen/HARLAscripts/llm_only.py: Alpha generator based solely on iterative interactions with an LLM.scripts/llm_test_validity.py: Tests on how the system prompt affects the valid alpha rate of an LLM.save_path;
tensorboard_log.gplearn implements Genetic Programming, a commonly used method for symbolic regression. We maintained a modified version of gplearn to make it compatiable with our task. The corresponding experiment scipt is gp.py
DSO is a mature deep learning framework for symbolic optimization tasks. We maintained a minimal version of DSO to make it compatiable with our task. The corresponding experiment scipt is dso.py
We implemented some trading strategies based on Qlib. See backtest.py and trade_decision.py for demos.
@inproceedings{alphagen,
author = {Yu, Shuo and Xue, Hongyan and Ao, Xiang and Pan, Feiyang and He, Jia and Tu, Dandan and He, Qing},
title = {Generating Synergistic Formulaic Alpha Collections via Reinforcement Learning},
year = {2023},
doi = {10.1145/3580305.3599831},
booktitle = {Proceedings of the 29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
}
@article{HARLA,
author = {Yu, Shuo and Xue, Hongyan and Ao, Xiang and He, Qing},
title = {A hybrid approach to formulaic alpha discovery with large language model assistance},
journal = {Frontiers of Computer Science},
volume = {20},
number = {2},
pages = {2002316},
year = {2026},
doi = {10.1007/S11704-025-41061-5},
}
Feel free to submit Issues or Pull requests.
This work is maintained by the MLDM research group, IIP, ICT, CAS.
Maintainers include:
Thanks to the following contributors:
Thanks to the following in-depth research on our project:
764 followers · starred Apr 2024
820 followers · starred Jun 2025
49 followers · starred Oct 2026
40 followers · starred May 2025