mirror of
https://github.com/microsoft/qlib.git
synced 2026-06-30 01:21:18 +08:00
445 lines
26 KiB
Plaintext
445 lines
26 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import mlflow\n",
|
|
"mlflow.end_run()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stderr",
|
|
"text": [
|
|
"[8348:MainThread](2021-03-09 14:55:48,543) INFO - qlib.Initialization - [config.py:279] - default_conf: client.\n",
|
|
"[8348:MainThread](2021-03-09 14:55:50,592) WARNING - qlib.Initialization - [config.py:295] - redis connection failed(host=127.0.0.1 port=6379), cache will not be used!\n",
|
|
"[8348:MainThread](2021-03-09 14:55:50,597) INFO - qlib.Initialization - [__init__.py:48] - qlib successfully initialized based on client settings.\n",
|
|
"[8348:MainThread](2021-03-09 14:55:50,601) INFO - qlib.Initialization - [__init__.py:49] - data_path=C:\\Users\\lzh222333\\.qlib\\qlib_data\\cn_data\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import qlib\n",
|
|
"from qlib.config import REG_CN\n",
|
|
"from qlib.workflow.task.gen import RollingGen, task_generator\n",
|
|
"from qlib.workflow.task.manage import TaskManager\n",
|
|
"from qlib.config import C\n",
|
|
"\n",
|
|
"data_handler_template = {\n",
|
|
" \"start_time\": \"2008-01-01\",\n",
|
|
" \"end_time\": \"2020-08-01\",\n",
|
|
" \"fit_start_time\": \"2008-01-01\",\n",
|
|
" \"fit_end_time\": \"2014-12-31\",\n",
|
|
" \"instruments\": 'csi100',\n",
|
|
"}\n",
|
|
"\n",
|
|
"dataset_template = {\n",
|
|
" \"class\": \"DatasetH\",\n",
|
|
" \"module_path\": \"qlib.data.dataset\",\n",
|
|
" \"kwargs\": {\n",
|
|
" \"handler\": {\n",
|
|
" \"class\": \"Alpha158\",\n",
|
|
" \"module_path\": \"qlib.contrib.data.handler\",\n",
|
|
" \"kwargs\": data_handler_template,\n",
|
|
" },\n",
|
|
" \"segments\": {\n",
|
|
" \"train\": (\"2008-01-01\", \"2014-12-31\"),\n",
|
|
" \"valid\": (\"2015-01-01\", \"2016-12-31\"),\n",
|
|
" \"test\": (\"2017-01-01\", \"2020-08-01\"),\n",
|
|
" },\n",
|
|
" },\n",
|
|
" }\n",
|
|
"\n",
|
|
"record_template = [\n",
|
|
" {\n",
|
|
" \"class\": \"SignalRecord\",\n",
|
|
" \"module_path\": \"qlib.workflow.record_temp\",\n",
|
|
" },\n",
|
|
" {\n",
|
|
" \"class\": \"SigAnaRecord\",\n",
|
|
" \"module_path\": \"qlib.workflow.record_temp\",\n",
|
|
" }\n",
|
|
"]\n",
|
|
"\n",
|
|
"# use lgb\n",
|
|
"lgb_task_template = {\n",
|
|
" \"model\": {\n",
|
|
" \"class\": \"LGBModel\",\n",
|
|
" \"module_path\": \"qlib.contrib.model.gbdt\",\n",
|
|
" },\n",
|
|
" \"dataset\": dataset_template,\n",
|
|
" \"record\": record_template,\n",
|
|
"}\n",
|
|
"\n",
|
|
"# use xgboost\n",
|
|
"xgboost_task_template = {\n",
|
|
" \"model\": {\n",
|
|
" \"class\": \"XGBModel\",\n",
|
|
" \"module_path\": \"qlib.contrib.model.xgboost\",\n",
|
|
" },\n",
|
|
" \"dataset\": dataset_template,\n",
|
|
" \"record\": record_template,\n",
|
|
"}\n",
|
|
"\n",
|
|
"provider_uri = \"~/.qlib/qlib_data/cn_data\" # target_dir\n",
|
|
"qlib.init(provider_uri=provider_uri, region=REG_CN)\n",
|
|
"\n",
|
|
"C[\"mongo\"] = {\n",
|
|
" \"task_url\" : \"mongodb://localhost:27017/\", # maybe you need to change it to your url\n",
|
|
" \"task_db_name\" : \"rolling_db3\"\n",
|
|
"}\n",
|
|
"\n",
|
|
"exp_name = 'rolling_exp3' # experiment name, will be used as the experiment in MLflow\n",
|
|
"task_pool = 'rolling_task3' # task pool name, will be used as the document in MongoDB"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"[{'dataset': {'class': 'DatasetH',\n",
|
|
" 'kwargs': {'handler': {'class': 'Alpha158',\n",
|
|
" 'kwargs': {'end_time': '2020-08-01',\n",
|
|
" 'fit_end_time': '2014-12-31',\n",
|
|
" 'fit_start_time': '2008-01-01',\n",
|
|
" 'instruments': 'csi100',\n",
|
|
" 'start_time': '2008-01-01'},\n",
|
|
" 'module_path': 'qlib.contrib.data.handler'},\n",
|
|
" 'segments': {'test': (Timestamp('2017-01-03 00:00:00'),\n",
|
|
" Timestamp('2019-04-08 00:00:00')),\n",
|
|
" 'train': (Timestamp('2008-01-02 00:00:00'),\n",
|
|
" Timestamp('2014-12-31 00:00:00')),\n",
|
|
" 'valid': (Timestamp('2015-01-05 00:00:00'),\n",
|
|
" Timestamp('2016-12-30 00:00:00'))}},\n",
|
|
" 'module_path': 'qlib.data.dataset'},\n",
|
|
" 'model': {'class': 'XGBModel', 'module_path': 'qlib.contrib.model.xgboost'},\n",
|
|
" 'record': [{'class': 'SignalRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'},\n",
|
|
" {'class': 'SigAnaRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'}],\n",
|
|
" 'task_key': 1},\n",
|
|
" {'dataset': {'class': 'DatasetH',\n",
|
|
" 'kwargs': {'handler': {'class': 'Alpha158',\n",
|
|
" 'kwargs': {'end_time': '2020-08-01',\n",
|
|
" 'fit_end_time': '2014-12-31',\n",
|
|
" 'fit_start_time': '2008-01-01',\n",
|
|
" 'instruments': 'csi100',\n",
|
|
" 'start_time': '2008-01-01'},\n",
|
|
" 'module_path': 'qlib.contrib.data.handler'},\n",
|
|
" 'segments': {'test': (Timestamp('2019-04-09 00:00:00'),\n",
|
|
" Timestamp('2021-07-12 00:00:00')),\n",
|
|
" 'train': (Timestamp('2010-04-23 00:00:00'),\n",
|
|
" Timestamp('2017-05-24 00:00:00')),\n",
|
|
" 'valid': (Timestamp('2017-05-25 00:00:00'),\n",
|
|
" Timestamp('2019-04-08 00:00:00'))}},\n",
|
|
" 'module_path': 'qlib.data.dataset'},\n",
|
|
" 'model': {'class': 'XGBModel', 'module_path': 'qlib.contrib.model.xgboost'},\n",
|
|
" 'record': [{'class': 'SignalRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'},\n",
|
|
" {'class': 'SigAnaRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'}],\n",
|
|
" 'task_key': 1},\n",
|
|
" {'dataset': {'class': 'DatasetH',\n",
|
|
" 'kwargs': {'handler': {'class': 'Alpha158',\n",
|
|
" 'kwargs': {'end_time': '2020-08-01',\n",
|
|
" 'fit_end_time': '2014-12-31',\n",
|
|
" 'fit_start_time': '2008-01-01',\n",
|
|
" 'instruments': 'csi100',\n",
|
|
" 'start_time': '2008-01-01'},\n",
|
|
" 'module_path': 'qlib.contrib.data.handler'},\n",
|
|
" 'segments': {'test': (Timestamp('2017-01-03 00:00:00'),\n",
|
|
" Timestamp('2019-04-08 00:00:00')),\n",
|
|
" 'train': (Timestamp('2008-01-02 00:00:00'),\n",
|
|
" Timestamp('2014-12-31 00:00:00')),\n",
|
|
" 'valid': (Timestamp('2015-01-05 00:00:00'),\n",
|
|
" Timestamp('2016-12-30 00:00:00'))}},\n",
|
|
" 'module_path': 'qlib.data.dataset'},\n",
|
|
" 'model': {'class': 'LGBModel', 'module_path': 'qlib.contrib.model.gbdt'},\n",
|
|
" 'record': [{'class': 'SignalRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'},\n",
|
|
" {'class': 'SigAnaRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'}],\n",
|
|
" 'task_key': 'task_lgb'},\n",
|
|
" {'dataset': {'class': 'DatasetH',\n",
|
|
" 'kwargs': {'handler': {'class': 'Alpha158',\n",
|
|
" 'kwargs': {'end_time': '2020-08-01',\n",
|
|
" 'fit_end_time': '2014-12-31',\n",
|
|
" 'fit_start_time': '2008-01-01',\n",
|
|
" 'instruments': 'csi100',\n",
|
|
" 'start_time': '2008-01-01'},\n",
|
|
" 'module_path': 'qlib.contrib.data.handler'},\n",
|
|
" 'segments': {'test': (Timestamp('2019-04-09 00:00:00'),\n",
|
|
" Timestamp('2021-07-12 00:00:00')),\n",
|
|
" 'train': (Timestamp('2010-04-23 00:00:00'),\n",
|
|
" Timestamp('2017-05-24 00:00:00')),\n",
|
|
" 'valid': (Timestamp('2017-05-25 00:00:00'),\n",
|
|
" Timestamp('2019-04-08 00:00:00'))}},\n",
|
|
" 'module_path': 'qlib.data.dataset'},\n",
|
|
" 'model': {'class': 'LGBModel', 'module_path': 'qlib.contrib.model.gbdt'},\n",
|
|
" 'record': [{'class': 'SignalRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'},\n",
|
|
" {'class': 'SigAnaRecord',\n",
|
|
" 'module_path': 'qlib.workflow.record_temp'}],\n",
|
|
" 'task_key': 'task_lgb'}]\n",
|
|
"Total Tasks, New Tasks: 4 0\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"tasks = task_generator(\n",
|
|
" xgboost_task_template, # default task name\n",
|
|
" RollingGen(step=550,rtype=RollingGen.ROLL_SD), # generate different date segment\n",
|
|
" task_lgb=lgb_task_template # use \"task_lgb\" as the task name\n",
|
|
")\n",
|
|
"# Uncomment next two lines to see the generated tasks\n",
|
|
"from pprint import pprint\n",
|
|
"pprint(tasks)\n",
|
|
"tm = TaskManager(task_pool=task_pool)\n",
|
|
"tm.create_task(tasks) # all tasks will be saved to MongoDB"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"pycharm": {
|
|
"name": "#%%\n"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stderr",
|
|
"text": [
|
|
"2021-03-09 14:55:51.600 | INFO | qlib.workflow.task.manage:run_task:355 - {'model': {'class': 'XGBModel', 'module_path': 'qlib.contrib.model.xgboost'}, 'dataset': {'class': 'DatasetH', 'module_path': 'qlib.data.dataset', 'kwargs': {'handler': {'class': 'Alpha158', 'module_path': 'qlib.contrib.data.handler', 'kwargs': {'start_time': '2008-01-01', 'end_time': '2020-08-01', 'fit_start_time': '2008-01-01', 'fit_end_time': '2014-12-31', 'instruments': 'csi100'}}, 'segments': {'train': (Timestamp('2008-01-02 00:00:00'), Timestamp('2014-12-31 00:00:00')), 'valid': (Timestamp('2015-01-05 00:00:00'), Timestamp('2016-12-30 00:00:00')), 'test': (Timestamp('2017-01-03 00:00:00'), Timestamp('2019-04-08 00:00:00'))}}}, 'record': [{'class': 'SignalRecord', 'module_path': 'qlib.workflow.record_temp'}, {'class': 'SigAnaRecord', 'module_path': 'qlib.workflow.record_temp'}], 'task_key': 1}\n",
|
|
"[8348:MainThread](2021-03-09 14:56:46,051) INFO - qlib.timer - [log.py:81] - Time cost: 54.448s | Loading data Done\n",
|
|
"[8348:MainThread](2021-03-09 14:56:46,440) INFO - qlib.timer - [log.py:81] - Time cost: 0.322s | DropnaLabel Done\n",
|
|
"[8348:MainThread](2021-03-09 14:56:52,461) INFO - qlib.timer - [log.py:81] - Time cost: 6.019s | CSZScoreNorm Done\n",
|
|
"[8348:MainThread](2021-03-09 14:56:52,464) INFO - qlib.timer - [log.py:81] - Time cost: 6.411s | fit & process data Done\n",
|
|
"[8348:MainThread](2021-03-09 14:56:52,468) INFO - qlib.timer - [log.py:81] - Time cost: 60.865s | Init data Done\n",
|
|
"[8348:MainThread](2021-03-09 14:56:52,471) INFO - qlib.workflow - [expm.py:245] - No tracking URI is provided. Use the default tracking URI.\n",
|
|
"[8348:MainThread](2021-03-09 14:56:52,500) INFO - qlib.workflow - [exp.py:181] - Experiment 2 starts running ...\n",
|
|
"[8348:MainThread](2021-03-09 14:56:52,567) INFO - qlib.workflow - [recorder.py:233] - Recorder dd6bceb6d319493686ab6565633c0b5a starts running under Experiment 2 ...\n",
|
|
"[0]\ttrain-rmse:1.05165\tvalid-rmse:1.05565\n",
|
|
"[20]\ttrain-rmse:0.97071\tvalid-rmse:1.00077\n",
|
|
"[40]\ttrain-rmse:0.95124\tvalid-rmse:1.00609\n",
|
|
"[59]\ttrain-rmse:0.93833\tvalid-rmse:1.00945\n",
|
|
"[8348:MainThread](2021-03-09 14:59:37,266) INFO - qlib.workflow - [record_temp.py:126] - Signal record 'pred.pkl' has been saved as the artifact of the Experiment 2\n",
|
|
"'The following are prediction results of the XGBModel model.'\n",
|
|
" score\n",
|
|
"datetime instrument \n",
|
|
"2017-01-03 SH600000 -0.103259\n",
|
|
" SH600010 -0.084365\n",
|
|
" SH600015 -0.107433\n",
|
|
" SH600016 -0.064723\n",
|
|
" SH600018 -0.038639\n",
|
|
"{'IC': 0.05347474869798698,\n",
|
|
" 'ICIR': 0.29781294430945265,\n",
|
|
" 'Rank IC': 0.0484064337863249,\n",
|
|
" 'Rank ICIR': 0.36035393716962033}\n",
|
|
"2021-03-09 14:59:38.633 | INFO | qlib.workflow.task.manage:run_task:355 - {'model': {'class': 'XGBModel', 'module_path': 'qlib.contrib.model.xgboost'}, 'dataset': {'class': 'DatasetH', 'module_path': 'qlib.data.dataset', 'kwargs': {'handler': {'class': 'Alpha158', 'module_path': 'qlib.contrib.data.handler', 'kwargs': {'start_time': '2008-01-01', 'end_time': '2020-08-01', 'fit_start_time': '2008-01-01', 'fit_end_time': '2014-12-31', 'instruments': 'csi100'}}, 'segments': {'train': (Timestamp('2010-04-23 00:00:00'), Timestamp('2017-05-24 00:00:00')), 'valid': (Timestamp('2017-05-25 00:00:00'), Timestamp('2019-04-08 00:00:00')), 'test': (Timestamp('2019-04-09 00:00:00'), Timestamp('2021-07-12 00:00:00'))}}}, 'record': [{'class': 'SignalRecord', 'module_path': 'qlib.workflow.record_temp'}, {'class': 'SigAnaRecord', 'module_path': 'qlib.workflow.record_temp'}], 'task_key': 1}\n",
|
|
"[8348:MainThread](2021-03-09 15:00:36,591) INFO - qlib.timer - [log.py:81] - Time cost: 57.954s | Loading data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:00:36,997) INFO - qlib.timer - [log.py:81] - Time cost: 0.338s | DropnaLabel Done\n",
|
|
"[8348:MainThread](2021-03-09 15:00:43,728) INFO - qlib.timer - [log.py:81] - Time cost: 6.728s | CSZScoreNorm Done\n",
|
|
"[8348:MainThread](2021-03-09 15:00:43,731) INFO - qlib.timer - [log.py:81] - Time cost: 7.137s | fit & process data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:00:43,734) INFO - qlib.timer - [log.py:81] - Time cost: 65.097s | Init data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:00:43,740) INFO - qlib.workflow - [expm.py:245] - No tracking URI is provided. Use the default tracking URI.\n",
|
|
"[8348:MainThread](2021-03-09 15:00:43,768) INFO - qlib.workflow - [exp.py:181] - Experiment 2 starts running ...\n",
|
|
"[8348:MainThread](2021-03-09 15:00:43,851) INFO - qlib.workflow - [recorder.py:233] - Recorder de2f892b569c436ba642a23e99f4f2b0 starts running under Experiment 2 ...\n",
|
|
"[0]\ttrain-rmse:1.05178\tvalid-rmse:1.05345\n",
|
|
"[20]\ttrain-rmse:0.96764\tvalid-rmse:0.99546\n",
|
|
"[40]\ttrain-rmse:0.94957\tvalid-rmse:0.99798\n",
|
|
"[57]\ttrain-rmse:0.93592\tvalid-rmse:1.00030\n",
|
|
"[8348:MainThread](2021-03-09 15:03:12,764) INFO - qlib.workflow - [record_temp.py:126] - Signal record 'pred.pkl' has been saved as the artifact of the Experiment 2\n",
|
|
"'The following are prediction results of the XGBModel model.'\n",
|
|
" score\n",
|
|
"datetime instrument \n",
|
|
"2019-04-09 SH600000 0.006996\n",
|
|
" SH600009 -0.102482\n",
|
|
" SH600010 0.016398\n",
|
|
" SH600011 0.004459\n",
|
|
" SH600015 -0.128315\n",
|
|
"{'IC': 0.013224093132176661,\n",
|
|
" 'ICIR': 0.08254897170570956,\n",
|
|
" 'Rank IC': 0.02472594591723197,\n",
|
|
" 'Rank ICIR': 0.16330982475433398}\n",
|
|
"2021-03-09 15:03:13.593 | INFO | qlib.workflow.task.manage:run_task:355 - {'model': {'class': 'LGBModel', 'module_path': 'qlib.contrib.model.gbdt'}, 'dataset': {'class': 'DatasetH', 'module_path': 'qlib.data.dataset', 'kwargs': {'handler': {'class': 'Alpha158', 'module_path': 'qlib.contrib.data.handler', 'kwargs': {'start_time': '2008-01-01', 'end_time': '2020-08-01', 'fit_start_time': '2008-01-01', 'fit_end_time': '2014-12-31', 'instruments': 'csi100'}}, 'segments': {'train': (Timestamp('2008-01-02 00:00:00'), Timestamp('2014-12-31 00:00:00')), 'valid': (Timestamp('2015-01-05 00:00:00'), Timestamp('2016-12-30 00:00:00')), 'test': (Timestamp('2017-01-03 00:00:00'), Timestamp('2019-04-08 00:00:00'))}}}, 'record': [{'class': 'SignalRecord', 'module_path': 'qlib.workflow.record_temp'}, {'class': 'SigAnaRecord', 'module_path': 'qlib.workflow.record_temp'}], 'task_key': 'task_lgb'}\n",
|
|
"[8348:MainThread](2021-03-09 15:04:06,545) INFO - qlib.timer - [log.py:81] - Time cost: 52.814s | Loading data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:04:06,919) INFO - qlib.timer - [log.py:81] - Time cost: 0.312s | DropnaLabel Done\n",
|
|
"[8348:MainThread](2021-03-09 15:04:12,850) INFO - qlib.timer - [log.py:81] - Time cost: 5.928s | CSZScoreNorm Done\n",
|
|
"[8348:MainThread](2021-03-09 15:04:12,853) INFO - qlib.timer - [log.py:81] - Time cost: 6.305s | fit & process data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:04:12,856) INFO - qlib.timer - [log.py:81] - Time cost: 59.125s | Init data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:04:12,859) INFO - qlib.workflow - [expm.py:245] - No tracking URI is provided. Use the default tracking URI.\n",
|
|
"[8348:MainThread](2021-03-09 15:04:12,888) INFO - qlib.workflow - [exp.py:181] - Experiment 2 starts running ...\n",
|
|
"[8348:MainThread](2021-03-09 15:04:12,958) INFO - qlib.workflow - [recorder.py:233] - Recorder 15df799127a74656829978c1b9352e60 starts running under Experiment 2 ...\n",
|
|
"Training until validation scores don't improve for 50 rounds\n",
|
|
"[20]\ttrain's l2: 0.970491\tvalid's l2: 0.987723\n",
|
|
"[40]\ttrain's l2: 0.957984\tvalid's l2: 0.990056\n",
|
|
"[60]\ttrain's l2: 0.947201\tvalid's l2: 0.991459\n",
|
|
"Early stopping, best iteration is:\n",
|
|
"[18]\ttrain's l2: 0.971834\tvalid's l2: 0.987481\n",
|
|
"[8348:MainThread](2021-03-09 15:04:19,847) INFO - qlib.workflow - [record_temp.py:126] - Signal record 'pred.pkl' has been saved as the artifact of the Experiment 2\n",
|
|
"'The following are prediction results of the LGBModel model.'\n",
|
|
" score\n",
|
|
"datetime instrument \n",
|
|
"2017-01-03 SH600000 -0.013089\n",
|
|
" SH600010 -0.006642\n",
|
|
" SH600015 -0.035137\n",
|
|
" SH600016 -0.034634\n",
|
|
" SH600018 -0.029493\n",
|
|
"{'IC': 0.05704431372255674,\n",
|
|
" 'ICIR': 0.28879437007622133,\n",
|
|
" 'Rank IC': 0.05181220321608411,\n",
|
|
" 'Rank ICIR': 0.3233833799543165}\n",
|
|
"2021-03-09 15:04:21.111 | INFO | qlib.workflow.task.manage:run_task:355 - {'model': {'class': 'LGBModel', 'module_path': 'qlib.contrib.model.gbdt'}, 'dataset': {'class': 'DatasetH', 'module_path': 'qlib.data.dataset', 'kwargs': {'handler': {'class': 'Alpha158', 'module_path': 'qlib.contrib.data.handler', 'kwargs': {'start_time': '2008-01-01', 'end_time': '2020-08-01', 'fit_start_time': '2008-01-01', 'fit_end_time': '2014-12-31', 'instruments': 'csi100'}}, 'segments': {'train': (Timestamp('2010-04-23 00:00:00'), Timestamp('2017-05-24 00:00:00')), 'valid': (Timestamp('2017-05-25 00:00:00'), Timestamp('2019-04-08 00:00:00')), 'test': (Timestamp('2019-04-09 00:00:00'), Timestamp('2021-07-12 00:00:00'))}}}, 'record': [{'class': 'SignalRecord', 'module_path': 'qlib.workflow.record_temp'}, {'class': 'SigAnaRecord', 'module_path': 'qlib.workflow.record_temp'}], 'task_key': 'task_lgb'}\n",
|
|
"[8348:MainThread](2021-03-09 15:05:16,072) INFO - qlib.timer - [log.py:81] - Time cost: 54.958s | Loading data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:05:16,466) INFO - qlib.timer - [log.py:81] - Time cost: 0.334s | DropnaLabel Done\n",
|
|
"[8348:MainThread](2021-03-09 15:05:22,281) INFO - qlib.timer - [log.py:81] - Time cost: 5.812s | CSZScoreNorm Done\n",
|
|
"[8348:MainThread](2021-03-09 15:05:22,283) INFO - qlib.timer - [log.py:81] - Time cost: 6.209s | fit & process data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:05:22,286) INFO - qlib.timer - [log.py:81] - Time cost: 61.172s | Init data Done\n",
|
|
"[8348:MainThread](2021-03-09 15:05:22,291) INFO - qlib.workflow - [expm.py:245] - No tracking URI is provided. Use the default tracking URI.\n",
|
|
"[8348:MainThread](2021-03-09 15:05:22,317) INFO - qlib.workflow - [exp.py:181] - Experiment 2 starts running ...\n",
|
|
"[8348:MainThread](2021-03-09 15:05:22,386) INFO - qlib.workflow - [recorder.py:233] - Recorder 0c814539f55842b9b6310843fc5ec708 starts running under Experiment 2 ...\n",
|
|
"Training until validation scores don't improve for 50 rounds\n",
|
|
"[20]\ttrain's l2: 0.969033\tvalid's l2: 0.98571\n",
|
|
"[40]\ttrain's l2: 0.955399\tvalid's l2: 0.986164\n",
|
|
"[60]\ttrain's l2: 0.943514\tvalid's l2: 0.986301\n",
|
|
"Early stopping, best iteration is:\n",
|
|
"[26]\ttrain's l2: 0.964587\tvalid's l2: 0.985356\n",
|
|
"[8348:MainThread](2021-03-09 15:05:29,546) INFO - qlib.workflow - [record_temp.py:126] - Signal record 'pred.pkl' has been saved as the artifact of the Experiment 2\n",
|
|
"'The following are prediction results of the LGBModel model.'\n",
|
|
" score\n",
|
|
"datetime instrument \n",
|
|
"2019-04-09 SH600000 0.029586\n",
|
|
" SH600009 0.004306\n",
|
|
" SH600010 -0.004411\n",
|
|
" SH600011 0.002707\n",
|
|
" SH600015 -0.029124\n",
|
|
"{'IC': 0.020784811232504984,\n",
|
|
" 'ICIR': 0.11590182186569555,\n",
|
|
" 'Rank IC': 0.028925697036767055,\n",
|
|
" 'Rank ICIR': 0.16388058980901396}\n"
|
|
]
|
|
},
|
|
{
|
|
"output_type": "execute_result",
|
|
"data": {
|
|
"text/plain": [
|
|
"True"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"execution_count": 26
|
|
}
|
|
],
|
|
"source": [
|
|
"from qlib.workflow.task.manage import run_task\n",
|
|
"from qlib.workflow.task.collect import TaskCollector\n",
|
|
"from qlib.model.trainer import task_train\n",
|
|
"\n",
|
|
"run_task(task_train, task_pool, experiment_name=exp_name) # all tasks will be trained using \"task_train\" method"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"pycharm": {
|
|
"name": "#%%\n"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stderr",
|
|
"text": [
|
|
"Loading data: 100%|██████████| 4/4 [00:00<00:00, 37.38it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"output_type": "execute_result",
|
|
"data": {
|
|
"text/plain": [
|
|
"{('task_lgb', '2019-04-08'): datetime instrument\n",
|
|
" 2017-01-03 SH600000 -0.013089\n",
|
|
" SH600010 -0.006642\n",
|
|
" SH600015 -0.035137\n",
|
|
" SH600016 -0.034634\n",
|
|
" SH600018 -0.029493\n",
|
|
" ... \n",
|
|
" 2019-04-08 SZ002415 0.049199\n",
|
|
" SZ002450 -0.013450\n",
|
|
" SZ002594 0.022395\n",
|
|
" SZ002736 0.091433\n",
|
|
" SZ300059 -0.016237\n",
|
|
" Name: score, Length: 55000, dtype: float64}"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"execution_count": 27
|
|
}
|
|
],
|
|
"source": [
|
|
"def get_task_key(task):\n",
|
|
" task_key = task[\"task_key\"]\n",
|
|
" rolling_end_timestamp = task[\"dataset\"][\"kwargs\"][\"segments\"][\"test\"][1]\n",
|
|
" #rolling_end_datatime = rolling_end_timestamp.to_pydatetime()\n",
|
|
" return task_key, rolling_end_timestamp.strftime('%Y-%m-%d')\n",
|
|
"\n",
|
|
"def my_filter(task):\n",
|
|
" # only choose the results of \"task_lgb\" and test segment end in 2019 from all tasks\n",
|
|
" task_key, rolling_end = get_task_key(task)\n",
|
|
" if task_key==\"task_lgb\" and rolling_end.startswith('2019'):\n",
|
|
" return True\n",
|
|
" return False\n",
|
|
"\n",
|
|
"# name tasks by \"get_task_key\" and filter tasks by \"my_filter\"\n",
|
|
"pred_rolling = TaskCollector.collect(exp_name, get_task_key, my_filter) \n",
|
|
"pred_rolling"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"pycharm": {
|
|
"name": "#%%\n"
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "3.6.5-final"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
} |