{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[95290:MainThread](2021-03-03 12:14:32,922) INFO - qlib.Initialization - [config.py:276] - default_conf: client.\n",
      "[95290:MainThread](2021-03-03 12:14:32,925) WARNING - qlib.Initialization - [config.py:291] - redis connection failed(host=127.0.0.1 port=6379), cache will not be used!\n",
      "[95290:MainThread](2021-03-03 12:14:33,203) INFO - qlib.Initialization - [__init__.py:46] - qlib successfully initialized based on client settings.\n",
      "[95290:MainThread](2021-03-03 12:14:33,205) INFO - qlib.Initialization - [__init__.py:47] - data_path=/Users/xuanyidong/.qlib/qlib_data/cn_data\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "import qlib\n",
    "import pprint\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "from qlib import config as qconfig\n",
    "from qlib.utils import init_instance_by_config\n",
    "\n",
    "qlib.init(provider_uri='~/.qlib/qlib_data/cn_data', region=qconfig.REG_CN)\n",
    "\n",
    "dataset_config = {\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\": {\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\": \"csi300\",\n",
    "                    },\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",
    "        }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'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': 'csi300',\n",
      "                                   'start_time': '2008-01-01'},\n",
      "                        'module_path': 'qlib.contrib.data.handler'},\n",
      "            'segments': {'test': ('2017-01-01', '2020-08-01'),\n",
      "                         'train': ('2008-01-01', '2014-12-31'),\n",
      "                         'valid': ('2015-01-01', '2016-12-31')}},\n",
      " 'module_path': 'qlib.data.dataset'}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[95290:MainThread](2021-03-03 12:18:43,481) INFO - qlib.timer - [log.py:81] - Time cost: 237.911s | Loading data Done\n",
      "[95290:MainThread](2021-03-03 12:18:45,080) INFO - qlib.timer - [log.py:81] - Time cost: 0.465s | DropnaLabel Done\n",
      "[95290:MainThread](2021-03-03 12:18:51,572) INFO - qlib.timer - [log.py:81] - Time cost: 6.491s | CSZScoreNorm Done\n",
      "[95290:MainThread](2021-03-03 12:18:51,573) INFO - qlib.timer - [log.py:81] - Time cost: 8.090s | fit & process data Done\n",
      "[95290:MainThread](2021-03-03 12:18:51,573) INFO - qlib.timer - [log.py:81] - Time cost: 246.003s | Init data Done\n"
     ]
    }
   ],
   "source": [
    "pprint.pprint(dataset_config)\n",
    "dataset = init_instance_by_config(dataset_config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'class': 'MLflowExpManager', 'module_path': 'qlib.workflow.expm', 'kwargs': {'uri': 'file:/Users/xuanyidong/Desktop/AutoDL-Projects/notebooks/Q/mlruns', 'default_exp_name': 'Experiment'}}\n",
      "Wrapper(provider=<qlib.workflow.QlibRecorder object at 0x7ff46b8a4850>)\n",
      "<qlib.workflow.expm.MLflowExpManager object at 0x7ff46b8a4c10>\n"
     ]
    }
   ],
   "source": [
    "from qlib.workflow import R\n",
    "from qlib.config import C\n",
    "print(C.exp_manager)\n",
    "print(R)\n",
    "print(R.exp_manager)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}