Skip to main content

A Quantitative-research Platform

Project description

Python Versions Platform PypI Versions Upload Python Package Github Actions Test Status Documentation Status License Join the chat at https://gitter.im/Microsoft/qlib

Qlib is an AI-oriented quantitative investment platform, which aims to realize the potential, empower the research, and create the value of AI technologies in quantitative investment.

It contains the full ML pipeline of data processing, model training, back-testing; and covers the entire chain of quantitative investment: alpha seeking, risk modeling, portfolio optimization, and order execution.

With Qlib, user can easily try ideas to create better Quant investment strategies.

For more details, please refer to our paper "Qlib: An AI-oriented Quantitative Investment Platform".

Framework of Qlib

At the module level, Qlib is a platform that consists of the above components. The components are designed as loose-coupled modules and each component could be used stand-alone.

Name Description
Infrastructure layer Infrastructure layer provides underlying support for Quant research. DataServer provides high-performance infrastructure for users to manage and retrieve raw data. Trainer provides flexible interface to control the training process of models which enable algorithms controlling the training process.
Workflow layer Workflow layer covers the whole workflow of quantitative investment. Information Extractor extracts data for models. Forecast Model focuses on producing all kinds of forecast signals (e.g. alpha, risk) for other modules. With these signals Portfolio Generator will generate the target portfolio and produce orders to be executed by Order Executor.
Interface layer Interface layer tries to present a user-friendly interface for the underlying system. Analyser module will provide users detailed analysis reports of forecasting signals, portfolios and execution results
  • The modules with hand-drawn style are under development and will be released in the future.
  • The modules with dashed borders are highly user-customizable and extendible.

Quick Start

This quick start guide tries to demonstrate

  1. It's very easy to build a complete Quant research workflow and try your ideas with Qlib.
  2. Though with public data and simple models, machine learning technologies work very well in practical Quant investment.

Installation

Users can easily install Qlib by pip according to the following command

  pip install pyqlib

Also, users can install Qlib by the source code according to the following steps:

  • Before installing Qlib from source, users need to install some dependencies:

    pip install numpy
    pip install --upgrade  cython
    
  • Clone the repository and install Qlib:

    git clone https://github.com/microsoft/qlib.git && cd qlib
    python setup.py install
    

Data Preparation

Load and prepare data by running the following code:

python scripts/get_data.py qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn

This dataset is created by public data collected by crawler scripts, which have been released in the same repository. Users could create the same dataset with it.

Please pay ATTENTION that the data is collected from Yahoo Finance and the data might not be perfect. We recommend users to prepare their own data if they have high-quality dataset. For more information, users can refer to the related document.

Auto Quant Research Workflow

Qlib provides a tool named qrun to run the whole workflow automatically (including building dataset, training models, backtest and evaluation). You can start an auto quant research workflow and have a graphical reports analysis according to the following steps:

  1. Quant Research Workflow: Run qrun with lightgbm workflow config (workflow_config_lightgbm.yaml) as following.

      cd examples  # Avoid running program under the directory contains `qlib`
      qrun benchmarks/LightGBM/workflow_config_lightgbm.yaml
    

    The result of qrun is as follows, please refer to please refer to Intraday Trading for more details about the result.

    'The following are analysis results of the excess return without cost.'
                           risk
    mean               0.000708
    std                0.005626
    annualized_return  0.178316
    information_ratio  1.996555
    max_drawdown      -0.081806
    'The following are analysis results of the excess return with cost.'
                           risk
    mean               0.000512
    std                0.005626
    annualized_return  0.128982
    information_ratio  1.444287
    max_drawdown      -0.091078
    

    Here are detailed documents for qrun and workflow.

  2. Graphical Reports Analysis: Run examples/workflow_by_code.ipynb with jupyter notebook to get graphical reports

    • Forecasting signal (model prediction) analysis

      • Cumulative Return of groups Cumulative Return
      • Return distribution long_short
      • Information Coefficient (IC) Information Coefficient
        Monthly IC IC
      • Auto Correlation of forecasting signal (model prediction) Auto Correlation
    • Portfolio analysis

      • Backtest return Report

Building Customized Quant Research Workflow by Code

The automatic workflow may not suite the research workflow of all Quant researchers. To support a flexible Quant research workflow, Qlib also provides a modularized interface to allow researchers to build their own workflow by code. Here is a demo for customized Quant research workflow by code.

Quant Model Zoo

Here is a list of models built on Qlib.

Your PR of new Quant models is highly welcomed.

Run a single model

