mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-04 11:30:57 +08:00
fix OPDT_backtest bugs
This commit is contained in:
@@ -89,8 +89,8 @@ and finally start our OPD method.
|
||||
python main.py --config=example/OPD/config.yml
|
||||
```
|
||||
|
||||
### Citation
|
||||
You are more than welcome to cite our paper:
|
||||
## Citation
|
||||
You are more than welcome to citetmu our paper:
|
||||
```
|
||||
@inproceedings{fang2021universal,
|
||||
title={Universal Trading for Order Execution with Oracle Policy Distillation},
|
||||
|
||||
@@ -71,24 +71,22 @@ class RuleObs(BaseObs):
|
||||
if time == -1:
|
||||
predictions += [0.0] * size
|
||||
else:
|
||||
predictions += df.iloc[size * time : size * (time + 1)].reshape(-1).tolist()
|
||||
predictions += df[size * time : size * (time + 1)].reshape(-1).tolist()
|
||||
elif feature["type"] == "daily":
|
||||
predictions += df.reshape(-1)[:size].tolist()
|
||||
elif feature["type"] == "range":
|
||||
# if feature.startswith('oracle'):
|
||||
# predictions += df.iloc[:, (time + 1) : size + (time + 1)].reshape(-1).tolist()
|
||||
if time == -1:
|
||||
predictions += [0.0] * size
|
||||
else:
|
||||
predictions += df.iloc[time : size + time].reshape(-1).tolist()
|
||||
predictions += df[time : size + time].reshape(-1).tolist()
|
||||
elif feature["type"] == "interval":
|
||||
if len(df.iloc[interval * size : (interval + 1) * size].reshape(-1)) == size:
|
||||
predictions += df.iloc[interval * size : (interval + 1) * size].reshape(-1).tolist()
|
||||
if len(df[interval * size : (interval + 1) * size].reshape(-1)) == size:
|
||||
predictions += df[interval * size : (interval + 1) * size].reshape(-1).tolist()
|
||||
else:
|
||||
predictions += [0.0] * size
|
||||
elif feature["type"] == "step":
|
||||
if len(df.iloc[size * (time + 1) : size * (time + 2)].reshape(-1)) == size:
|
||||
predictions += df.iloc[size * (time + 1) : size * (time + 2)].reshape(-1).tolist()
|
||||
if len(df[size * (time + 1) : size * (time + 2)].reshape(-1)) == size:
|
||||
predictions += df[size * (time + 1) : size * (time + 2)].reshape(-1).tolist()
|
||||
else:
|
||||
predictions += [0.0] * size
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ def w_order(f, start, end):
|
||||
all_path = os.path.join(data_path, "order/all/")
|
||||
if not os.path.exists(all_path):
|
||||
os.makedirs(all_path)
|
||||
order_test.to_pickle(all_path + f[:-9] + '.target')
|
||||
order.to_pickle(all_path + f[:-9] + '.target')
|
||||
return 0
|
||||
|
||||
res = Parallel(n_jobs=64)(delayed(w_order)(f, 0, 239) for f in os.listdir(in_dir))
|
||||
|
||||
@@ -6,13 +6,14 @@ feature_path = os.path.join(data_path, 'feature/teacher/')
|
||||
if not os.path.exists(feature_path):
|
||||
os.makedirs(feature_path)
|
||||
|
||||
log_file = os.path.join(os.environ.get('OUTPUT_DIR'),'example/OPDT_b/0/test/')
|
||||
log_file = os.path.join(os.environ.get('OUTPUT_DIR'),'example/OPDT_b/test/')
|
||||
files = os.listdir(log_file)
|
||||
|
||||
for f in files:
|
||||
if f.endswith(".log"):
|
||||
df = pd.read_pickle(log_file + f)
|
||||
df['datetime'] = df.index.get_level_values(1).map(lambda x: x[1])
|
||||
#df['datetime'] = df.index.get_level_values(1).map(lambda x: x[1])
|
||||
df['datetime'] = df.index.get_level_values(1)
|
||||
df.set_index('datetime', append=True, drop=True, inplace=True)
|
||||
action = df['action']
|
||||
action = action.reset_index(level=1, drop=True)
|
||||
|
||||
Reference in New Issue
Block a user