Qlib Quantitative Investment Platform

repository·main·Indexed 13 days ago

https://github.com/microsoft/qlib

An AI-oriented quantitative investment platform providing a full machine learning pipeline for financial research, including data processing, model training, and back-testing. It supports supervised learning, reinforcement learning, and market dynamics modeling, featuring implementations like ALSTM, DoubleEnsemble, GATs, and KRNN. The platform includes specialized datasets such as Alpha158 and Alpha360 and provides comprehensive signal-based and portfolio-based evaluation metrics.

Tokens
62.2K
Snippets
180
Records
282
Agent score
98%

What's inside Qlib

  1. Overview of Qlib

    main
    Qlib is an AI-oriented quantitative investment platform designed to empower research and create value using AI technologies in quantitative investment. It provides a comprehensive framework covering the entire quantitative pipeline, from data management to model training, backtesting, and online serving.
  2. Overview of Online Serving in Qlib

    main

    Online Serving is a suite of modules in Qlib designed to move beyond backtesting by enabling models to make predictions in real market conditions or facilitate real trading. It allows models to utilize the latest available data for live decision-making.

    Key components include:

    • Online Manager: Manages the online workflow and tasks.
    • Online Strategy: Defines the logic for how predictions are converted into trading actions.
    • Online Tool: Provides utility functions for online operations.
    • Updater: Handles the updating of models or data to ensure they remain current.

    Important Requirements & Limitations:

    • Data Freshness: Users must ensure their data sources are continuously updated. Qlib provides scripts (e.g., for Yahoo Finance) to automate daily data collection.
    • Prediction vs. Execution: Currently, Qlib supports daily updating predictions for the next trading day. However, it does not support generating orders for the next trading day due to public data limitations.
    • Task Management: For managing large numbers of models or complex tasks, users should refer to the Task Management documentation, which utilizes components like TrainerRM or Collector.
  3. What is Qlib?

    main

    Qlib is an open-source, AI-oriented quantitative investment platform designed to empower research and create value using AI technologies. It covers the entire quantitative investment chain, including alpha seeking, risk modeling, portfolio optimization, and order execution.

    Key capabilities include:

    • Full ML Pipeline: Supports data processing, model training, and back-testing.
    • Diverse Modeling Paradigms: Supports supervised learning (for mining non-linear patterns), market dynamics modeling (using adaptive concept drift), and reinforcement learning (for continuous investment decisions).
    • SOTA Research: Integrates state-of-the-art quantitative research works and models.
  4. Available Data Collection Scripts

    main

    Qlib provides several built-in scripts for collecting different types of financial data:

    • yahoo: Retrieves US and CN stock data from Yahoo Finance.
    • fund: Retrieves fund data from http://fund.eastmoney.com.
    • cn_index: Retrieves Chinese indices (e.g., CSI300, CSI100) from http://www.csindex.com.cn.
    • us_index: Retrieves US indices (e.g., SP500, NASDAQ100, DJIA, SP400) from Wikipedia.
    • contrib: Contains scripts for auxiliary functions.
  5. Overview of Graph Attention Networks (GATs) in Qlib

    main

    Qlib includes a custom implementation of Graph Attention Networks (GATs) built using PyTorch. GATs use masked self-attentional layers on graph-structured data, allowing nodes in stacked layers to attend to their neighborhoods' features. This implementation avoids costly matrix operations (like inversion) and does not require the graph structure to be known upfront.

    For theoretical background, refer to the original paper: Graph Attention Networks.

  6. What is a Point-in-Time (PIT) Database?

    main

    A Point-in-Time (PIT) database is designed to prevent data leakage during historical market analysis and backtesting. In financial datasets, information (like financial reports) is often amended or updated over time. If a backtest uses the latest version of a data point for a historical timestamp, it is using information that would not have been available at that time.

    A PIT database ensures that for any historical timestamp, the user retrieves the specific version of the data that was actually available at that moment, maintaining consistency between historical backtesting and online trading performance.

  7. What is Temporally Correlated Task Scheduling (TCTS)?

    main

    Temporally Correlated Task Scheduling (TCTS) is a framework for sequence learning that utilizes multiple temporally correlated auxiliary tasks to improve the training of a main task. In financial contexts like stock trend forecasting, these auxiliary tasks might involve predicting stock prices for different future time steps (e.g., predicting tomorrow's price vs. the day after tomorrow).

    Key components include:

    • Learnable Task Scheduler: An adaptive component that selects the best auxiliary task during training based on the current model status and minibatch data.
    • Bi-level Optimization: The scheduler and the main model are trained jointly. The scheduler is optimized to maximize validation performance, while the model is optimized to minimize training loss guided by the scheduler's task selection.
  8. What is DoubleEnsemble?

    main

    DoubleEnsemble is an ensemble framework designed for financial market prediction. It addresses two primary challenges in financial data: low signal-to-noise ratios and the increasing number of features.

    It works through two main mechanisms:

    1. Sample Reweighting: Identifies key samples based on training dynamics (learning trajectories).
    2. Feature Selection: Identifies key features using shuffling-based ablation impact.

    The framework is model-agnostic and can be applied to a wide range of base models to extract complex patterns while mitigating overfitting and instability.

  9. What is State-Frequency-Memory (SFM)?

    main

    State-Frequency-Memory (SFM) is a recurrent network architecture designed for stock price prediction. It utilizes the Discrete Fourier Transform (DFT) to decompose the hidden states of memory cells. This allows the model to capture multi-frequency trading patterns from historical market data, which are then used to predict future stock prices.

    For more details on the underlying theory, refer to the paper: Stock Price Prediction via Discovering Multi-Frequency Trading Patterns.

  10. Understand the Qlib Data Workflow

    main

    The Qlib Data Layer is designed for high-performance quantitative investment tasks. A typical workflow follows these stages:

    1. Data Preparation: Download raw data and convert it into Qlib format (files with the .bin suffix). At this stage, only basic data like OHLCV (Open, High, Low, Close, Volume) is typically stored.
    2. Feature Engineering (Data Loader): Use Qlib's expression engine to create basic features (e.g., Ref($close, 60) / $close). This is handled by the Data Loader, which is a component of the Data Handler.
    3. Complex Processing (Data Handler): For advanced operations like data normalization that are difficult to express via simple operators, use Data Handler with customized processors.
    4. Dataset Preparation: The Dataset component takes the processed data from the Data Handler and prepares it into a format specific to your machine learning model.