Actively developed

Qlib guide

Qlib frames trading research as a machine-learning pipeline: data, features, models, portfolio and evaluation.

Last reviewed · Also known as pyqlib, Microsoft Qlib, RD-Agent

Quick answer

Qlib is Microsoft’s open-source, AI-oriented quantitative investment platform. It provides a fast data layer and expression engine for factors (such as the Alpha158 set), a model zoo from LightGBM to LSTMs and Transformers, a backtesting and portfolio-strategy layer, and YAML workflows that run end to end. RD-Agent builds on it to automate factor and model research with LLMs.

Qlib at a glance

Category
Machine learning & AI
Language
Python
License
MIT
Does
Machine learning, Backtesting, Market data, Performance analytics
Markets
Stocks
Best for
Cross-sectional stock prediction with machine learning at research scale.
In AlgoGP
Use the exported strategy object from your own code

Pick it if

Cross-sectional stock prediction with machine learning at research scale.

Watch out for

Built around daily cross-sectional equity data (China and US datasets).

Qlib strengths and limitations

Strengths

  • Complete ML research pipeline.
  • Strong baselines and benchmarks.
  • Backed by Microsoft Research.

Limitations

  • Built around daily cross-sectional equity data (China and US datasets).
  • Not a live-trading engine.

Qlib example

pip install pyqlib
Install
pip install pyqlib
python -m qlib.run.get_data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
qrun examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
Run a LightGBM benchmark workflow.

Use Qlib with AlgoGP

AlgoGP does not add Qlib to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from Qlib yourself.

  1. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from Qlib

    Feed Qlib’s bars to StrategyBridge, place the returned orders with Qlib, and report fills back with sync().

Qlib connects to Yahoo Finance. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.

Qlib: frequently asked questions

Can Qlib trade live?

It focuses on research and simulation; signals are exported to an execution system.

Qlib alternatives

Independent guide. AlgoGP is not affiliated with Qlib. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy