Home

Awesome

TradeMaster: An RL Platform for Trading

Python 3.7 Platform License

<div align="center"> <img align="center" src=figure/Logo.png width="30%"/> </div>

TradeMaster is a first-of-its kind, best-in-class open-source platform for quantitative trading (QT) empowered by reinforcement learning (RL).

It covers the full pipeline for the design, implementation, evaluation and deployment of RL-based trading methods. It contains: 1) a toolkit for efficient data collection, preprocessing and analysis; 2) a high-fidelity data-driven market simulator for mainstream QT tasks (e.g., portfolio management and algorithmic trading); 3) standard implementations of over 10 novel FinRL methods; 4) a systematic evaluation benchmark called PRUDEX-Compass.

Outline

Overview

<div align="center"> <img align="center" src=figure/Architecture.jpg width="70%"/> </div>

TradeMaster could be beneficial to a wide range of communities including leading trading firms, startups, financial service providers and personal investors. We hope TradeMaster can make a change for the whole pipeline of FinRL to prevent untrustworthy results and lead successful industry deployment.

Installation

We provide a video tutorial of using docker to build a proper environment of running this project.

Video Tutorial

To help you better understand the step discribed in the video, Here are the installation tutorials for different operating systems:

Tutorial

We provide tutorials for users to get start with.

AlgorithmDatasetCode linkDescription
Classic RLFXtutorialClassic RL Algorithms for Portfolio Management on FX
DeepScalperBitcointutorialDeepScalper for Algorithm Trading on Crypto
EIIEDJ30tutorialEIIE for Portfolio Management on DJ30
IMITDJ30tutorialInvestor Imitator for Portfolio Management on DJ30
SARLDJ30tutorialSARL for Portfolio Management on DJ30

Toolkit

Results and Visualization

The evaluation module of TradeMaster is mainly based on PRUDEX-Compass, a systematic evaluation toolkit of FinRL methods with 6 axes and 17 measures. We show some results here:

PRUDEX-Compass provides an intuitive visual means to give readers a sense of comparability and positioning of FinRL methods. The inner level maps out the relative strength of FinRL methods in terms of each axis, whereas the outer level provides a compact way to visually assess which set-up and evaluation measures are practically reported to point out how comprehensive the evaluation are for FinRL algorithms.

<div align="center"> <img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/PRUDEX.jpg" width = 500 height = 400 /> </div>

PRIDE-Star is a star plot to evaluate profitability,risk-control and diversity. It contains the normalized score of 8 measures.

<table align="center"> <tr> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/A2C.PNG" width = 220 height = 200 /> </center></td> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/PPO.PNG" width = 220 height = 200 /> </center></td> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/SAC.PNG" width = 220 height = 200 /> </center></td> </tr> <tr> <td align="center"><center>(a) A2C</center></td><td align="center"><center>(b) PPO</center></td> <td align="center"><center>(c) SAC</center></td> </tr> </table>

Rank distribution plot is a bar plot, where the i-th column in the rank distribution shows the probability that a given method is assigned rank i in the corresponding metrics.

<table align="center"> <tr> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/result/visualization/rank-1.png" width = 300 height = 170 /> </center></td> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/USrank.PNG" width = 300 height = 170 /> </center></td> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/FXrank.PNG" width = 300 height = 170 /> </center></td> </tr> <tr> <td align="center"><center>(a) All 4 datasets</center></td><td align="center"><center>(b) DJ30</center></td> <td align="center"><center>(c) FX</center></td> </tr> </table> <!-- <div align="center"> <img src="https://github.com/qinmoelei/TradeMaster_reframe/blob/master/tutorial/result/visualization/rank-1.png" width = 300 height = 225 /> </div> -->

Performance profile reports FinRL methods' score distribution of all runs across the different financial markets that are statistically unbiased and more robust to outliers.

<table align="center"> <tr> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/result/visualization/pp-1.png" width = 300 height = 170 /> </center></td> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/USPP.PNG" width = 300 height = 170 /> </center></td> <td ><center><img src="https://github.com/TradeMaster-NTU/TradeMaster/blob/main/tutorial/visualization_data/FXPP.PNG" width = 300 height = 170 /> </center></td> </tr> <tr> <td align="center"><center>(a) All 4 datasets</center></td><td align="center"><center>(b) DJ30</center></td> <td align="center"><center>(c) FX</center></td> </tr> </table> <!-- <div align="center"> <img src="https://github.com/qinmoelei/TradeMaster_reframe/blob/master/tutorial/result/visualization/pp-1.png" width = 300 height = 225 /> </div> -->

For more information of the usage of this part, please refer to this tutorial and this project

Model Zoo

DeepScalper based on Pytorch (Shuo Sun et al, CIKM 22)

OPD based on Pytorch (Fang et al, AAAI 21)

