Skip to content

Commit 60ecca3

Browse files
committed
Merge branch 'AdjustRollingAPI' into finco
2 parents effed38 + d39e539 commit 60ecca3

File tree

167 files changed

+2475
-1097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+2475
-1097
lines changed

.github/release-drafter.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ categories:
1414
label:
1515
- 'doc'
1616
- 'documentation'
17+
- title: '🧹 Maintenance'
18+
label:
19+
- 'maintenance'
1720
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
1821
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
1922
version-resolver:
@@ -30,4 +33,4 @@ version-resolver:
3033
template: |
3134
## Changes
3235
33-
$CHANGES
36+
$CHANGES

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
3939
run: |
4040
twine upload dist/*
41-
41+
4242
deploy_with_manylinux:
4343
runs-on: ubuntu-latest
4444
steps:

.github/workflows/test_qlib_from_pip.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
build:
11+
if: ${{ false }} # FIXME: temporarily disable... Due to we are rushing a feature
1112
timeout-minutes: 120
1213

1314
runs-on: ${{ matrix.os }}
@@ -19,10 +20,20 @@ jobs:
1920

2021
steps:
2122
- name: Test qlib from pip
22-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2324

25+
# Since version 3.7 of python for MacOS is installed in CI, version 3.7.17, this version causes "_bz not found error".
26+
# So we make the version number of python 3.7 for MacOS more specific.
27+
# refs: https://github.com/actions/setup-python/issues/682
2428
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v2
29+
if: (matrix.os == 'macos-latest' && matrix.python-version == '3.7') || (matrix.os == 'macos-11' && matrix.python-version == '3.7')
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: "3.7.16"
33+
34+
- name: Set up Python ${{ matrix.python-version }}
35+
if: (matrix.os != 'macos-latest' || matrix.python-version != '3.7') && (matrix.os != 'macos-11' || matrix.python-version != '3.7')
36+
uses: actions/setup-python@v4
2637
with:
2738
python-version: ${{ matrix.python-version }}
2839

@@ -50,7 +61,9 @@ jobs:
5061
5162
- name: Downloads dependencies data
5263
run: |
53-
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
64+
cd ..
65+
python -m qlib.run.get_data qlib_data --target_dir ~/.qlib/qlib_data/cn_data --region cn
66+
cd qlib
5467
5568
- name: Test workflow by config
5669
run: |

.github/workflows/test_qlib_from_source.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@ jobs:
2020

2121
steps:
2222
- name: Test qlib from source
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2424

25+
# Since version 3.7 of python for MacOS is installed in CI, version 3.7.17, this version causes "_bz not found error".
26+
# So we make the version number of python 3.7 for MacOS more specific.
27+
# refs: https://github.com/actions/setup-python/issues/682
2528
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
29+
if: (matrix.os == 'macos-latest' && matrix.python-version == '3.7') || (matrix.os == 'macos-11' && matrix.python-version == '3.7')
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: "3.7.16"
33+
34+
- name: Set up Python ${{ matrix.python-version }}
35+
if: (matrix.os != 'macos-latest' || matrix.python-version != '3.7') && (matrix.os != 'macos-11' || matrix.python-version != '3.7')
36+
uses: actions/setup-python@v4
2737
with:
2838
python-version: ${{ matrix.python-version }}
2939

3040
- name: Update pip to the latest version
3141
# pip release version 23.1 on Apr.15 2023, CI failed to run, Please refer to #1495 ofr detailed logs.
32-
# The pip version has been temporarily fixed to 23.0.1
42+
# The pip version has been temporarily fixed to 23.0
3343
run: |
34-
python -m pip install pip==23.0.1
44+
python -m pip install pip==23.0
3545
3646
- name: Installing pytorch for macos
3747
if: ${{ matrix.os == 'macos-11' || matrix.os == 'macos-latest' }}
@@ -54,7 +64,10 @@ jobs:
5464
python -m pip install -e .[dev]
5565
5666
- name: Lint with Black
67+
# Python 3.7 will use a black with low level. So we use python with higher version for black check
68+
if: (matrix.python-version != '3.7')
5769
run: |
70+
pip install -U black # follow the latest version of black, previous Qlib dependency will downgrade black
5871
black . -l 120 --check --diff
5972
6073
- name: Make html with sphinx
@@ -129,8 +142,7 @@ jobs:
129142
- name: Test data downloads
130143
run: |
131144
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
132-
azcopy copy https://qlibpublic.blob.core.windows.net/data/rl /tmp/qlibpublic/data --recursive
133-
mv /tmp/qlibpublic/data tests/.data
145+
python scripts/get_data.py download_data --file_name rl_data.zip --target_dir tests/.data/rl
134146
135147
- name: Install Lightgbm for MacOS
136148
if: ${{ matrix.os == 'macos-11' || matrix.os == 'macos-latest' }}

.github/workflows/test_qlib_from_source_slow.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@ jobs:
2020

2121
steps:
2222
- name: Test qlib from source slow
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2424

25+
# Since version 3.7 of python for MacOS is installed in CI, version 3.7.17, this version causes "_bz not found error".
26+
# So we make the version number of python 3.7 for MacOS more specific.
27+
# refs: https://github.com/actions/setup-python/issues/682
2528
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
29+
if: (matrix.os == 'macos-latest' && matrix.python-version == '3.7') || (matrix.os == 'macos-11' && matrix.python-version == '3.7')
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: "3.7.16"
33+
34+
- name: Set up Python ${{ matrix.python-version }}
35+
if: (matrix.os != 'macos-latest' || matrix.python-version != '3.7') && (matrix.os != 'macos-11' || matrix.python-version != '3.7')
36+
uses: actions/setup-python@v4
2737
with:
2838
python-version: ${{ matrix.python-version }}
2939

3040
- name: Set up Python tools
3141
# pip release version 23.1 on Apr.15 2023, CI failed to run, Please refer to #1495 ofr detailed logs.
32-
# The pip version has been temporarily fixed to 23.0.1
42+
# The pip version has been temporarily fixed to 23.0
3343
run: |
34-
python -m pip install pip==23.0.1
44+
python -m pip install pip==23.0
3545
pip install --upgrade cython numpy
3646
pip install -e .[dev]
3747

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 22.6.0
3+
rev: 23.7.0
44
hooks:
55
- id: black
66
args: ["qlib", "-l 120"]
@@ -9,4 +9,4 @@ repos:
99
rev: 4.0.1
1010
hooks:
1111
- id: flake8
12-
args: ["--ignore=E501,F541,E266,E402,W503,E731,E203"]
12+
args: ["--ignore=E501,F541,E266,E402,W503,E731,E203"]

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Recent released features
1212
| Feature | Status |
1313
| -- | ------ |
14+
| KRNN and Sandwich models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1414/) on May 26, 2023 |
1415
| Release Qlib v0.9.0 | :octocat: [Released](https://github.com/microsoft/qlib/releases/tag/v0.9.0) on Dec 9, 2022 |
1516
| RL Learning Framework | :hammer: :chart_with_upwards_trend: Released on Nov 10, 2022. [#1332](https://github.com/microsoft/qlib/pull/1332), [#1322](https://github.com/microsoft/qlib/pull/1322), [#1316](https://github.com/microsoft/qlib/pull/1316),[#1299](https://github.com/microsoft/qlib/pull/1299),[#1263](https://github.com/microsoft/qlib/pull/1263), [#1244](https://github.com/microsoft/qlib/pull/1244), [#1169](https://github.com/microsoft/qlib/pull/1169), [#1125](https://github.com/microsoft/qlib/pull/1125), [#1076](https://github.com/microsoft/qlib/pull/1076)|
1617
| HIST and IGMTF models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1040) on Apr 10, 2022 |
@@ -90,6 +91,7 @@ For more details, please refer to our paper ["Qlib: An AI-oriented Quantitative
9091
</ul>
9192
</li>
9293
<li type="circle"><a href="#adapting-to-market-dynamics">Adapting to Market Dynamics</a></li>
94+
<li type="circle"><a href="#reinforcement-learning-modeling-continuous-decisions">Reinforcement Learning: modeling continuous decisions</a></li>
9395
</ul>
9496
</li>
9597
</td>
@@ -353,6 +355,8 @@ Here is a list of models built on `Qlib`.
353355
- [ADD based on pytorch (Hongshun Tang, et al.2020)](examples/benchmarks/ADD/)
354356
- [IGMTF based on pytorch (Wentao Xu, et al.2021)](examples/benchmarks/IGMTF/)
355357
- [HIST based on pytorch (Wentao Xu, et al.2021)](examples/benchmarks/HIST/)
358+
- [KRNN based on pytorch](examples/benchmarks/KRNN/)
359+
- [Sandwich based on pytorch](examples/benchmarks/Sandwich/)
356360

357361
Your PR of new Quant models is highly welcomed.
358362

@@ -389,6 +393,17 @@ Here is a list of solutions built on `Qlib`.
389393
- [Rolling Retraining](examples/benchmarks_dynamic/baseline/)
390394
- [DDG-DA on pytorch (Wendi, et al. AAAI 2022)](examples/benchmarks_dynamic/DDG-DA/)
391395
396+
## Reinforcement Learning: modeling continuous decisions
397+
Qlib now supports reinforcement learning, a feature designed to model continuous investment decisions. This functionality assists investors in optimizing their trading strategies by learning from interactions with the environment to maximize some notion of cumulative reward.
398+
399+
Here is a list of solutions built on `Qlib` categorized by scenarios.
400+
401+
### [RL for order execution](examples/rl_order_execution)
402+
[Here](https://qlib.readthedocs.io/en/latest/component/rl/overall.html#order-execution) is the introduction of this scenario. All the methods below are compared [here](examples/rl_order_execution).
403+
- [TWAP](examples/rl_order_execution/exp_configs/backtest_twap.yml)
404+
- [PPO: "An End-to-End Optimal Trade Execution Framework based on Proximal Policy Optimization", IJCAL 2020](examples/rl_order_execution/exp_configs/backtest_ppo.yml)
405+
- [OPDS: "Universal Trading for Order Execution with Oracle Policy Distillation", AAAI 2021](examples/rl_order_execution/exp_configs/backtest_opds.yml)
406+
392407
# Quant Dataset Zoo
393408
Dataset plays a very important role in Quant. Here is a list of the datasets built on `Qlib`:
394409

docs/component/data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Here are some example:
119119
for daily data:
120120
.. code-block:: bash
121121
122-
python scripts/get_data.py csv_data_cn --target_dir ~/.qlib/csv_data/cn_data
122+
python scripts/get_data.py download_data --file_name csv_data_cn.zip --target_dir ~/.qlib/csv_data/cn_data
123123
124124
for 1min data:
125125
.. code-block:: bash

docs/component/rl/guidance.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
========
3+
Guidance
4+
========
5+
.. currentmodule:: qlib
6+
7+
QlibRL can help users quickly get started and conveniently implement quantitative strategies based on reinforcement learning(RL) algorithms. For different user groups, we recommend the following guidance to use QlibRL.
8+
9+
Beginners to Reinforcement Learning Algorithms
10+
==============================================
11+
Whether you are a quantitative researcher who wants to understand what RL can do in trading or a learner who wants to get started with RL algorithms in trading scenarios, if you have limited knowledge of RL and want to shield various detailed settings to quickly get started with RL algorithms, we recommend the following sequence to learn qlibrl:
12+
- Learn the fundamentals of RL in `part1 <https://qlib.readthedocs.io/en/latest/component/rl/overall.html#reinforcement-learning>`_.
13+
- Understand the trading scenarios where RL methods can be applied in `part2 <https://qlib.readthedocs.io/en/latest/component/rl/overall.html#potential-application-scenarios-in-quantitative-trading>`_.
14+
- Run the examples in `part3 <https://qlib.readthedocs.io/en/latest/component/rl/quickstart.html>`_ to solve trading problems using RL.
15+
- If you want to further explore QlibRL and make some customizations, you need to first understand the framework of QlibRL in `part4 <https://qlib.readthedocs.io/en/latest/component/rl/framework.html>`_ and rewrite specific components according to your needs.
16+
17+
Reinforcement Learning Algorithm Researcher
18+
==============================================
19+
If you are already familiar with existing RL algorithms and dedicated to researching RL algorithms but lack domain knowledge in the financial field, and you want to validate the effectiveness of your algorithms in financial trading scenarios, we recommend the following steps to get started with QlibRL:
20+
- Understand the trading scenarios where RL methods can be applied in `part2 <https://qlib.readthedocs.io/en/latest/component/rl/overall.html#potential-application-scenarios-in-quantitative-trading>`_.
21+
- Choose an RL application scenario (currently, QlibRL has implemented two scenario examples: order execution and algorithmic trading). Run the example in `part3 <https://qlib.readthedocs.io/en/latest/component/rl/quickstart.html>`_ to get it working.
22+
- Modify the `policy <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/policy.py>`_ part to incorporate your own RL algorithm.
23+
24+
Quantitative Researcher
25+
=======================
26+
If you have a certain level of financial domain knowledge and coding skills, and you want to explore the application of RL algorithms in the investment field, we recommend the following steps to explore QlibRL:
27+
- Learn the fundamentals of RL in `part1 <https://qlib.readthedocs.io/en/latest/component/rl/overall.html#reinforcement-learning>`_.
28+
- Understand the trading scenarios where RL methods can be applied in `part2 <https://qlib.readthedocs.io/en/latest/component/rl/overall.html#potential-application-scenarios-in-quantitative-trading>`_.
29+
- Run the examples in `part3 <https://qlib.readthedocs.io/en/latest/component/rl/quickstart.html>`_ to solve trading problems using RL.
30+
- Understand the framework of QlibRL in `part4 <https://qlib.readthedocs.io/en/latest/component/rl/framework.html>`_.
31+
- Choose a suitable RL algorithm based on the characteristics of the problem you want to solve (currently, QlibRL supports PPO and DQN algorithms based on tianshou).
32+
- Design the MDP (Markov Decision Process) process based on market trading rules and the problem you want to solve. Refer to the example in order execution and make corresponding modifications to the following modules: `State <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/state.py#L70>`_, `Metrics <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/state.py#L18>`_, `ActionInterpreter <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/interpreter.py#L199>`_, `StateInterpreter <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/interpreter.py#L68>`_, `Reward <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/reward.py>`_, `Observation <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/interpreter.py#L44>`_, `Simulator <https://github.com/microsoft/qlib/blob/main/qlib/rl/order_execution/simulator_simple.py>`_.

0 commit comments

Comments
 (0)