Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
04b916c
safe yaml loader
you-n-g Feb 16, 2021
83237ba
yml afe load
you-n-g Feb 17, 2021
1e5cf1c
init version of online serving and rolling
you-n-g Feb 26, 2021
24024d5
qlib auto init basedon project & black format
you-n-g Feb 27, 2021
c4733f6
Merge pull request #1 from you-n-g/online_srv
lzh222333 Mar 2, 2021
b84156f
Consider more situations about task_config.
lzh222333 Mar 3, 2021
05cf0e1
add task_generator method and update some hint
lzh222333 Mar 3, 2021
fd2c1ba
Update some hint
lzh222333 Mar 3, 2021
2882929
Add an example about workflow using RollingGen.
lzh222333 Mar 3, 2021
a244f87
modified the comments
lzh222333 Mar 8, 2021
def132e
modified format and added TaskCollector
lzh222333 Mar 8, 2021
83dbdfb
finished document and example
lzh222333 Mar 9, 2021
e2f5827
update task manager
lzh222333 Mar 10, 2021
2ca2071
format code
lzh222333 Mar 10, 2021
48f0fc1
first version of online serving
lzh222333 Mar 11, 2021
0df88c0
bug fixed and update collect.py
lzh222333 Mar 11, 2021
44a7dc0
update docs and fix duplicated pred bug
you-n-g Mar 12, 2021
5de7870
Merge branch 'online_srv' of github.com:you-n-g/qlib into online_srv
you-n-g Mar 12, 2021
6d8aa21
the second version of online serving
lzh222333 Mar 12, 2021
9d84d38
format code and add example
lzh222333 Mar 12, 2021
e4e8a4a
fix task name & add cur_path
you-n-g Mar 12, 2021
8362780
fix import bug
you-n-g Mar 14, 2021
646d899
update docstring and document
lzh222333 Mar 15, 2021
0bc49da
add task management to index.rst
lzh222333 Mar 15, 2021
e3730b3
more clearly structure
lzh222333 Mar 16, 2021
5953365
finished update_online_pred demo
lzh222333 Mar 16, 2021
d33041d
format example
lzh222333 Mar 16, 2021
8abdd63
online_serving V3
lzh222333 Mar 18, 2021
84d5318
Merge branch 'online_srv_wd' into online_srv
you-n-g Mar 19, 2021
d66d4ec
Merge branch 'main' into online_srv
lzh222333 Mar 23, 2021
46cd576
Online Serving V4
lzh222333 Mar 26, 2021
9bf819e
Merge branch 'online_srv' of https://github.com/you-n-g/qlib into onl…
lzh222333 Mar 26, 2021
ee45a78
Merge branch 'main' into online_srv
lzh222333 Mar 26, 2021
1f2d2c9
online debug
lzh222333 Mar 30, 2021
eae94d1
Merge remote-tracking branch 'microsoft/qlib/main' into online_srv
lzh222333 Mar 30, 2021
544365f
ensemble & get_exp & dataset_pickle
lzh222333 Mar 31, 2021
3724273
Merge remote-tracking branch 'microsoft/qlib/main' into online_srv
lzh222333 Mar 31, 2021
edcd7b1
bug fixed & code format
lzh222333 Mar 31, 2021
bd7a1c1
trainer & group & collect & ensemble
lzh222333 Apr 2, 2021
431a9c9
online serving v5
lzh222333 Apr 2, 2021
cb42e99
bug fixed & examples fire
lzh222333 Apr 7, 2021
1dbb561
Fix some API(for lb nn)
you-n-g Apr 7, 2021
7160579
Merge branch 'online_srv_wd' into online_srv
you-n-g Apr 7, 2021
c20eb5c
format code
lzh222333 Apr 8, 2021
18bf4b5
parameter adjustment
you-n-g Apr 8, 2021
a366c11
Update features for hyb nn
you-n-g Apr 9, 2021
cca43cf
Refactor update & modification when running NN
you-n-g Apr 11, 2021
b15e5e3
Fix the multi-processing bug
you-n-g Apr 12, 2021
5095b2a
simulator & examples
lzh222333 Apr 13, 2021
cec318f
online serving V7
lzh222333 Apr 16, 2021
de0a0c0
bug fixed
lzh222333 Apr 22, 2021
319396c
online serving V8
lzh222333 Apr 25, 2021
0058f7d
Online Serving V8
lzh222333 Apr 26, 2021
42f5100
update collector
lzh222333 Apr 27, 2021
36ab078
filter
Apr 28, 2021
45c6dfc
filter
Apr 28, 2021
fa4511c
filter
Apr 28, 2021
40cf83e
online serving V9 middle status
lzh222333 Apr 28, 2021
6f66934
Merge branch 'online_srv' of https://github.com/you-n-g/qlib into onl…
lzh222333 Apr 28, 2021
67c5740
OnlineServing V9
lzh222333 Apr 29, 2021
2b7ffa1
Merge remote-tracking branch 'microsoft/main' into online_srv
lzh222333 Apr 29, 2021
1c99fb3
Merge remote-tracking branch 'microsoft/main' into online_srv
lzh222333 May 6, 2021
84c56f1
docs and bug fixed
lzh222333 May 6, 2021
846c64f
fix param
binlins May 6, 2021
9dfd001
online serving v10
lzh222333 May 7, 2021
bec65dd
add document and reindex
binlins May 7, 2021
08edb92
add flt_data doc
binlins May 7, 2021
060a32e
Merge branch 'online_srv' into online_srv_blin
you-n-g May 7, 2021
1c605e5
Merge pull request #14 from you-n-g/online_srv_blin
you-n-g May 7, 2021
4c23261
Merge branch 'online_srv' of https://github.com/you-n-g/qlib into onl…
lzh222333 May 9, 2021
f5ded06
Merge remote-tracking branch 'microsoft/main' into online_srv
lzh222333 May 9, 2021
370b6aa
logger & doc
lzh222333 May 9, 2021
d71a666
Online serving V11
lzh222333 May 13, 2021
ebd01e0
Online Serving V11
lzh222333 May 14, 2021
aef3f18
format code
lzh222333 May 14, 2021
a986379
bug fixed
lzh222333 May 14, 2021
8c3a08b
Finally!
lzh222333 May 17, 2021
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
Prev Previous commit
Next Next commit
online serving v10
  • Loading branch information
