Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qlib RL framework (stage 1) - single-asset order execution #1076

Merged
merged 105 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
f09af43
rl init
ultmaster Feb 28, 2022
65e775e
aux info
ultmaster Feb 28, 2022
f761e35
Reward config
ultmaster Mar 1, 2022
78f6662
update
ultmaster Mar 1, 2022
0eaea69
simple
ultmaster Mar 2, 2022
cb6dd9b
update saoe init
ultmaster Mar 2, 2022
7ae01ea
update simulator and seed
ultmaster Mar 15, 2022
7693bed
minor
ultmaster Mar 21, 2022
2613919
minor
ultmaster Mar 22, 2022
3a88e61
update sim
ultmaster Mar 25, 2022
7a79b7f
checkpoint
ultmaster Mar 25, 2022
c5fd45c
obs
ultmaster Mar 29, 2022
f86e664
Update interpreter
ultmaster Mar 29, 2022
736993a
init qlib simulator
ultmaster Mar 29, 2022
ac57fa0
checkpoint
ultmaster Apr 1, 2022
fd3a9b3
Refine codebase
ultmaster Apr 19, 2022
fe17bb3
Merge branch 'main' of https://github.com/microsoft/qlib into rl-simple
ultmaster Apr 19, 2022
2bfb979
checkpoint
ultmaster Apr 19, 2022
587dd70
checkpoint
ultmaster Apr 20, 2022
80e8181
Add one test
ultmaster Apr 20, 2022
f915aa8
More tests
ultmaster Apr 20, 2022
71ddc95
Simulator checkpoint
ultmaster Apr 21, 2022
d41c68f
checkpoint
ultmaster Apr 21, 2022
99fa4f0
First-step tested
ultmaster Apr 22, 2022
f245ab8
Checkpoint
ultmaster Apr 22, 2022
e035f3b
Update data_queue API
ultmaster Apr 22, 2022
0d3055b
Checkpoint
ultmaster Apr 22, 2022
0848b15
Update test
ultmaster Apr 22, 2022
4b89907
Move files
ultmaster Apr 23, 2022
b1997cc
Checkpoint
ultmaster Apr 23, 2022
bd80eec
Single-quote -> double-quote
ultmaster Apr 23, 2022
d7a2b78
Fix finite env tests
ultmaster Apr 23, 2022
9a31e49
Tested with mypy
ultmaster Apr 24, 2022
eb162d1
pep-574
ultmaster Apr 24, 2022
c01e161
No call for env done
ultmaster Apr 24, 2022
9a05916
Update finite env docs
ultmaster Apr 25, 2022
14ef3de
Fix csv writer
ultmaster Apr 25, 2022
924b2c4
Refine tester
ultmaster Apr 25, 2022
79384ae
Update logger
ultmaster Apr 25, 2022
d9124c7
Add another logger test
ultmaster Apr 25, 2022
18b29da
Checkpoint
ultmaster Apr 25, 2022
40951ba
Add network sanity test
ultmaster Apr 25, 2022
32fd1ce
steps per episode is not correct
ultmaster Apr 25, 2022
be31192
Cleanup code, ready for PR
ultmaster Apr 25, 2022
c2795d2
Merge branch 'main' of https://github.com/microsoft/qlib into rl-simple
ultmaster Apr 25, 2022
3a92b56
Reformat with black
ultmaster Apr 25, 2022
d9bc048
Fix pylint for py37
ultmaster Apr 25, 2022
bf9973a
Fix lint
ultmaster Apr 25, 2022
6d11d45
Fix lint
ultmaster Apr 25, 2022
9db85a1
Fix flake
ultmaster Apr 25, 2022
40b40a5
update mypy command
ultmaster Apr 25, 2022
80f4db7
mypy
ultmaster Apr 25, 2022
571b262
Update exclude pattern
ultmaster Apr 25, 2022
c69e70d
Use pyproject.toml
ultmaster Apr 25, 2022
d2e6758
test
ultmaster Apr 25, 2022
a45e217
.
ultmaster Apr 25, 2022
303025e
.
ultmaster Apr 25, 2022
424b164
Refactor pipeline
ultmaster Apr 26, 2022
29e4ab9
.
ultmaster Apr 26, 2022
0caf2c5
defaults run bash
ultmaster Apr 26, 2022
3dc1b73
.
ultmaster Apr 26, 2022
4f24094
Revert and skip follow_imports
ultmaster Apr 26, 2022
fb930a0
Fix toml issue
ultmaster Apr 26, 2022
61faf62
fix mypy
ultmaster Apr 26, 2022
f9d6d2f
.
ultmaster Apr 26, 2022
fcc5592
.
ultmaster Apr 26, 2022
2821ab3
.
ultmaster Apr 26, 2022
9c19c74
Fix install
ultmaster Apr 26, 2022
7ba3653
Minor fix
ultmaster May 6, 2022
54ee6c0
Fix test
ultmaster May 7, 2022
a6e01c0
Fix test
ultmaster May 7, 2022
b27daa6
Merge branch 'main' of https://github.com/microsoft/qlib into rl-simple
ultmaster May 7, 2022
e5a5381
Remove requirements
ultmaster May 7, 2022
354d4c9
Revert
ultmaster May 7, 2022
5e481f0
fix tests
ultmaster May 7, 2022
508e407
Fix lint
ultmaster May 7, 2022
60f8703
.
ultmaster May 7, 2022
e22f9e8
.
ultmaster May 7, 2022
a951cc9
.
ultmaster May 7, 2022
b4815e6
.
ultmaster May 7, 2022
9fe59a3
.
ultmaster May 7, 2022
f37f526
update install from source command
ultmaster May 7, 2022
4c4c0b6
.
ultmaster May 7, 2022
fb8cd1d
Fix data download
ultmaster May 7, 2022
0c17122
.
ultmaster May 7, 2022
06769dc
.
ultmaster May 8, 2022
37e8e37
.
ultmaster May 8, 2022
bae7c9f
.
ultmaster May 8, 2022
33cf405
.
ultmaster May 8, 2022
4ffd5c9
.
ultmaster May 8, 2022
aba6640
Fix py37
ultmaster May 8, 2022
a27f338
Ignore tests on non-linux
ultmaster May 8, 2022
6be74a6
resolve comments
ultmaster May 12, 2022
2958c77
fix tests
ultmaster May 12, 2022
38bcf7e
resolve comments
ultmaster May 13, 2022
267cb67
some typo
you-n-g May 15, 2022
4063f78
style updates
ultmaster May 16, 2022
daa510f
More comments
ultmaster May 16, 2022
60157a9
fix dummy
ultmaster May 16, 2022
68a88bb
add warning
ultmaster May 18, 2022
25a26c0
Align precision in some system
you-n-g May 19, 2022
a3ece1c
Merge pull request #2 from you-n-g/rl-simple
ultmaster May 20, 2022
6292958
Added some impl notes
ultmaster May 20, 2022
d649c2e
Merge branch 'rl-simple' of github.com:ultmaster/qlib into rl-simple
ultmaster May 20, 2022
5da6adb
Merge pull request #1 from you-n-g/rl-simple-typo
ultmaster May 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
pip install numpy==1.19.5 ruamel.yaml
pip install pyqlib --ignore-installed

