mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-10 22:36:55 +08:00
format
This commit is contained in:
@@ -37,9 +37,7 @@ class Sampler:
|
||||
def __init__(self, config):
|
||||
self.raw_dir = config["raw_dir"] + "/"
|
||||
self.order_dir = config["order_dir"] + "/"
|
||||
self.ins_list = [
|
||||
f[:-11] for f in os.listdir(self.order_dir) if f.endswith("target")
|
||||
]
|
||||
self.ins_list = [f[:-11] for f in os.listdir(self.order_dir) if f.endswith("target")]
|
||||
self.features = config["features"]
|
||||
self.queue = Queue(1000)
|
||||
self.child = None
|
||||
@@ -60,9 +58,7 @@ class Sampler:
|
||||
order_df = pd.read_pickle(order_dir + ins + ".pkl.target")
|
||||
feature_df_list = []
|
||||
for feature in features:
|
||||
feature_df_list.append(
|
||||
pd.read_pickle(f"{feature['loc']}/{ins}.pkl")
|
||||
)
|
||||
feature_df_list.append(pd.read_pickle(f"{feature['loc']}/{ins}.pkl"))
|
||||
raw_df = pd.read_pickle(raw_dir + ins + ".pkl.backtest")
|
||||
date_list = order_df.index.get_level_values(0).tolist()
|
||||
index = 0
|
||||
@@ -81,16 +77,7 @@ class Sampler:
|
||||
day_raw_df_index, day_raw_df_value, day_raw_df_column = toArray(day_raw_df)
|
||||
day_feature_dfs_ = toArray(day_feature_dfs)
|
||||
queue.put(
|
||||
(
|
||||
ins,
|
||||
date,
|
||||
day_raw_df_value,
|
||||
day_raw_df_column,
|
||||
day_raw_df_index,
|
||||
day_feature_dfs_,
|
||||
target,
|
||||
is_buy,
|
||||
),
|
||||
(ins, date, day_raw_df_value, day_raw_df_column, day_raw_df_index, day_feature_dfs_, target, is_buy,),
|
||||
block=True,
|
||||
)
|
||||
|
||||
@@ -103,13 +90,7 @@ class Sampler:
|
||||
if self.child is None:
|
||||
self.child = Process(
|
||||
target=self._worker,
|
||||
args=(
|
||||
self.order_dir,
|
||||
self.raw_dir,
|
||||
self.features,
|
||||
self.ins_list,
|
||||
self.queue,
|
||||
),
|
||||
args=(self.order_dir, self.raw_dir, self.features, self.ins_list, self.queue,),
|
||||
daemon=True,
|
||||
)
|
||||
self.child.start()
|
||||
@@ -164,9 +145,7 @@ class TestSampler(Sampler):
|
||||
for df in df_list:
|
||||
day_df_list.append(df.loc[ins, date].values)
|
||||
day_feature_dfs = np.array(day_df_list)
|
||||
day_raw_df_index, day_raw_df_value, day_raw_df_column = toArray(
|
||||
day_raw_df
|
||||
)
|
||||
day_raw_df_index, day_raw_df_value, day_raw_df_column = toArray(day_raw_df)
|
||||
day_feature_dfs_ = toArray(day_feature_dfs)
|
||||
queue.put(
|
||||
(
|
||||
@@ -192,22 +171,14 @@ class TestSampler(Sampler):
|
||||
"""
|
||||
if order_dir:
|
||||
self.order_dir = order_dir
|
||||
self.ins_list = [
|
||||
f[:-11] for f in os.listdir(self.order_dir) if f.endswith("target")
|
||||
]
|
||||
self.ins_list = [f[:-11] for f in os.listdir(self.order_dir) if f.endswith("target")]
|
||||
if not self.child is None:
|
||||
self.child.terminate()
|
||||
while not self.queue.empty():
|
||||
self.queue.get()
|
||||
self.child = Process(
|
||||
target=self._worker,
|
||||
args=(
|
||||
self.order_dir,
|
||||
self.raw_dir,
|
||||
self.features,
|
||||
self.ins_list,
|
||||
self.queue,
|
||||
),
|
||||
args=(self.order_dir, self.raw_dir, self.features, self.ins_list, self.queue,),
|
||||
daemon=True,
|
||||
)
|
||||
self.child.start()
|
||||
|
||||
Reference in New Issue
Block a user