---
name: qlib-quant-research
description: Use when you say "connect Claude to Qlib" or "set up Microsoft's AI quant platform and build one research workflow"; it installs Qlib, prepares the data, and runs its workflow, model and backtest tools with Claude.
---
# Microsoft Qlib quant research with Claude
## What it does
Qlib is an open-source, AI-oriented quantitative investment platform from Microsoft. It covers the full ML pipeline of data processing, model training and back-testing, and the whole chain of quant investment: alpha seeking, risk modeling, portfolio optimization and order execution.
It supports three modeling paradigms:
- Supervised learning, with a model zoo of over twenty models you can run from config files: XGBoost, LightGBM, CatBoost, MLP, LSTM, GRU, ALSTM, GATs, SFM, TFT, TabNet, DoubleEnsemble, TCTS, Transformer, Localformer, TRA, TCN, ADARNN, ADD, IGMTF, HIST, KRNN, Sandwich.
- Market dynamics modeling, with rolling retraining and DDG-DA.
- Reinforcement learning, with order execution examples (TWAP, PPO, OPDS).
Other parts: `qrun` to run a whole workflow (dataset, training, backtest, evaluation) from one YAML config; `workflow_by_code` for a custom workflow in Python; `run_all_model.py` to run one or many models; the Alpha158 and Alpha360 dataset handlers; a data health check script; graphical report analysis (cumulative return, IC, auto-correlation, backtest report); offline and online data server modes. Qlib is also equipped with RD-Agent (https://github.com/microsoft/RD-Agent) to automate the R&D process, including factor mining and model optimization.
This is research tooling. It is not financial advice. Keep to backtests on historical data; the README's workflows do not place real orders.
## What you need
- Python 3.8 to 3.12. Conda is suggested for managing the environment.
- Linux, Windows or macOS. `run_all_model.py` only supports Linux for now.
- On a Mac with M1, install OpenMP first with `brew install libomp` if the LightGBM wheel fails to build.
- Market data. The official dataset is disabled temporarily due to a stricter data security policy; the README points to a community data source at https://github.com/chenditc/investment_data/releases.
- Each model baseline has its own dependencies in its `requirements.txt` (for example TFT only supports Python 3.6 to 3.7 because of `tensorflow==1.15.0`).
## Setup
Install the stable release:
```bash
pip install pyqlib
```
Or install the development version from source:
```bash
pip install numpy
pip install --upgrade cython
git clone https://github.com/microsoft/qlib.git && cd qlib
pip install .
```
Get data. The community dataset the README links to:
```bash
wget https://github.com/chenditc/investment_data/releases/latest/download/qlib_bin.tar.gz
mkdir -p ~/.qlib/qlib_data/cn_data
tar -zxvf qlib_bin.tar.gz -C ~/.qlib/qlib_data/cn_data --strip-components=1
```
Or with Qlib's own data module:
```bash
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
python -m qlib.cli.data qlib_data --target_dir ~/.qlib/qlib_data/cn_data_1min --region cn --interval 1min
```
Check the data:
```bash
python scripts/check_data_health.py check_data --qlib_dir ~/.qlib/qlib_data/cn_data
```
Run one full workflow:
```bash
cd examples
qrun benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
```
For the graphical reports:
```bash
python -m pip install .[analysis]
```
Then open `examples/workflow_by_code.ipynb` with `jupyter notebook`.
Note on saved artifacts: new source builds restrict recorder loads by default. If you reload saved models or datasets, resume online or delayed training, or use DDG-DA, verify the artifact writer and storage permissions before opting in with `trusted=True` (CLI: `--trusted=True`). Fresh in-memory training needs no opt-in. Read the migration guide first: https://qlib.readthedocs.io/en/latest/start/artifact_migration.html
Docs: https://qlib.readthedocs.io/en/latest/
The bundled dataset is built from public data collected by the crawler scripts in `scripts/data_collector/`, sourced from Yahoo Finance, and may not be perfect. Use any collector only on data you are allowed to collect and within the source site's terms; prepare your own data if you have a better set.
## How to use it with Claude
- "Read the Qlib docs at qlib.readthedocs.io and set up one research workflow for me end to end."
- "Run qrun on examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml and explain the excess return, information ratio and max drawdown it prints."
- "Copy examples/workflow_by_code.py and change it into my own workflow with the Alpha360 handler."
- "Use run_all_model.py to run lightgbm and xgboost, then compare their IC and backtest results."
- "Explain the difference between rolling retraining and DDG-DA in examples/benchmarks_dynamic and which one fits my data."
- "Walk me through the RL order execution example and the TWAP, PPO and OPDS configs."
- "Check my data health with scripts/check_data_health.py and tell me what the warnings mean."
## Credits
Made by microsoft (Qlib), packaged by Orbit. Source: https://github.com/microsoft/qlib, license: MIT.