- name: Make html with sphnix
- name: Make html with sphinx
run: |
pip install -U sphinx
pip install sphinx_rtd_theme readthedocs_sphinx_ext
Expand Down Expand Up @@ -97,12 +97,21 @@ jobs:
run: |
pip install --upgrade pip
pip install flake8
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 qlib
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 --per-file-ignores="__init__.py:F401,F403" qlib

# https://github.com/python/mypy/issues/10600
- name: Check Qlib with mypy
run: |
pip install mypy
mypy qlib --install-types --non-interactive || true
mypy qlib

- name: Test data downloads
run: |
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data_simple --interval 1d --region cn
python -c "import os; userpath=os.path.expanduser('~'); os.rename(userpath + '/.qlib/qlib_data/cn_data_simple', userpath + '/.qlib/qlib_data/cn_data')"
azcopy copy https://qlibpublic.blob.core.windows.net/data /tmp/qlibpublic --recursive
mv /tmp/qlibpublic/data tests/.data

- name: Test workflow by config (install from pip)
run: |
Expand All @@ -113,6 +122,7 @@ jobs:
- name: Install Qlib from source
run: |
pip install --upgrade cython jupyter jupyter_contrib_nbextensions numpy scipy scikit-learn # installing without this line will cause errors on GitHub Actions, while instsalling locally won't
pip install gym tianshou torch
pip install -e .

