mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-09 22:10:56 +08:00
Add inst_processors to D.features
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import datetime
|
||||
import pandas as pd
|
||||
|
||||
from qlib.data.inst_processor import InstProcessor
|
||||
|
||||
def resample_feature(df: pd.DataFrame) -> pd.DataFrame:
|
||||
df = df.droplevel(level="instrument")
|
||||
df = df.loc[df.index.time == datetime.time(13, 1)]
|
||||
df.index = df.index.normalize()
|
||||
return df
|
||||
|
||||
class ResampleProcessor(InstProcessor):
|
||||
def __init__(self, freq: str, hour: int, minute: int):
|
||||
self.freq = freq
|
||||
self.hour = hour
|
||||
self.minute = minute
|
||||
|
||||
def __call__(self, df: pd.DataFrame, *args, **kwargs):
|
||||
df = df.loc[df.index.time == datetime.time(self.hour, self.minute)]
|
||||
df.index = df.index.normalize()
|
||||
return df
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
qlib_init:
|
||||
provider_uri: "~/.qlib/qlib_data/cn_data"
|
||||
backend_freq_config:
|
||||
provider_uri:
|
||||
day: "~/.qlib/qlib_data/cn_data"
|
||||
1min: "~/.qlib/qlib_data/cn_data_1min"
|
||||
region: cn
|
||||
@@ -19,13 +18,14 @@ data_handler_config: &data_handler_config
|
||||
# with label as reference
|
||||
sample_benchmark: label
|
||||
sample_config:
|
||||
# using pandas.DataFrame.resample
|
||||
feature: resample("1d", level="datetime").last()
|
||||
# or
|
||||
# using custom function, df.groupby(level="instrument").apply(<user func>)
|
||||
# feature:
|
||||
# module_path: features_sample.py
|
||||
# func: resample_feature
|
||||
feature:
|
||||
- class: ResampleProcessor
|
||||
moudle_path: features_sample.py
|
||||
kwargs:
|
||||
freq: 1d
|
||||
hour: 13
|
||||
minute: 1
|
||||
|
||||
port_analysis_config: &port_analysis_config
|
||||
strategy:
|
||||
class: TopkDropoutStrategy
|
||||
|
||||
Reference in New Issue
Block a user