From f1e831a7b8acfcdab524b8325a961fe5491c862c Mon Sep 17 00:00:00 2001 From: robcaulk Date: Sun, 26 Mar 2023 13:43:59 +0200 Subject: [PATCH] fix bug in backtest target setting --- freqtrade/freqai/data_kitchen.py | 8 ++++---- freqtrade/freqai/freqai_interface.py | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index 52d487b08..21b41db2d 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -1291,7 +1291,7 @@ class FreqaiDataKitchen: return dataframe - def use_strategy_to_populate_indicators( + def use_strategy_to_populate_indicators( # noqa: C901 self, strategy: IStrategy, corr_dataframes: dict = {}, @@ -1362,12 +1362,12 @@ class FreqaiDataKitchen: dataframe = self.populate_features(dataframe.copy(), corr_pair, strategy, corr_dataframes, base_dataframes, True) - dataframe = strategy.set_freqai_targets(dataframe.copy(), metadata=metadata) + if self.live: + dataframe = strategy.set_freqai_targets(dataframe.copy(), metadata=metadata) + dataframe = self.remove_special_chars_from_feature_names(dataframe) self.get_unique_classes_from_labels(dataframe) - dataframe = self.remove_special_chars_from_feature_names(dataframe) - if self.config.get('reduce_df_footprint', False): dataframe = reduce_dataframe_footprint(dataframe) diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index b657bd811..fe62adea9 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -306,7 +306,7 @@ class IFreqaiModel(ABC): if check_features: self.dd.load_metadata(dk) dataframe_dummy_features = self.dk.use_strategy_to_populate_indicators( - strategy, prediction_dataframe=dataframe.tail(1), pair=metadata["pair"] + strategy, prediction_dataframe=dataframe.tail(1), pair=pair ) dk.find_features(dataframe_dummy_features) self.check_if_feature_list_matches_strategy(dk) @@ -316,7 +316,7 @@ class IFreqaiModel(ABC): else: if populate_indicators: dataframe = self.dk.use_strategy_to_populate_indicators( - strategy, prediction_dataframe=dataframe, pair=metadata["pair"] + strategy, prediction_dataframe=dataframe, pair=pair ) populate_indicators = False @@ -332,6 +332,9 @@ class IFreqaiModel(ABC): dataframe_train = dk.slice_dataframe(tr_train, dataframe_base_train) dataframe_backtest = dk.slice_dataframe(tr_backtest, dataframe_base_backtest) + dataframe_train = dk.remove_special_chars_from_feature_names(dataframe_train) + dataframe_backtest = dk.remove_special_chars_from_feature_names(dataframe_backtest) + if not self.model_exists(dk): dk.find_features(dataframe_train) dk.find_labels(dataframe_train)