- name: Install test dependencies
Expand All @@ -129,4 +139,3 @@ jobs:
- name: Test workflow by config (install from source)
run: |
python qlib/workflow/cli.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml

5 changes: 4 additions & 1 deletion .github/workflows/test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
pip install --upgrade pip
pip install flake8
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 qlib
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 --per-file-ignores="__init__.py:F401,F403" qlib

- name: Install Qlib with pip
run: |
Expand All @@ -65,6 +65,8 @@ jobs:
run: |
python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data_simple --interval 1d --region cn
python -c "import os; userpath=os.path.expanduser('~'); os.rename(userpath + '/.qlib/qlib_data/cn_data_simple', userpath + '/.qlib/qlib_data/cn_data')"
azcopy copy https://qlibpublic.blob.core.windows.net/data /tmp/qlibpublic --recursive
mv /tmp/qlibpublic/data tests/.data
- name: Test workflow by config (install from pip)
run: |
python qlib/workflow/cli.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
Expand All @@ -75,6 +77,7 @@ jobs:
python -m pip install --upgrade cython
python -m pip install numpy jupyter jupyter_contrib_nbextensions
python -m pip install -U scipy scikit-learn # installing without this line will cause errors on GitHub Actions, while instsalling locally won't
python -m pip install gym tianshou torch
pip install -e .
- name: Install test dependencies
run: |
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ examples/estimator/estimator_example/

*.egg-info/

# test related
test-output.xml
.output
.data

# special software
mlruns/

tags

.pytest_cache/
.mypy_cache/
.vscode/

*.swp
Expand Down
17 changes: 17 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[mypy]
exclude = (?x)(
^qlib/backtest
| ^qlib/contrib
| ^qlib/data
| ^qlib/model
| ^qlib/strategy
| ^qlib/tests
| ^qlib/utils
| ^qlib/workflow
| ^qlib/config\.py$
| ^qlib/log\.py$
| ^qlib/__init__\.py$
)
ignore_missing_imports = true
disallow_incomplete_defs = true
follow_imports = skip
3 changes: 3 additions & 0 deletions qlib/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@

# Epsilon for avoiding division by zero.
EPS = 1e-12

# Infinity in integer
INF = 10**18
6 changes: 5 additions & 1 deletion qlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def get_module_logger(module_name, level: Optional[int] = None) -> QlibLogger:
if level is None:
level = C.logging_level

module_name = "qlib.{}".format(module_name)
if not module_name.startswith("qlib."):
# Add a prefix of qlib. when the requested ``module_name`` doesn't start with ``qlib.``.
# If the module_name is already qlib.xxx, we do not format here. Otherwise, it will become qlib.qlib.xxx.
module_name = "qlib.{}".format(module_name)
ultmaster marked this conversation as resolved.
Show resolved Hide resolved

# Get logger.
module_logger = QlibLogger(module_name)
module_logger.setLevel(level)
Expand Down
43 changes: 43 additions & 0 deletions qlib/rl/aux_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from __future__ import annotations

from typing import Generic, TYPE_CHECKING, TypeVar

from qlib.typehint import final

from .simulator import StateType

if TYPE_CHECKING:
from .utils.env_wrapper import EnvWrapper


__all__ = ["AuxiliaryInfoCollector"]

AuxInfoType = TypeVar("AuxInfoType")


class AuxiliaryInfoCollector(Generic[StateType, AuxInfoType]):
"""Override this class to collect customized auxiliary information from environment."""

env: EnvWrapper | None = None

@final
def __call__(self, simulator_state: StateType) -> AuxInfoType:
return self.collect(simulator_state)

def collect(self, simulator_state: StateType) -> AuxInfoType:
"""Override this for customized auxiliary info.
Usually useful in Multi-agent RL.

Parameters
----------
simulator_state
Retrieved with ``simulator.get_state()``.

Returns
-------
Auxiliary information.
"""
raise NotImplementedError("collect is not implemented!")
8 changes: 8 additions & 0 deletions qlib/rl/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""Common utilities to handle ad-hoc-styled data.
ultmaster marked this conversation as resolved.
Show resolved Hide resolved

Most of these snippets comes from research project (paper code).
Please take caution when using them in production.
"""
Loading