1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-13 07:46:53 +08:00

Add inst_processors to D.features

This commit is contained in:
zhupr
2021-08-29 23:13:24 +08:00
committed by you-n-g
parent d1cbf4c3d9
commit 3605cd7b96
7 changed files with 258 additions and 107 deletions

View File

@@ -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