All the models listed above are runnable with Qlib. Users can find the config files we provide and some details about the model through the benchmarks folder. More information can be retrieved at the model files listed above.

Qlib provides three different ways to run a single model, users can pick the one that fits their cases best:

  • User can use the tool qrun mentioned above to run a model's workflow based from a config file.

  • User can create a workflow_by_code python script based on the one listed in the examples folder.

  • User can use the script run_all_model.py listed in the examples folder to run a model. Here is an example of the specific shell command to be used: python run_all_model.py --models=lightgbm, where the --models arguments can take any number of models listed above(the available models can be found in benchmarks). For more use cases, please refer to the file's docstrings.

Run multiple models

Qlib also provides a script run_all_model.py which can run multiple models for several iterations. (Note: the script only supprots Linux now. Other OS will be supported in the future.)

The script will create a unique virtual environment for each model, and delete the environments after training. Thus, only experiment results such as IC and backtest results will be generated and stored. (Note: the script will erase your previous experiment records created by running itself.)

Here is an example of running all the models for 10 iterations:

python run_all_model.py 10

It also provides the API to run specific models at once. For more use cases, please refer to the file's docstrings.

Quant Dataset Zoo

Dataset plays a very important role in Quant. Here is a list of the datasets built on Qlib.

Dataset US Market China Market
Alpha360
Alpha158

Here is a tutorial to build dataset with Qlib. Your PR to build new Quant dataset is highly welcomed.

More About Qlib

The detailed documents are organized in docs. Sphinx and the readthedocs theme is required to build the documentation in html formats.

cd docs/
conda install sphinx sphinx_rtd_theme -y
# Otherwise, you can install them with pip
# pip install sphinx sphinx_rtd_theme
make html

You can also view the latest document online directly.

Qlib is in active and continuing development. Our plan is in the roadmap, which is managed as a github project.

Offline Mode and Online Mode

The data server of Qlib can either deployed as Offline mode or Online mode. The default mode is offline mode.

Under Offline mode, the data will be deployed locally.

Under Online mode, the data will be deployed as a shared data service. The data and their cache will be shared by all the clients. The data retrieval performance is expected to be improved due to a higher rate of cache hits. It will consume less disk space, too. The documents of the online mode can be found in Qlib-Server. The online mode can be deployed automatically with Azure CLI based scripts. The source code of online data server can be found in Qlib-Server repository.

Performance of Qlib Data Server

The performance of data processing is important to data-driven methods like AI technologies. As an AI-oriented platform, Qlib provides a solution for data storage and data processing. To demonstrate the performance of Qlib data server, we compare it with several other data storage solutions.

We evaluate the performance of several storage solutions by finishing the same task, which creates a dataset (14 features/factors) from the basic OHLCV daily data of a stock market (800 stocks each day from 2007 to 2020). The task involves data queries and processing.

HDF5 MySQL MongoDB InfluxDB Qlib -E -D Qlib +E -D Qlib +E +D
Total (1CPU) (seconds) 184.4±3.7 365.3±7.5 253.6±6.7 368.2±3.6 147.0±8.8 47.6±1.0 7.4±0.3
Total (64CPU) (seconds) 8.8±0.6 4.2±0.2
  • +(-)E indicates with (out) ExpressionCache
  • +(-)D indicates with (out) DatasetCache

