Skip to content

Commit

Permalink
support check_transform_proc module_path
Browse files Browse the repository at this point in the history
  • Loading branch information
bxdd authored and you-n-g committed Jul 2, 2021
1 parent b523b27 commit 946c939
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
20 changes: 4 additions & 16 deletions examples/highfreq/highfreq_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from qlib.data.dataset.handler import DataHandler, DataHandlerLP
from qlib.data.dataset.processor import Processor
from qlib.utils import get_cls_kwargs
from qlib.log import TimeInspector
from qlib.contrib.data.handler import check_transform_proc



class HighFreqHandler(DataHandlerLP):
Expand All @@ -16,20 +15,9 @@ def __init__(
fit_end_time=None,
drop_raw=True,
):
def check_transform_proc(proc_l):
new_l = []
for p in proc_l:
p["kwargs"].update(
{
"fit_start_time": fit_start_time,
"fit_end_time": fit_end_time,
}
)
new_l.append(p)
return new_l

infer_processors = check_transform_proc(infer_processors)
learn_processors = check_transform_proc(learn_processors)
infer_processors = check_transform_proc(infer_processors, fit_start_time, fit_end_time)
learn_processors = check_transform_proc(learn_processors, fit_start_time, fit_end_time)

data_loader = {
"class": "QlibDataLoader",
Expand Down
2 changes: 1 addition & 1 deletion examples/highfreq/highfreq_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_calendar_day(freq="day", future=False):
if flag in H["c"]:
_calendar = H["c"][flag]
else:
_calendar = np.array(list(map(lambda x: x.date(), Cal.load_calendar(freq, future))))
_calendar = np.array(list(map(lambda x: pd.Timestamp(x.date()), Cal.load_calendar(freq, future))))
H["c"][flag] = _calendar
return _calendar

Expand Down
2 changes: 1 addition & 1 deletion examples/highfreq/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HighfreqWorkflow:
"fit_start_time": start_time,
"fit_end_time": train_end_time,
"instruments": MARKET,
"infer_processors": [{"class": "HighFreqNorm", "module_path": "highfreq_processor", "kwargs": {}}],
"infer_processors": [{"class": "HighFreqNorm", "module_path": "highfreq_processor"}],
}
DATA_HANDLER_CONFIG1 = {
"start_time": start_time,
Expand Down
6 changes: 4 additions & 2 deletions qlib/contrib/data/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def check_transform_proc(proc_l, fit_start_time, fit_end_time):
"fit_end_time": fit_end_time,
}
)
# FIXME: the `module_path` parameter is missed.
new_l.append({"class": klass.__name__, "kwargs": pkwargs})
proc_config = {"class": klass.__name__, "kwargs": pkwargs}
if isinstance(p, dict) and "module_path" in p:
proc_config["module_path"] = p["module_path"]
new_l.append(proc_config)
else:
new_l.append(p)
return new_l
Expand Down

0 comments on commit 946c939

Please sign in to comment.