mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-14 08:16:54 +08:00
format code
This commit is contained in:
@@ -9,53 +9,37 @@ data_handler_config = {
|
|||||||
"end_time": "2020-08-01",
|
"end_time": "2020-08-01",
|
||||||
"fit_start_time": "2008-01-01",
|
"fit_start_time": "2008-01-01",
|
||||||
"fit_end_time": "2014-12-31",
|
"fit_end_time": "2014-12-31",
|
||||||
"instruments": 'csi100',
|
"instruments": "csi100",
|
||||||
}
|
}
|
||||||
|
|
||||||
dataset_config = {
|
dataset_config = {
|
||||||
"class": "DatasetH",
|
"class": "DatasetH",
|
||||||
"module_path": "qlib.data.dataset",
|
"module_path": "qlib.data.dataset",
|
||||||
"kwargs": {
|
"kwargs": {
|
||||||
"handler": {
|
"handler": {"class": "Alpha158", "module_path": "qlib.contrib.data.handler", "kwargs": data_handler_config,},
|
||||||
"class": "Alpha158",
|
"segments": {
|
||||||
"module_path": "qlib.contrib.data.handler",
|
"train": ("2008-01-01", "2014-12-31"),
|
||||||
"kwargs": data_handler_config,
|
"valid": ("2015-01-01", "2016-12-31"),
|
||||||
},
|
"test": ("2017-01-01", "2020-08-01"),
|
||||||
"segments": {
|
|
||||||
"train": ("2008-01-01", "2014-12-31"),
|
|
||||||
"valid": ("2015-01-01", "2016-12-31"),
|
|
||||||
"test": ("2017-01-01", "2020-08-01"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
record_config = [
|
record_config = [
|
||||||
{
|
{"class": "SignalRecord", "module_path": "qlib.workflow.record_temp",},
|
||||||
"class": "SignalRecord",
|
{"class": "SigAnaRecord", "module_path": "qlib.workflow.record_temp",},
|
||||||
"module_path": "qlib.workflow.record_temp",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"class": "SigAnaRecord",
|
|
||||||
"module_path": "qlib.workflow.record_temp",
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# use lgb
|
# use lgb
|
||||||
task_lgb_config = {
|
task_lgb_config = {
|
||||||
"model": {
|
"model": {"class": "LGBModel", "module_path": "qlib.contrib.model.gbdt",},
|
||||||
"class": "LGBModel",
|
|
||||||
"module_path": "qlib.contrib.model.gbdt",
|
|
||||||
},
|
|
||||||
"dataset": dataset_config,
|
"dataset": dataset_config,
|
||||||
"record": record_config,
|
"record": record_config,
|
||||||
}
|
}
|
||||||
|
|
||||||
# use xgboost
|
# use xgboost
|
||||||
task_xgboost_config = {
|
task_xgboost_config = {
|
||||||
"model": {
|
"model": {"class": "XGBModel", "module_path": "qlib.contrib.model.xgboost",},
|
||||||
"class": "XGBModel",
|
|
||||||
"module_path": "qlib.contrib.model.xgboost",
|
|
||||||
},
|
|
||||||
"dataset": dataset_config,
|
"dataset": dataset_config,
|
||||||
"record": record_config,
|
"record": record_config,
|
||||||
}
|
}
|
||||||
@@ -64,17 +48,17 @@ provider_uri = "~/.qlib/qlib_data/cn_data" # target_dir
|
|||||||
qlib.init(provider_uri=provider_uri, region=REG_CN)
|
qlib.init(provider_uri=provider_uri, region=REG_CN)
|
||||||
|
|
||||||
C["mongo"] = {
|
C["mongo"] = {
|
||||||
"task_url" : "mongodb://localhost:27017/", # maybe you need to change it to your url
|
"task_url": "mongodb://localhost:27017/", # maybe you need to change it to your url
|
||||||
"task_db_name" : "rolling_db"
|
"task_db_name": "rolling_db",
|
||||||
}
|
}
|
||||||
|
|
||||||
exp_name = 'rolling_exp' # experiment name, will be used as the experiment in MLflow
|
exp_name = "rolling_exp" # experiment name, will be used as the experiment in MLflow
|
||||||
task_pool = 'rolling_task' # task pool name, will be used as the document in MongoDB
|
task_pool = "rolling_task" # task pool name, will be used as the document in MongoDB
|
||||||
|
|
||||||
tasks = task_generator(
|
tasks = task_generator(
|
||||||
task_xgboost_config, # default task name
|
task_xgboost_config, # default task name
|
||||||
RollingGen(step=550,rtype=RollingGen.ROLL_SD), # generate different date segment
|
RollingGen(step=550, rtype=RollingGen.ROLL_SD), # generate different date segment
|
||||||
task_lgb=task_lgb_config # use "task_lgb" as the task name
|
task_lgb=task_lgb_config, # use "task_lgb" as the task name
|
||||||
)
|
)
|
||||||
|
|
||||||
# Uncomment next two lines to see the generated tasks
|
# Uncomment next two lines to see the generated tasks
|
||||||
@@ -82,26 +66,29 @@ tasks = task_generator(
|
|||||||
# pprint(tasks)
|
# pprint(tasks)
|
||||||
|
|
||||||
tm = TaskManager(task_pool=task_pool)
|
tm = TaskManager(task_pool=task_pool)
|
||||||
tm.create_task(tasks) # all tasks will be saved to MongoDB
|
tm.create_task(tasks) # all tasks will be saved to MongoDB
|
||||||
|
|
||||||
from qlib.workflow.task.manage import run_task
|
from qlib.workflow.task.manage import run_task
|
||||||
from qlib.workflow.task.collect import TaskCollector
|
from qlib.workflow.task.collect import TaskCollector
|
||||||
from qlib.model.trainer import task_train
|
from qlib.model.trainer import task_train
|
||||||
|
|
||||||
run_task(task_train, task_pool, experiment_name=exp_name) # all tasks will be trained using "task_train" method
|
run_task(task_train, task_pool, experiment_name=exp_name) # all tasks will be trained using "task_train" method
|
||||||
|
|
||||||
|
|
||||||
def get_task_key(task_config):
|
def get_task_key(task_config):
|
||||||
task_key = task_config["task_key"]
|
task_key = task_config["task_key"]
|
||||||
rolling_end_timestamp = task_config["dataset"]["kwargs"]["segments"]["test"][1]
|
rolling_end_timestamp = task_config["dataset"]["kwargs"]["segments"]["test"][1]
|
||||||
return task_key, rolling_end_timestamp.strftime('%Y-%m-%d')
|
return task_key, rolling_end_timestamp.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
def my_filter(task_config):
|
def my_filter(task_config):
|
||||||
# only choose the results of "task_lgb" and test in 2019 from all tasks
|
# only choose the results of "task_lgb" and test in 2019 from all tasks
|
||||||
task_key, rolling_end = get_task_key(task_config)
|
task_key, rolling_end = get_task_key(task_config)
|
||||||
if task_key=="task_lgb" and rolling_end.startswith('2019'):
|
if task_key == "task_lgb" and rolling_end.startswith("2019"):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# name tasks by "get_task_key" and filter tasks by "my_filter"
|
# name tasks by "get_task_key" and filter tasks by "my_filter"
|
||||||
pred_rolling = TaskCollector.collect_predictions(exp_name, get_task_key, my_filter)
|
pred_rolling = TaskCollector.collect_predictions(exp_name, get_task_key, my_filter)
|
||||||
pred_rolling
|
pred_rolling
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ class TaskCollector:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def collect_predictions(
|
def collect_predictions(
|
||||||
experiment_name: str, get_key_func, filter_func=None,
|
experiment_name: str,
|
||||||
|
get_key_func,
|
||||||
|
filter_func=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user