From e6dfccce2f64daed27381ae02d0e92bf12574623 Mon Sep 17 00:00:00 2001 From: Mingzhe Han Date: Wed, 24 Feb 2021 13:44:20 +0800 Subject: [PATCH] fix OPDT_backtest bugs --- examples/trade/README.md | 4 ++-- examples/trade/observation/obs_rule.py | 14 ++++++-------- examples/trade/order_gen.py | 2 +- examples/trade/teacher_feature.py | 5 +++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/trade/README.md b/examples/trade/README.md index 5b621c37a..8add4ecf0 100644 --- a/examples/trade/README.md +++ b/examples/trade/README.md @@ -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}, diff --git a/examples/trade/observation/obs_rule.py b/examples/trade/observation/obs_rule.py index 679a67e0a..350c79934 100644 --- a/examples/trade/observation/obs_rule.py +++ b/examples/trade/observation/obs_rule.py @@ -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 diff --git a/examples/trade/order_gen.py b/examples/trade/order_gen.py index 898aaab7c..f0fa38e0d 100644 --- a/examples/trade/order_gen.py +++ b/examples/trade/order_gen.py @@ -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)) diff --git a/examples/trade/teacher_feature.py b/examples/trade/teacher_feature.py index d605fb74e..62e69ceba 100644 --- a/examples/trade/teacher_feature.py +++ b/examples/trade/teacher_feature.py @@ -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)