revert pickle reading for historic predictions

This commit is contained in:
Robert Caulk 2022-07-17 16:06:36 +02:00
parent 41eeb99177
commit 921f3899f0
1 changed files with 10 additions and 8 deletions

View File

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