From 23b6915dde7364ec8387655380d9d3d7c46c3fba Mon Sep 17 00:00:00 2001 From: Wagner Costa Santos Date: Wed, 2 Nov 2022 15:49:51 -0300 Subject: [PATCH 1/2] fix issue with different backtesting prediction size --- freqtrade/freqai/data_kitchen.py | 24 +++++++++++++++++------- freqtrade/freqai/freqai_interface.py | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index f0e24dd80..581ab78c0 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -1312,14 +1312,16 @@ class FreqaiDataKitchen: append_df = pd.read_hdf(self.backtesting_results_path) return append_df - def check_if_backtest_prediction_exists( - self + def check_if_backtest_prediction_is_valid( + self, + length_backtesting_dataframe: int ) -> bool: """ - Check if a backtesting prediction already exists - :param dk: FreqaiDataKitchen + Check if a backtesting prediction already exists and if the predictions + to append has the same sime of backtesting dataframe slice + :param length_backtesting_dataframe: Length of backtesting dataframe slice :return: - :boolean: whether the prediction file exists or not. + :boolean: whether the prediction file is valid. """ path_to_predictionfile = Path(self.full_path / self.backtest_predictions_folder / @@ -1327,10 +1329,18 @@ class FreqaiDataKitchen: self.backtesting_results_path = path_to_predictionfile file_exists = path_to_predictionfile.is_file() + if file_exists: - logger.info(f"Found backtesting prediction file at {path_to_predictionfile}") + append_df = self.get_backtesting_prediction() + if len(append_df) == length_backtesting_dataframe: + logger.info(f"Found backtesting prediction file at {path_to_predictionfile}") + return True + else: + logger.info("A new backtesting prediction file is required. " + "(Number of predictions is different of dataframe length).") + return False else: logger.info( f"Could not find backtesting prediction file at {path_to_predictionfile}" ) - return file_exists + return False diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index dcf902954..af158990b 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -275,7 +275,7 @@ class IFreqaiModel(ABC): dk.set_new_model_names(pair, trained_timestamp) - if dk.check_if_backtest_prediction_exists(): + if dk.check_if_backtest_prediction_is_valid(len(dataframe_backtest)): self.dd.load_metadata(dk) dk.find_features(dataframe_train) self.check_if_feature_list_matches_strategy(dk) From 3ba1e221eb5f12686f1a48ace1cebd90705beacd Mon Sep 17 00:00:00 2001 From: robcaulk Date: Thu, 3 Nov 2022 19:08:33 +0100 Subject: [PATCH 2/2] fix typo --- freqtrade/freqai/data_kitchen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index 581ab78c0..e06709b2c 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -1318,7 +1318,7 @@ class FreqaiDataKitchen: ) -> bool: """ Check if a backtesting prediction already exists and if the predictions - to append has the same sime of backtesting dataframe slice + to append has the same size of backtesting dataframe slice :param length_backtesting_dataframe: Length of backtesting dataframe slice :return: :boolean: whether the prediction file is valid. @@ -1337,7 +1337,7 @@ class FreqaiDataKitchen: return True else: logger.info("A new backtesting prediction file is required. " - "(Number of predictions is different of dataframe length).") + "(Number of predictions is different from dataframe length).") return False else: logger.info(