1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-06-06 05:51:17 +08:00

Add Qlib notebook tutorial (#1037)

* Add Qlib notebook tutorial

* Update tutorial
This commit is contained in:
you-n-g
2022-04-08 21:29:41 +08:00
committed by GitHub
parent 7f1293ec34
commit 2952c443ca
7 changed files with 1239 additions and 7 deletions

View File

@@ -386,6 +386,8 @@ Dataset plays a very important role in Quant. Here is a list of the datasets bui
Your PR to build new Quant dataset is highly welcomed. Your PR to build new Quant dataset is highly welcomed.
# More About Qlib # More About Qlib
If you want to have a quick glance at the most frequently used components of qlib, you can try notebooks [here](examples/tutorial/).
The detailed documents are organized in [docs](docs/). The detailed documents are organized in [docs](docs/).
[Sphinx](http://www.sphinx-doc.org) and the readthedocs theme is required to build the documentation in html formats. [Sphinx](http://www.sphinx-doc.org) and the readthedocs theme is required to build the documentation in html formats.
```bash ```bash
@@ -471,8 +473,10 @@ If you don't know how to start to contribute, you can refer to the following exa
| Models | [Implement a new model](https://github.com/microsoft/qlib/pull/689) | | Models | [Implement a new model](https://github.com/microsoft/qlib/pull/689) |
[Good first issues](https://github.com/microsoft/qlib/labels/good%20first%20issue) are labelled to indicate that they are easy to start your contributions. [Good first issues](https://github.com/microsoft/qlib/labels/good%20first%20issue) are labelled to indicate that they are easy to start your contributions.
You can find some impefect implementation in Qlib by `rg 'TODO|FIXME' qlib`
If you would like to become one of Qlib's maintainers to contribute more (e.g. help merge PR, triage issues), please contact us by email([qlib@microsoft.com](mailto:qlib@microsoft.com)). We are glad to help you to set the right permission. If you would like to become one of Qlib's maintainers to contribute more (e.g. help merge PR, triage issues), please contact us by email([qlib@microsoft.com](mailto:qlib@microsoft.com)). We are glad to help to upgrade your permission.
## Licence ## Licence
Most contributions require you to agree to a Most contributions require you to agree to a

File diff suppressed because it is too large Load Diff

View File

@@ -256,7 +256,6 @@
"recorder = R.get_recorder(recorder_id=ba_rid, experiment_name=\"backtest_analysis\")\n", "recorder = R.get_recorder(recorder_id=ba_rid, experiment_name=\"backtest_analysis\")\n",
"print(recorder)\n", "print(recorder)\n",
"pred_df = recorder.load_object(\"pred.pkl\")\n", "pred_df = recorder.load_object(\"pred.pkl\")\n",
"pred_df_dates = pred_df.index.get_level_values(level='datetime')\n",
"report_normal_df = recorder.load_object(\"portfolio_analysis/report_normal_1day.pkl\")\n", "report_normal_df = recorder.load_object(\"portfolio_analysis/report_normal_1day.pkl\")\n",
"positions = recorder.load_object(\"portfolio_analysis/positions_normal_1day.pkl\")\n", "positions = recorder.load_object(\"portfolio_analysis/positions_normal_1day.pkl\")\n",
"analysis_df = recorder.load_object(\"portfolio_analysis/port_analysis_1day.pkl\")" "analysis_df = recorder.load_object(\"portfolio_analysis/port_analysis_1day.pkl\")"

View File

@@ -10,17 +10,19 @@ try:
from .gbdt import LGBModel from .gbdt import LGBModel
except ModuleNotFoundError: except ModuleNotFoundError:
DEnsembleModel, LGBModel = None, None DEnsembleModel, LGBModel = None, None
print("Please install necessary libs for DEnsembleModel and LGBModel, such as lightgbm.") print(
"ModuleNotFoundError. DEnsembleModel and LGBModel are skipped. (optional: maybe installing lightgbm can fix it.)"
)
try: try:
from .xgboost import XGBModel from .xgboost import XGBModel
except ModuleNotFoundError: except ModuleNotFoundError:
XGBModel = None XGBModel = None
print("Please install necessary libs for XGBModel, such as xgboost.") print("ModuleNotFoundError. XGBModel is skipped(optional: maybe installing xgboost can fix it).")
try: try:
from .linear import LinearModel from .linear import LinearModel
except ModuleNotFoundError: except ModuleNotFoundError:
LinearModel = None LinearModel = None
print("Please install necessary libs for LinearModel, such as scipy and sklearn.") print("ModuleNotFoundError. LinearModel is skipped(optional: maybe installing scipy and sklearn can fix it).")
# import pytorch models # import pytorch models
try: try:
from .pytorch_alstm import ALSTM from .pytorch_alstm import ALSTM
@@ -36,6 +38,6 @@ try:
pytorch_classes = (ALSTM, GATs, GRU, LSTM, DNNModelPytorch, TabnetModel, SFM_Model, TCN, ADD) pytorch_classes = (ALSTM, GATs, GRU, LSTM, DNNModelPytorch, TabnetModel, SFM_Model, TCN, ADD)
except ModuleNotFoundError: except ModuleNotFoundError:
pytorch_classes = () pytorch_classes = ()
print("Please install necessary libs for PyTorch models.") print("ModuleNotFoundError. PyTorch models are skipped (optional: maybe installing pytorch can fix it).")
all_model_classes = (CatBoostModel, DEnsembleModel, LGBModel, XGBModel, LinearModel) + pytorch_classes all_model_classes = (CatBoostModel, DEnsembleModel, LGBModel, XGBModel, LinearModel) + pytorch_classes

View File

@@ -199,6 +199,9 @@ class DatasetH(Dataset):
col_set : str col_set : str
The col_set will be passed to self.handler when fetching data. The col_set will be passed to self.handler when fetching data.
TODO: make it automatic:
- select DK_I for test data
- select DK_L for training data.
data_key : str data_key : str
The data to fetch: DK_* The data to fetch: DK_*
Default is DK_I, which indicate fetching data for **inference**. Default is DK_I, which indicate fetching data for **inference**.

View File

@@ -43,6 +43,11 @@ def sys_config(config, config_path):
# workflow handler function # workflow handler function
def workflow(config_path, experiment_name="workflow", uri_folder="mlruns"): def workflow(config_path, experiment_name="workflow", uri_folder="mlruns"):
"""
This is a Qlib CLI entrance.
User can run the whole Quant research workflow defined by a configure file
- the code is located here ``qlib/workflow/cli.py`
"""
with open(config_path) as fp: with open(config_path) as fp:
config = yaml.safe_load(fp) config = yaml.safe_load(fp)

View File

@@ -6,4 +6,5 @@ pandas
lxml lxml
loguru loguru
baostock baostock
yahooquery yahooquery
beautifulsoup4