DeepTrader based on Pytorch (Wang et al, AAAI 21)

SARL based on Pytorch (Yunan Ye et al, AAAI 20)

ETTO based on Pytorch (Lin et al, 20)

Investor-Imitator based on Pytorch (Yi Ding et al, KDD 18)

EIIE based on Pytorch (Jiang et al, 17)

Classic RL based on Pytorch and Ray: PPO A2C SAC DDPG DQN PG TD3

Dataset

DatasetData SourceTypeRange and FrequencyRaw DataDatasheet
SP500YahooFinanceUS Stock2000/01/01-2022/01/01, 1dayOHLCVSP500
DJ30YahooFinanceUS Stock2012/01/01-2021/12/31, 1dayOHLCVDJ30
FXKaggleFX2000/01/01-2019/12/31, 1dayOHLCVFX
CryptoKaggleCrypto2013/04/29-2021/07/06, 1dayOHLCVCrypto
SZ50YahooFinanceCN Securities2009/01/02-2021-01-01, 1dayOHLCVSZ50
BitcoinKaggleCrypto2021-04-07 11:33-2021-04-19 09:54 , 1minLOBBitcoin

OHLCV: open, high, low, and close prices; volume: corresponding trading volume

External Data Source

Users may download data from the following data source with personal account:

Data SourceTypeRange and FrequencyRequest LimitsRaw Data
AlpacaUS Stocks, ETFs2015-now, 1minAccount-specificOHLCV
BaostockCN Securities1990-12-19-now, 5minAccount-specificOHLCV
BinanceCryptocurrencyAPI-specific, 1s, 1minAPI-specificTick-level daily data
CCXTCryptocurrencyAPI-specific, 1minAPI-specificOHLCV
IEXCloudNMS US securities1970-now, 1 day100 per second per IPOHLCV
JoinQuantCN Securities2005-now, 1min3 requests each timeOHLCV
QuantConnectUS Securities1998-now, 1sNAOHLCV
RiceQuantCN Securities2005-now, 1msAccount-specificOHLCV
TushareCN Securities, A share-now, 1 minAccount-specificOHLCV
WRDSUS Securities2003-now, 1ms5 requests each timeIntraday Trades
YahooFinanceUS SecuritiesFrequency-specific, 1min2,000/hourOHLCV

How to Use Your Own Data

TradeMaster supports financial data with open, high, low, close, volume (OHLCV) raw informations as:

<div align="center"> <img align="center" src=figure/ohlcv.jpg width="70%"/> </div>

We compute 10 technical indicators to describe the financial markets:

<div align="center"> <img align="center" src=figure/feature.jpg width="40%"/> </div>

Users can adapt their data with prefered features by changing the data loading and feature calculation part with corresponding input and output size. We plan to support limit order book (LOB) and altervative data such as text and graph in the future.

File Structure

|-- agent
|   |-- ClassicRL
|   |-- DeepScalper
|   |-- DeepTrader
|   |-- EIIE
|   |-- Investor_Imitator
|   |-- SARL
|-- config
|   |-- input_config
|   |-- output_config
|-- data
|   |-- download_data.py
|   |-- preprocess.py
|   |-- data
|       |-- BTC
|       |-- dj30
|       |-- exchange
|       |-- sz50
|-- env
|   |-- AT
|   |-- OE
|   |-- PM
|-- experiment
|-- figure
|-- result
|-- tutorial
|   |-- ClassRL_for_PM_on_FX.ipynb
|   |-- DeepScalper_for_AT_on_Bitcoin.ipynb
|   |-- EIIE_for_PM_on_DJ30.ipynb
|   |-- IMIT_for_PM_on_DJ30.ipynb
|   |-- SARL_for_PM_on_DJ30.ipynb
|   |-- Visualization.ipynb
|-- visualization
|   |-- compass
|   |-- exen
|   |-- ocatgon
|   |-- performance_profile
|   |-- rank
|-- README.md
|-- requirement.txt

Publications

Deep Reinforcement Learning for Quantitative Trading: Challenges and Opportunities (IEEE Intelligent Systems 2022)

DeepScalper: A Risk-Aware Reinforcement Learning Framework to Capture Fleeting Intraday Trading Opportunities (CIKM 2022)

Commission Fee is not Enough: A Hierarchical Reinforced Framework for Portfolio Management (AAAI 21)

Reinforcement Learning for Quantitative Trading (Survey)

PRUDEX-Compass: Towards Systematic Evaluation of Reinforcement Learning in Financial Markets

Contact

Join Us

We have positions for software engineer, RA and postdoc. If you are interested in working at the intersection of RL and financial trading, feel free to send an email to shuo003@e.ntu.edu.sg with your CV.

Competition

TradeMaster Cup 2022