From 5bfda534b2dbb98b3e17f529d836b99a7a16ec05 Mon Sep 17 00:00:00 2001 From: robcaulk Date: Fri, 19 Jan 2024 17:46:34 +0100 Subject: [PATCH] feat: allow custom user features to be plotted in backtesting (freqai) --- freqtrade/freqai/data_kitchen.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index 6d4d6c8dc..56d09ca61 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -432,8 +432,12 @@ class FreqaiDataKitchen: if self.freqai_config["feature_parameters"].get("DI_threshold", 0) > 0: append_df["DI_values"] = self.DI_values + user_cols = [col for col in dataframe_backtest.columns if col.startswith("%%")] + cols = ["date"] + cols.extend(user_cols) + dataframe_backtest.reset_index(drop=True, inplace=True) - merged_df = pd.concat([dataframe_backtest["date"], append_df], axis=1) + merged_df = pd.concat([dataframe_backtest[cols], append_df], axis=1) return merged_df def append_predictions(self, append_df: DataFrame) -> None: @@ -451,7 +455,8 @@ class FreqaiDataKitchen: Back fill values to before the backtesting range so that the dataframe matches size when it goes back to the strategy. These rows are not included in the backtest. """ - to_keep = [col for col in dataframe.columns if not col.startswith("&")] + to_keep = [col for col in dataframe.columns if + not col.startswith("&") and not col.startswith("%%")] self.return_dataframe = pd.merge(dataframe[to_keep], self.full_df, how='left', on='date') self.return_dataframe[self.full_df.columns] = (