lzh222333 committed May 7, 2021
commit 9dfd001f6fafbe077dcdc30feacd0dbeb7bf31e6
1 change: 1 addition & 0 deletions docs/advanced/task_management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ More information of ``Task Manager`` can be found in `here <../reference/api.htm

Task Training
===============
#FIXME: Trainer
After generating and storing those ``task``, it's time to run the ``task`` which are in the *WAITING* status.
``Qlib`` provides a method called ``run_task`` to run those ``task`` in task pool, however, users can also customize how tasks are executed.
An easy way to get the ``task_func`` is using ``qlib.model.trainer.task_train`` directly.
Expand Down
21 changes: 14 additions & 7 deletions examples/online_srv/online_management_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fire
import qlib
from qlib.model.trainer import DelayTrainerRM
from qlib.workflow import R
from qlib.workflow.online.manager import OnlineManager
from qlib.workflow.online.strategy import RollingAverageStrategy
from qlib.workflow.task.gen import RollingGen
Expand Down Expand Up @@ -110,31 +111,37 @@ def __init__(
}
qlib.init(provider_uri=provider_uri, region=region, mongo=mongo_conf)
self.rolling_gen = RollingGen(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RollingGen is a legacy implementation.
We should think about if it is the best practice under the new design.

step=rolling_step, rtype=RollingGen.ROLL_SD, modify_end_time=False
) # The rolling tasks generator, modify_end_time is false because we just need simulate to 2018-10-31.
step=rolling_step, rtype=RollingGen.ROLL_SD, ds_extra_mod_func=None
) # The rolling tasks generator, ds_extra_mod_func is None because we just need simulate to 2018-10-31 and needn't change handler end time.
self.trainer = DelayTrainerRM(self.exp_name, self.task_pool)
self.task_manager = TaskManager(self.task_pool) # A good way to manage all your tasks
self.rolling_online_manager = OnlineManager(
RollingAverageStrategy(
exp_name, task_template=tasks, rolling_gen=self.rolling_gen, trainer=self.trainer, need_log=False
),
RollingAverageStrategy(exp_name, task_template=tasks, rolling_gen=self.rolling_gen, need_log=False),
trainer=self.trainer,
begin_time=self.start_time,
need_log=False,
)
self.tasks = tasks

# Reset all things to the first status, be careful to save important data
def reset(self):
TaskManager(self.task_pool).remove()
exp = R.get_exp(experiment_name=self.exp_name)
for rid in exp.list_recorders():
exp.delete_recorder(rid)

# Run this to run all workflow automatically
def main(self):
print("========== reset ==========")
self.rolling_online_manager.reset()
self.reset()
print("========== simulate ==========")
self.rolling_online_manager.simulate(end_time=self.end_time)
print("========== collect results ==========")
print(self.rolling_online_manager.get_collector()())
print("========== signals ==========")
print(self.rolling_online_manager.get_signals())
print("========== online history ==========")
print(self.rolling_online_manager.get_online_history(self.exp_name))
print(self.rolling_online_manager.history)


if __name__ == "__main__":
Expand Down
13 changes: 3 additions & 10 deletions examples/online_srv/rolling_online_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from qlib.workflow.task.gen import RollingGen
from qlib.workflow.task.manage import TaskManager
from qlib.workflow.online.manager import OnlineManager
from qlib.workflow.task.utils import list_recorders
from qlib.model.trainer import TrainerRM

data_handler_config = {
"start_time": "2013-01-01",
Expand Down Expand Up @@ -86,7 +84,7 @@ def __init__(
task_url="mongodb://10.0.0.4:27017/",
task_db_name="rolling_db",
rolling_step=550,
tasks=[task_xgboost_config], # , task_lgb_config],
tasks=[task_xgboost_config, task_lgb_config],
):
mongo_conf = {
"task_url": task_url, # your MongoDB url
Expand All @@ -103,7 +101,6 @@ def __init__(
name_id,
task,
RollingGen(step=rolling_step, rtype=RollingGen.ROLL_SD),
TrainerRM(experiment_name=name_id, task_pool=name_id),
)
)

Expand All @@ -116,9 +113,8 @@ def __init__(

# Reset all things to the first status, be careful to save important data
def reset(self):
print("========== reset ==========")
for task in self.tasks:
name_id = task["model"]["class"] + "_" + str(self.rolling_step)
name_id = task["model"]["class"]
TaskManager(name_id).remove()
exp = R.get_exp(experiment_name=name_id)
for rid in exp.list_recorders():
Expand All @@ -127,12 +123,9 @@ def reset(self):
if os.path.exists(self._ROLLING_MANAGER_PATH):
os.remove(self._ROLLING_MANAGER_PATH)

for rid in list_recorders("OnlineManagerSignals", lambda x: True if x.info["name"] == name_id else False):
exp.delete_recorder(rid)

def first_run(self):
print("========== reset ==========")
self.rolling_online_manager.reset()
self.reset()
print("========== first_run ==========")
self.rolling_online_manager.first_train()
print("========== dump ==========")
Expand Down
12 changes: 8 additions & 4 deletions qlib/model/ens/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from typing import Union
import pandas as pd
from qlib.utils import flatten_dict


class Ensemble:
Expand Down Expand Up @@ -77,19 +78,22 @@ def __call__(self, ensemble_dict: dict) -> pd.DataFrame:
class AverageEnsemble(Ensemble):
def __call__(self, ensemble_dict: dict):
"""
Average a dict of same shape dataframe like `prediction` or `IC` into an ensemble.
Average and standardize a dict of same shape dataframe like `prediction` or `IC` into an ensemble.

NOTE: The values of dict must be pd.DataFrame, and have the index "datetime"
NOTE: The values of dict must be pd.DataFrame, and have the index "datetime". If it is a nested dict, then flat it.

Args:
ensemble_dict (dict): a dict like {"A": pd.DataFrame, "B": pd.DataFrame}.
The key of the dict will be ignored.

Returns:
pd.DataFrame: the complete result of averaging.
pd.DataFrame: the complete result of averaging and standardizing.
"""
# need to flatten the nested dict
ensemble_dict = flatten_dict(ensemble_dict)
values = list(ensemble_dict.values())
results = pd.concat(values, axis=1)
results = results.mean(axis=1).to_frame("score")
results = results.groupby("datetime").apply(lambda df: (df - df.mean()) / df.std())
results = results.mean(axis=1)
results = results.sort_index()
return results
20 changes: 18 additions & 2 deletions qlib/model/ens/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,36 @@ def __init__(self, group_func=None, ens: Ensemble = None):
self._ens_func = ens

def group(self, *args, **kwargs) -> dict:
# TODO: such design is weird when `_group_func` is the only configurable part in the class
"""
Group a set of object and change them to a dict.

For example: {(A,B,C1): object, (A,B,C2): object} -> {(A,B): {C1: object, C2: object}}

Returns:
dict: grouped dict
"""
if isinstance(getattr(self, "_group_func", None), Callable):
return self._group_func(*args, **kwargs)
else:
raise NotImplementedError(f"Please specify valid `group_func`.")

def reduce(self, *args, **kwargs) -> dict:
"""
Reduce grouped dict in some way.

For example: {(A,B): {C1: object, C2: object}} -> {(A,B): object}

Returns:
dict: reduced dict
"""
if isinstance(getattr(self, "_ens_func", None), Callable):
return self._ens_func(*args, **kwargs)
else:
raise NotImplementedError(f"Please specify valid `_ens_func`.")

def __call__(self, ungrouped_dict: dict, n_jobs=1, verbose=0, *args, **kwargs) -> dict:
"""Group the ungrouped_dict into different groups.
"""
Group the ungrouped_dict into different groups.

Args:
ungrouped_dict (dict): the ungrouped dict waiting for grouping like {name: things}
Expand Down
Loading