From 921f3899f062e042cd9fd26c48263405fb63871c Mon Sep 17 00:00:00 2001 From: Robert Caulk Date: Sun, 17 Jul 2022 16:06:36 +0200 Subject: [PATCH] revert pickle reading for historic predictions --- freqtrade/freqai/data_drawer.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/freqtrade/freqai/data_drawer.py b/freqtrade/freqai/data_drawer.py index 41736c154..5488a7e6b 100644 --- a/freqtrade/freqai/data_drawer.py +++ b/freqtrade/freqai/data_drawer.py @@ -78,7 +78,7 @@ class FreqaiDataDrawer: """ exists = Path(self.full_path / str("historic_predictions.pkl")).resolve().exists() if exists: - with open(self.full_path / str("historic_predictions.pkl"), "wb") as fp: + with open(self.full_path / str("historic_predictions.pkl"), "rb") as fp: self.historic_predictions = pickle.load(fp) logger.info(f"Found existing historic predictions at {self.full_path}, but beware " "that statistics may be inaccurate if the bot has been offline for " @@ -235,13 +235,14 @@ class FreqaiDataDrawer: i = length_difference + 1 df = self.model_return_values[pair] = self.model_return_values[pair].shift(-i) - hp_df = self.historic_predictions[pair] - # here are some pandas hula hoops to accommodate the possibility of a series - # or dataframe depending number of labels requested by user - nan_df = pd.DataFrame(np.nan, index=hp_df.index[-2:] + 2, columns=hp_df.columns) - hp_df = pd.concat([hp_df, nan_df], ignore_index=True, axis=0) - hp_df = pd.concat([hp_df, nan_df[-2:-1]], axis=0) + if pair in self.historic_predictions: + hp_df = self.historic_predictions[pair] + # here are some pandas hula hoops to accommodate the possibility of a series + # or dataframe depending number of labels requested by user + nan_df = pd.DataFrame(np.nan, index=hp_df.index[-2:] + 2, columns=hp_df.columns) + hp_df = pd.concat([hp_df, nan_df], ignore_index=True, axis=0) + self.historic_predictions[pair] = hp_df[:-1] for label in dk.label_list: df[label].iloc[-1] = predictions[label].iloc[-1] @@ -254,7 +255,8 @@ class FreqaiDataDrawer: df["DI_values"].iloc[-1] = dk.DI_values[-1] # append the new predictions to persistent storage - hp_df.iloc[-1] = df[label].iloc[-1] + if pair in self.historic_predictions: + self.historic_predictions[pair].iloc[-1] = df[label].iloc[-1] if length_difference < 0: prepend_df = pd.DataFrame(