diff --git a/README.md b/README.md index cd0c8542f..9a4d2d868 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,11 @@ For more details, please refer to our paper ["Qlib: An AI-oriented Quantitative At the module level, Qlib is a platform that consists of the above components. The components are designed as loose-coupled modules and each component could be used stand-alone. -| Name | Description | -| ------ | ----- | -| `Data layer` | `DataServer` focuses on providing high-performance infrastructure for users to manage and retrieve raw data. `DataEnhancement` will preprocess the data and provide the best dataset to be fed into the models. | -| `Interday Model` | `Interday model` focuses on producing prediction scores (aka. _alpha_). Models are trained by `Model Creator` and managed by `Model Manager`. Users could choose one or multiple models for prediction. Multiple models could be combined with `Ensemble` module. | -| `Interday Strategy` | `Portfolio Generator` will take prediction scores as input and output the orders based on the current position to achieve the target portfolio. | -| `Intraday Trading` | `Order Executor` is responsible for executing orders output by `Interday Strategy` and returning the executed results. | -| `Analysis` | Users could get a detailed analysis report of forecasting signals and portfolios in this part. | +| Name | Description | +| ------ | ----- | +| `Infrastructure` layer | `Infrastructure` layer provides underlying support for Quant research. `DataServer` provides high-performance infrastructure for users to manage and retrieve raw data. `Trainer` provides flexible interface to control the training process of models which enable algorithms controlling the training process. | +| `Workflow` layer | `Workflow` layer covers the whole workflow of quantitative investment. `Information Extractor` extracts data for models. `Forecast Model` focuses on producing all kinds of forecast signals (e.g. _alpha_, risk) for other modules. With these signals `Portfolio Generator` will generate the target portfolio and produce orders to be executed by `Order Executor`. | +| `Interface` layer | `Interface` layer tries to present a user-friendly interface for the underlying system. `Analyser` module will provide users detailed analysis reports of forecasting signals, portfolios and execution results | * The modules with hand-drawn style are under development and will be released in the future. * The modules with dashed borders are highly user-customizable and extendible. diff --git a/docs/_static/img/framework.png b/docs/_static/img/framework.png index 673f10e03..d8242f7c1 100644 Binary files a/docs/_static/img/framework.png and b/docs/_static/img/framework.png differ diff --git a/qlib/model/trainer.py b/qlib/model/trainer.py new file mode 100644 index 000000000..e4fc8eef9 --- /dev/null +++ b/qlib/model/trainer.py @@ -0,0 +1,40 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +from qlib.utils import init_instance_by_config, flatten_dict +from qlib.workflow import R +from qlib.workflow.record_temp import SignalRecord + + +def task_train(config: dict, experiment_name): + """ + task based training + + Parameters + ---------- + config : dict + A dict describing the training process + """ + + # model initiaiton + model = init_instance_by_config(config.get("task")["model"]) + dataset = init_instance_by_config(config.get("task")["dataset"]) + + # start exp + with R.start(experiment_name=experiment_name): + # train model + R.log_params(**flatten_dict(config.get("task"))) + model.fit(dataset) + recorder = R.get_recorder() + + # generate records: prediction, backtest, and analysis + for record in config.get("task")["record"]: + if record["class"] == SignalRecord.__name__: + srconf = {"model": model, "dataset": dataset, "recorder": recorder} + record["kwargs"].update(srconf) + sr = init_instance_by_config(record) + sr.generate() + else: + rconf = {"recorder": recorder} + record["kwargs"].update(rconf) + ar = init_instance_by_config(record) + ar.generate() diff --git a/qlib/workflow/cli.py b/qlib/workflow/cli.py index 4c02f0592..b9c040e87 100644 --- a/qlib/workflow/cli.py +++ b/qlib/workflow/cli.py @@ -8,9 +8,7 @@ import qlib import fire import pandas as pd import ruamel.yaml as yaml -from qlib.utils import init_instance_by_config, flatten_dict -from qlib.workflow import R -from qlib.workflow.record_temp import SignalRecord +from ..model.trainer import task_train def get_path_list(path): @@ -54,29 +52,7 @@ def workflow(config_path, experiment_name="workflow"): region = config.get("region") qlib.init(provider_uri=provider_uri, region=region) - # model initiaiton - model = init_instance_by_config(config.get("task")["model"]) - dataset = init_instance_by_config(config.get("task")["dataset"]) - - # start exp - with R.start(experiment_name=experiment_name): - # train model - R.log_params(**flatten_dict(config.get("task"))) - model.fit(dataset) - recorder = R.get_recorder() - - # generate records: prediction, backtest, and analysis - for record in config.get("task")["record"]: - if record["class"] == SignalRecord.__name__: - srconf = {"model": model, "dataset": dataset, "recorder": recorder} - record["kwargs"].update(srconf) - sr = init_instance_by_config(record) - sr.generate() - else: - rconf = {"recorder": recorder} - record["kwargs"].update(rconf) - ar = init_instance_by_config(record) - ar.generate() + task_train(config, experiment_name=experiment_name) # function to run worklflow by config