TradeMaster RL Platform

repository·1.0.0·Indexed 25 days ago

https://github.com/trademaster-ntu/trademaster

An open-source reinforcement learning platform for quantitative trading. It provides a full pipeline including multi-modality market data, data preprocessing, high-fidelity market simulators, and a model zoo featuring over 13 RL-based trading algorithms (such as DeepScalper, SARL, and ETEO). The platform includes evaluation toolkits with the PRIDE-Star visualization tool, as well as specialized tools like EarnMore and FinAgent for advanced trading workflows.

Tokens
15.9K
Snippets
38
Records
88
Agent score
84%

What's inside TradeMaster

  1. Overview of TradeMaster Architecture

    1.0.0

    TradeMaster is an open-source platform for quantitative trading (QT) using reinforcement learning (RL). It provides a complete pipeline for designing, implementing, evaluating, and deploying RL-based trading algorithms. The architecture consists of six core modules:

    1. Multi-modality market data: Supports various financial assets at multiple granularities.
    2. Data preprocessing pipeline: A complete workflow for preparing market data.
    3. Market simulators: High-fidelity, data-driven simulators designed for mainstream QT tasks.
    4. RL algorithms: Efficient implementations of over 13 novel RL-based trading algorithms.
    5. Evaluation toolkits: Systematic evaluation tools covering 6 axes and 17 measures.
    6. Interdisciplinary interfaces: Various interfaces designed to accommodate users from different backgrounds.
  2. Overview of TradeMaster RL Platform

    1.0.0

    TradeMaster is an open-source reinforcement learning (RL) platform designed for quantitative trading (QT). It provides a full pipeline for designing, implementing, evaluating, and deploying RL-based trading algorithms. The platform is composed of six key modules:

    1. Multi-modality market data: Supports various financial assets at multiple granularities.
    2. Data preprocessing pipeline: A complete workflow for preparing financial data.
    3. Market simulators: High-fidelity, data-driven simulators for mainstream QT tasks.
    4. RL algorithms: Efficient implementations of over 13 novel RL-based trading algorithms.
    5. Evaluation toolkits: Systematic evaluation tools using 6 axes and 17 measures.
    6. Interdisciplinary interfaces: Various interfaces designed for users from different backgrounds.
  3. Understand the TradeMaster File Structure

    1.0.0

    The repository is organized into several functional directories:

    • configs/: Configuration files.
    • data/: Datasets categorized by algorithmic_trading, high_frequency_trading, order_execution, and portfolio_management.
    • deploy/: Backend service and client scripts (backend_service.py, backend_client.py).
    • installation/: Setup guides for Docker and requirements.
    • tools/: Specialized tools for algorithmic_trading, data_preprocessor, high_frequency_trading, market_dynamics_labeling, missing_value_imputation, order_execution, and portfolio_management.
    • tradmaster/: The core library containing agents, datasets, environments, evaluation, imputation, losses, nets, preprocessor, optimizers, pretrained, trainers, transition, and utils.
    • unit_testing/: Test suites.
  4. Understand the TradeMaster project structure

    1.0.0

    The TradeMaster repository is organized into several functional directories. Key directories include:

    • configs/: Configuration files for experiments and environments.
    • data/: Datasets categorized by trading type: algorithmic_trading, high_frequency_trading, order_excution, and porfolio_management.
    • deploy/: Scripts for backend services and clients (backend_service.py, backend_client.py).
    • tools/: Specialized utilities for data preprocessing, market dynamics labeling, missing value imputation, and task-specific tools (e.g., algorithmic_trading, high_frequency_trading).
    • tradmaster/: The core library containing RL components:
      • agents/: Reinforcement learning agent implementations.
      • datasets/: Dataset handling logic.
      • enviornments/: Trading environment implementations.
      • evaluation/: Metrics and evaluation logic.
      • imputation/: Missing value imputation modules.
      • losses/: Loss function definitions.
      • nets/: Neural network architectures.
      • preprocessor/: Data preprocessing logic.
      • optimizers/: Optimization algorithms.
      • pretrained/: Pre-trained model weights.
      • trainers/: Training loops and logic.
      • transition/: State transition logic.
      • utils/: General utility functions.
    • installation/: Documentation for setup via Docker or requirements.
    • unit_testing/: Test suites for the project.
  5. Label datasets with Market Dynamics Modeling

    1.0.0

    Use the Market Dynamics Modeling module to label raw datasets with interpretable and controllable dynamics. This allows you to use these dynamics as meta-information for targeted policy evaluation.

    Workflow:

    1. Configure Parameters: Edit the configuration file located at configs/market_dynamics_modeling/market_dynamics_modeling.py. For detailed information on the modeling algorithm and parameters, refer to the TradeMaster_Sandbox_whitepaper.pdf.
    2. Run Labeling: Execute the labeling script to prepare the dataset.
    3. Tune Results: Review the experiment logs and generated visualizations (metrics_of_each_dynamics.png and slice_and_merge_model_{dynamic_number}dynamics_minlength{min_length_limit}_{labeling_method}_labeling_{tic}.png) to adjust hyperparameters until the dynamics meet your requirements.
    python tools/market_dynamics_labeling/run.py
  6. Create and activate a Conda environment for TradeMaster

    1.0.0

    TradeMaster requires Python 3.9+. It is recommended to use Miniconda. Use the following commands to update your base conda installation, create a new environment named TradeMaster, and activate it.

    conda update -n base -c defaults conda
    conda create --name TradeMaster python=3.9
    conda activate TradeMaster
  7. Implement High Frequency Trading with Double DQN (HFT_DDQN)

    1.0.0

    High Frequency Trading (HFT) in TradeMaster involves buying or selling a pre-selected financial instrument periodically within seconds, accounting for order execution. The HFT_DDQN approach utilizes a double Q network and a decayed supervised regulator (generated from a real Q-table based on future price information) to optimize profit margins.

    You can implement this using the provided Jupyter Notebook or the standalone training script.

  8. Test an agent under a specific market dynamic

    1.0.0

    After preparing your labeled dataset, you can perform evaluation on a specific market dynamic by running the trainer with the dynamics_test task. This will generate reports and visualization results (such as Radar plots).

    Use the --task_name dynamics_test argument and specify the target dynamic index using --test_dynamic.

    python tools/algorithmic_trading/train.py --task_name dynamics_test --test_dynamic 0
  9. Implement Portfolio Management with SARL

    1.0.0

    The State Augmented Reinforcement Learning (SARL) method for portfolio management uses asset prices (internal features) and Financial News (external information) to construct an augmented state $s$. The asset movement signal $\delta$ is used for state augmentation, allowing the policy network to generate management strategies from the augmented state.

    You can implement the training and testing process for SARL using the provided notebook or Python script within the TradeMaster framework.

  10. Generate high-level evaluations with PRUDEX-Compass

    1.0.0

    PRUDEX-Compass provides high-level benchmarking using 6 axes and 16 measures. You can generate a compass visualization by running the create_compass.py script with a JSON data file.

    JSON Data Format Requirements: Each entry in the JSON list must define:

    • color: One of ["magenta", "green", "blue", "orange", "cyan", "brown"].
    • label: A string describing the entry.
    • inner_level: An integer attribute value between 1 and 100.
    • outer_level: A boolean value (true or false).
  11. Run TradeMaster using Docker

    1.0.0

    After building the image, you can verify the installation by running an interactive container and executing a training script. Use docker run -it to enter the container's bash shell, then run the tools/algorithmic_trading/train.py script to start an experiment.

    docker images
    docker run -it --name trademaster trademaster:1.0.0 /bin/bash
    # Inside the container:
    python tools/algorithmic_trading/train.py