diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index cf7c4151b..3386d2881 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -147,6 +147,9 @@ class IFreqaiModel(ABC): # the concatenated results for the full backtesting period back to the strategy. elif not self.follow_mode: self.dk = FreqaiDataKitchen(self.config, self.live, metadata["pair"]) + dataframe = self.dk.use_strategy_to_populate_indicators( + strategy, prediction_dataframe=dataframe, pair=metadata["pair"] + ) if not self.config.get("freqai_backtest_live_models", False): logger.info(f"Training {len(self.dk.training_timeranges)} timeranges") dk = self.start_backtesting(dataframe, metadata, self.dk) @@ -637,7 +640,7 @@ class IFreqaiModel(ABC): self.dd.historic_predictions[pair] = pred_df hist_preds_df = self.dd.historic_predictions[pair] - self.set_start_dry_live_date(pred_df) + self.set_start_dry_live_date(strat_df) for label in hist_preds_df.columns: if hist_preds_df[label].dtype == object: @@ -680,7 +683,7 @@ class IFreqaiModel(ABC): if self.dd.historic_predictions[dk.pair][label].dtype == object: continue f = spy.stats.norm.fit( - self.dd.historic_predictions[dk.pair][label].fillna(0).tail(num_candles)) + self.dd.historic_predictions[dk.pair][label].tail(num_candles)) dk.data["labels_mean"][label], dk.data["labels_std"][label] = f[0], f[1] return @@ -844,6 +847,7 @@ class IFreqaiModel(ABC): """ fit_live_predictions_candles = self.freqai_info.get("fit_live_predictions_candles", 0) if fit_live_predictions_candles: + logger.info("Applying fit_live_predictions in backtesting") label_columns = [col for col in dk.full_df.columns if ( col.startswith("&") and not (col.startswith("&") and col.endswith("_mean")) and diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index 605485e12..c53137093 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -363,7 +363,8 @@ def test_backtesting_fit_live_predictions(mocker, freqai_conf, caplog): corr_df, base_df = freqai.dd.get_base_and_corr_dataframes(sub_timerange, "LTC/BTC", freqai.dk) df = freqai.dk.use_strategy_to_populate_indicators(strategy, corr_df, base_df, "LTC/BTC") freqai.dk.pair = "ADA/BTC" - freqai.dk.full_df = df + freqai.dk.full_df = df.fillna(0) + freqai.dk.full_df assert "&-s_close_mean" not in freqai.dk.full_df.columns assert "&-s_close_std" not in freqai.dk.full_df.columns freqai.backtesting_fit_live_predictions(freqai.dk)