Most general-purpose databases take too much time on loading data. After looking into the underlying implementation, we find that data go through too many layers of interfaces and unnecessary format transformations in general-purpose database solutions. Such overheads greatly slow down the data loading process. Qlib data are stored in a compact format, which is efficient to be combined into arrays for scientific computation.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the right to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pyqlib-0.6.0-cp38-cp38-win_amd64.whl (268.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyqlib-0.6.0-cp38-cp38-manylinux2010_x86_64.whl (663.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyqlib-0.6.0-cp38-cp38-manylinux1_x86_64.whl (663.2 kB view details)

Uploaded CPython 3.8

pyqlib-0.6.0-cp38-cp38-macosx_10_14_x86_64.whl (260.2 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

pyqlib-0.6.0-cp37-cp37m-win_amd64.whl (266.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

pyqlib-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl (626.5 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pyqlib-0.6.0-cp37-cp37m-manylinux1_x86_64.whl (626.5 kB view details)

Uploaded CPython 3.7m

pyqlib-0.6.0-cp37-cp37m-macosx_10_14_x86_64.whl (259.6 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

pyqlib-0.6.0-cp36-cp36m-win_amd64.whl (266.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

pyqlib-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl (623.5 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pyqlib-0.6.0-cp36-cp36m-manylinux1_x86_64.whl (623.5 kB view details)

Uploaded CPython 3.6m

pyqlib-0.6.0-cp36-cp36m-macosx_10_14_x86_64.whl (260.9 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

Details for the file pyqlib-0.6.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 268.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for pyqlib-0.6.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d03dff98ce03b49b4355eefa1da628a0c26feeefaf85c1c1357294d648331cd3
MD5 9d4b4c6523bdf287f97673510fc54bb5
BLAKE2b-256 b875bb3c206230369b91a128eb3512c7e8ca18fce5cbbb34b116e75fa7796a57

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 663.2 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b551f434e2a0e95fd18efe8a16a35827e7c83208b6ee84b5e54c24c4a5743423
MD5 b108954e255add96a78ba90fb3f28ad0
BLAKE2b-256 bf8e7db54361fd904395f8105c9d9608f09165cd7c964e07538c493899bce5d0

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 663.2 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c4ef585dd0ed242d8fbec04b5c451c3bb2951b74a0cb57082232d325e1f7c5ae
MD5 60efb4194462058f2f8a59c2731d70f5
BLAKE2b-256 8fbe77ddd3d402ad9888b63638394d063d8c671f8c7e3428210453293d270265

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 260.2 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for pyqlib-0.6.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 43df4307e37e4f41e24f5dce08f1c0b847aa7e5f062dfe78dbbc0d25a93cbad3
MD5 a7e82fe15a42b302968e7d798cc1d2c3
BLAKE2b-256 8acb24887926c83db58454af19f7ee84db08f0bdcc38c360fd19a0f7ee81c167

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 266.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 7b8dbd8550ed1b5a6bcc33b72c749cf9ddfccfcf9d0530b3c8c76e4e265533f8
MD5 c24b2a69060055b6797e8324a85457b4
BLAKE2b-256 cb53c2a3ba648d967373fc081ea2047c53fc74dd8d9e2746d4e60854999461e4

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 626.5 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 43acbe5fb3172baa8babf39f0b8602c46744e3e4dd67f7befdf28a6d575e4606
MD5 022bea77823cafbeb74670a11b444e48
BLAKE2b-256 66b740d8ea1c84cc0e0b50fd7b7529cf58bf47d4e7000f11917e18769a69d8df

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 626.5 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c480600027cc7a3c6f37d03fa4f03639a8f4b050172701ffc40c26da8d164db3
MD5 d4e562fa7fff1ee475a3f373d3d412b2
BLAKE2b-256 42d72e61ab2897793cc20fdfe5dda53c734743647c69f2f9597b68d9d72822c0

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 259.6 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a7b092284c98af1690db1efe7374b6d3a5703bb338dc655aa2110974593a888d
MD5 84543e01f660de739f8e30b73c4fe030
BLAKE2b-256 29dd874362dd958f3e5086391f66fc1055ca16f7952a86ec83b3b41b44e58174

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 266.6 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.8

File hashes

Hashes for pyqlib-0.6.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 be703b880f227c699be056f4f5bb6e80f97f087b57d93e6a290f4671d49320fc
MD5 c198e088b9073ee09aa6f9b21fc01046
BLAKE2b-256 b3e0e48a138dcafd1f102cbc5c64915549982439f8f695c79a24bdb48c36d23e

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 623.5 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0ebe9f00d953678c8f4c0628501f40acf5d14de9ff08b2cc9ccf5b378f286b21
MD5 c6cede8f0e7a6a4062338281d7b3edee
BLAKE2b-256 9fc227ecf2e3cab6bd032528f343f9c5ecacb7e2297a169cffff75852fa77262

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 623.5 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for pyqlib-0.6.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7bb27f7eff67eba0f227242f6e4b2a708e95d68dbd6262c420f08dbd04184ceb
MD5 f936a38f55a82a5d7a7e54589fb52cc0
BLAKE2b-256 bb30a2cf0e59d799908d31ae4a073e51b3be401ddb461d91266dc6916e389299

See more details on using hashes here.

File details

Details for the file pyqlib-0.6.0-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyqlib-0.6.0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 260.9 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.12

File hashes

Hashes for pyqlib-0.6.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ab03075eb62cde59b3349e5eb7b5b7fbfa30a1427d48219995e4666f562becc9
MD5 1246db27d8fcf4dd143bd98357d1065f
BLAKE2b-256 efef37caa2dfdc1f939cebca6ed2e86563a1437a511735df3fcc73e4e9611d36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page