1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-16 17:12:20 +08:00

Add filter_pipe API

This commit is contained in:
Jactus
2021-01-26 12:33:36 +08:00
committed by you-n-g
parent 828993b397
commit c0e7cbc983
2 changed files with 18 additions and 2 deletions

View File

@@ -54,6 +54,7 @@ class Alpha360(DataHandlerLP):
learn_processors=_DEFAULT_LEARN_PROCESSORS, learn_processors=_DEFAULT_LEARN_PROCESSORS,
fit_start_time=None, fit_start_time=None,
fit_end_time=None, fit_end_time=None,
filter_pipe=None,
**kwargs, **kwargs,
): ):
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time) infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
@@ -66,6 +67,7 @@ class Alpha360(DataHandlerLP):
"feature": self.get_feature_config(), "feature": self.get_feature_config(),
"label": kwargs.get("label", self.get_label_config()), "label": kwargs.get("label", self.get_label_config()),
}, },
"filter_pipe": filter_pipe,
}, },
} }
@@ -138,6 +140,7 @@ class Alpha158(DataHandlerLP):
fit_start_time=None, fit_start_time=None,
fit_end_time=None, fit_end_time=None,
process_type=DataHandlerLP.PTYPE_A, process_type=DataHandlerLP.PTYPE_A,
filter_pipe=None,
**kwargs, **kwargs,
): ):
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time) infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
@@ -146,7 +149,11 @@ class Alpha158(DataHandlerLP):
data_loader = { data_loader = {
"class": "QlibDataLoader", "class": "QlibDataLoader",
"kwargs": { "kwargs": {
"config": {"feature": self.get_feature_config(), "label": kwargs.get("label", self.get_label_config())}, "config": {
"feature": self.get_feature_config(),
"label": kwargs.get("label", self.get_label_config()),
},
"filter_pipe": filter_pipe,
}, },
} }
super().__init__( super().__init__(

View File

@@ -10,7 +10,9 @@ import pandas as pd
from typing import Tuple, Union from typing import Tuple, Union
from qlib.data import D from qlib.data import D
from qlib.utils import load_dataset from qlib.data import filter as filter_module
from qlib.data.filter import BaseDFilter
from qlib.utils import load_dataset, init_instance_by_config
class DataLoader(abc.ABC): class DataLoader(abc.ABC):
@@ -145,6 +147,13 @@ class QlibDataLoader(DLWParser):
swap_level : swap_level :
Whether to swap level of MultiIndex Whether to swap level of MultiIndex
""" """
if filter_pipe is not None:
assert isinstance(filter_pipe, list), "The type of `filter_pipe` must be list."
filter_pipe = [
init_instance_by_config(fp, None if "module_path" in fp else filter_module, accept_types=BaseDFilter)
for fp in filter_pipe
]
self.filter_pipe = filter_pipe self.filter_pipe = filter_pipe
self.swap_level = swap_level self.swap_level = swap_level
super().__init__(config) super().__init__(config)