|
|
|
|
@@ -1,53 +1,77 @@
|
|
|
|
|
# Learning Multiple Stock Trading Patterns with Temporal Routing Adaptor and Optimal Transport
|
|
|
|
|
|
|
|
|
|
This code provides a PyTorch implementation for TRA (Temporal Routing Adaptor), as described in the paper [Learning Multiple Stock Trading Patterns with Temporal Routing Adaptor and Optimal Transport](http://arxiv.org/abs/2106.12950).
|
|
|
|
|
Temporal Routing Adaptor (TRA) is designed to capture multiple trading patterns in the stock market data. Please refer to [our paper](http://arxiv.org/abs/2106.12950) for more details.
|
|
|
|
|
|
|
|
|
|
* TRA (Temporal Routing Adaptor) is a lightweight module that consists of a set of independent predictors for learning multiple patterns as well as a router to dispatch samples to different predictors.
|
|
|
|
|
* We also design a learning algorithm based on Optimal Transport (OT) to obtain the optimal sample to predictor assignment and effectively optimize the router with such assignment through an auxiliary loss term.
|
|
|
|
|
If you find our work useful in your research, please cite:
|
|
|
|
|
```
|
|
|
|
|
@inproceedings{HengxuKDD2021,
|
|
|
|
|
author = {Hengxu Lin and Dong Zhou and Weiqing Liu and Jiang Bian},
|
|
|
|
|
title = {Learning Multiple Stock Trading Patterns with Temporal Routing Adaptor and Optimal Transport},
|
|
|
|
|
booktitle = {Proceedings of the 27th ACM SIGKDD Conference on Knowledge Discovery \& Data Mining},
|
|
|
|
|
series = {KDD '21},
|
|
|
|
|
year = {2021},
|
|
|
|
|
publisher = {ACM},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@article{yang2020qlib,
|
|
|
|
|
title={Qlib: An AI-oriented Quantitative Investment Platform},
|
|
|
|
|
author={Yang, Xiao and Liu, Weiqing and Zhou, Dong and Bian, Jiang and Liu, Tie-Yan},
|
|
|
|
|
journal={arXiv preprint arXiv:2009.11189},
|
|
|
|
|
year={2020}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# Running TRA
|
|
|
|
|
## Usage (Recommended)
|
|
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
- Install `Qlib` main branch
|
|
|
|
|
**Update**: `TRA` has been moved to `qlib.contrib.model.pytorch_tra` to support other `Qlib` components like `qlib.workflow` and `Alpha158/Alpha360` dataset.
|
|
|
|
|
|
|
|
|
|
## Running
|
|
|
|
|
Please follow the official [doc](https://qlib.readthedocs.io/en/latest/component/workflow.html) to use `TRA` with `workflow`. Here we also provide several example config files:
|
|
|
|
|
|
|
|
|
|
- `workflow_config_tra_Alpha360.yaml`: running `TRA` with `Alpha360` dataset
|
|
|
|
|
- `workflow_config_tra_Alpha158.yaml`: running `TRA` with `Alpha158` dataset (with feature subsampling)
|
|
|
|
|
- `workflow_config_tra_Alpha158_full.yaml`: running `TRA` with `Alpha158` dataset (without feature subsampling)
|
|
|
|
|
|
|
|
|
|
The performances of `TRA` are reported in [Benchmarks](https://github.com/microsoft/qlib/tree/main/examples/benchmarks).
|
|
|
|
|
|
|
|
|
|
## Usage (Not Maintained)
|
|
|
|
|
|
|
|
|
|
This section is used to reproduce the results in the paper.
|
|
|
|
|
|
|
|
|
|
### Running
|
|
|
|
|
|
|
|
|
|
We attach our running scripts for the paper in `run.sh`.
|
|
|
|
|
|
|
|
|
|
And here are two ways to run the model:
|
|
|
|
|
|
|
|
|
|
* Running from scripts with default parameters
|
|
|
|
|
You can directly run from Qlib command `qrun`:
|
|
|
|
|
```
|
|
|
|
|
qrun configs/config_alstm.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
You can directly run from Qlib command `qrun`:
|
|
|
|
|
```
|
|
|
|
|
qrun configs/config_alstm.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Running from code with self-defined parameters
|
|
|
|
|
Setting different parameters is also allowed. See codes in `example.py`:
|
|
|
|
|
```
|
|
|
|
|
python example.py --config_file configs/config_alstm.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Setting different parameters is also allowed. See codes in `example.py`:
|
|
|
|
|
```
|
|
|
|
|
python example.py --config_file configs/config_alstm.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Here we trained TRA on a pretrained backbone model. Therefore we run `*_init.yaml` before TRA's scipts.
|
|
|
|
|
|
|
|
|
|
# Results
|
|
|
|
|
|
|
|
|
|
## Outputs
|
|
|
|
|
### Results
|
|
|
|
|
|
|
|
|
|
After running the scripts, you can find result files in path `./output`:
|
|
|
|
|
|
|
|
|
|
`info.json` - config settings and result metrics.
|
|
|
|
|
* `info.json` - config settings and result metrics.
|
|
|
|
|
* `log.csv` - running logs.
|
|
|
|
|
* `model.bin` - the model parameter dictionary.
|
|
|
|
|
* `pred.pkl` - the prediction scores and output for inference.
|
|
|
|
|
|
|
|
|
|
`log.csv` - running logs.
|
|
|
|
|
Evaluation metrics reported in the paper:
|
|
|
|
|
|
|
|
|
|
`model.bin` - the model parameter dictionary.
|
|
|
|
|
|
|
|
|
|
`pred.pkl` - the prediction scores and output for inference.
|
|
|
|
|
|
|
|
|
|
## Our Results
|
|
|
|
|
| Methods | MSE| MAE| IC | ICIR | AR | AV | SR | MDD |
|
|
|
|
|
|-------------------|-------------------|---------------------|--------------------|--------------------|--------------------|--------------------|--------------------|--------------------|
|
|
|
|
|
|-------|-------|------|-----|-----|-----|-----|-----|-----|
|
|
|
|
|
|Linear|0.163|0.327|0.020|0.132|-3.2%|16.8%|-0.191|32.1%|
|
|
|
|
|
|LightGBM|0.160(0.000)|0.323(0.000)|0.041|0.292|7.8%|15.5%|0.503|25.7%|
|
|
|
|
|
|MLP|0.160(0.002)|0.323(0.003)|0.037|0.273|3.7%|15.3%|0.264|26.2%|
|
|
|
|
|
@@ -61,21 +85,8 @@ After running the scripts, you can find result files in path `./output`:
|
|
|
|
|
|
|
|
|
|
A more detailed demo for our experiment results in the paper can be found in `Report.ipynb`.
|
|
|
|
|
|
|
|
|
|
# Common Issues
|
|
|
|
|
## Common Issues
|
|
|
|
|
|
|
|
|
|
For help or issues using TRA, please submit a GitHub issue.
|
|
|
|
|
|
|
|
|
|
Sometimes we might encounter situation where the loss is `NaN`, please check the `epsilon` parameter in the sinkhorn algorithm, adjusting the `epsilon` according to input's scale is important.
|
|
|
|
|
|
|
|
|
|
# Citation
|
|
|
|
|
If you find this repository useful in your research, please cite:
|
|
|
|
|
```
|
|
|
|
|
@inproceedings{HengxuKDD2021,
|
|
|
|
|
author = {Hengxu Lin and Dong Zhou and Weiqing Liu and Jiang Bian},
|
|
|
|
|
title = {Learning Multiple Stock Trading Patterns with Temporal Routing Adaptor and Optimal Transport},
|
|
|
|
|
booktitle = {Proceedings of the 27th ACM SIGKDD Conference on Knowledge Discovery \& Data Mining},
|
|
|
|
|
series = {KDD '21},
|
|
|
|
|
year = {2021},
|
|
|
|
|
publisher = {ACM},
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
Sometimes we might encounter situation where the loss is `NaN`, please check the `epsilon` parameter in the sinkhorn algorithm, adjusting the `epsilon` according to input's scale is important.
|
|
|
|
|
|