This repo is the Pytorch code for our paper “Relation-Aware Transformer for Portfolio Policy Learning”[1] in IJCAI 2020.
Note that this library is a part of our main project, and it is several versions ahead of the article.
python 3.7.3 (Anaconda)
pytorch 0.4.1.post2
cudnn 7.4.1
The raw data of Crypto-A is accessed with Poloniex[2]. We provide the Crypto-A dataset in link[3], where data selection is based on the method in [4]. Please download ./database to the same directory as the main.py. The statistics of Crypto-A are summarized as below. | Dataset | Assets | Training | Test |
---|---|---|---|---|
Crypto-A | 12 | 2016.01-2017.11 | 2017.11-2018.01 |
File main.py mainly contains the construction of RAT network, data preprocessing, the fitting model process and testing process. File run_mian.sh mainly contains the parameter configurations of training RAT.
cd ${RAT_ROOT}/RAT-master
./run_main.sh
The figure shows the entire structure of RAT, and we detail some related parameter configurations in run_main.sh as below.
--x_window_size
The length of the price series.
--local_context_length
The length of local price context.
--daily_interest_rate
The interest rate of the loan for one day.
--log_dir
The directory to save the log.
--model_dir
The directory to save the model.
--model_index
Set a unique ID for the model.
After training process, the model is saved in ${SAVE_MODEL_DIR}/${MODEL_INDEX}.pkl. After testing process, the backtest results are saved in ${LOG_DIR}/train_summary.csv. It contains metrics such as fAPV, SR, CR and basktest_history.
We provide a model with 495.28 fAPV in https://drive.google.com/drive/folders/11MK2QSj30G9pYE8qx_-80zgCDmJOHS9U?usp=sharing. You can download the model to ${SAVE_MODEL_DIR}/ and test it. When testing the given model, please comment out line 1443 in main.py to avoid the training process.
This project is constructed based on the open source project:
[PGPortfolio toolbox(https://github.com/ZhengyaoJiang/PGPortfolio)]
[Zhang Y, Zhao P, Li B, et al. Cost-sensitive portfolio selection via deep reinforcement learning[J]. IEEE Transactions on Knowledge and Data Engineering, 2020(https://github.com/Vanint/PPN)]
If you use this code for your research, please consider citing:
@inproceedings{xu-relation,
title = {Relation-Aware Transformer for Portfolio Policy Learning},
author = {Xu, Ke and Zhang, Yifan and Ye, Deheng and Zhao, Peilin and Tan, Mingkui},
booktitle = {Proceedings of the Twenty-Ninth International Joint Conference on Artificial Intelligence},
pages = {4647--4653},
year = {2020},
month = {7},
note = {Special Track on AI in FinTech}
}