From 913749c81bad3c85c882391bf0b6341967b0e89a Mon Sep 17 00:00:00 2001 From: Wagner Costa Santos Date: Thu, 17 Nov 2022 10:30:16 -0300 Subject: [PATCH] backtesting_from_live_saved_files - code refactoring --- docs/freqai-running.md | 2 +- freqtrade/freqai/data_kitchen.py | 27 +++++++++++---------------- freqtrade/freqai/freqai_interface.py | 2 -- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/docs/freqai-running.md b/docs/freqai-running.md index f97ed0ab4..d2f9595be 100644 --- a/docs/freqai-running.md +++ b/docs/freqai-running.md @@ -81,7 +81,7 @@ To save the models generated during a particular backtest so that you can start ### Backtest live models -FreqAI allow you to reuse ready models through the backtest parameter `--freqai-backtest-live-models`. This can be useful when you want to reuse models generated in dry/run for comparison or other study. For that, you must set `"purge_old_models"` to `True` in the config. +FreqAI allow you to reuse ready models through the backtest parameter `--freqai-backtest-live-models`. This can be useful when you want to reuse models generated in dry/run for comparison or other study. For that, you must set `"purge_old_models"` to `False` in the config. The `--timerange` parameter must not be informed, as it will be automatically calculated through the training end dates of the models. diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index c7fae7770..d5427c4a5 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -1519,15 +1519,13 @@ class FreqaiDataKitchen: pair_path = pair.split(":")[0].replace("/", "_").lower() file_name = f"live_backtesting_{pair_path}.feather" - path_to_live_backtesting_file = Path(self.full_path / - self.backtesting_live_model_folder_path / - file_name) - path_to_live_backtesting_bkp_file = Path(self.full_path / - self.backtesting_live_model_folder_path / - file_name.replace(".feather", ".backup.feather")) - - self.backtesting_live_model_path = path_to_live_backtesting_file - self.backtesting_live_model_bkp_path = path_to_live_backtesting_bkp_file + self.backtesting_live_model_path = Path(self.full_path / + self.backtesting_live_model_folder_path / + file_name) + self.backtesting_live_model_bkp_path = Path( + self.full_path / + self.backtesting_live_model_folder_path / + file_name.replace(".feather", ".backup.feather")) def save_backtesting_live_dataframe( self, dataframe: DataFrame, pair: str @@ -1566,15 +1564,12 @@ class FreqaiDataKitchen: return saved_dataframe else: raise OperationalException( - "Saved pair file not found" + "Saved live backtesting dataframe file not found." ) - def get_timerange_from_backtesting_live_dataframe( - self) -> TimeRange: + def get_timerange_from_backtesting_live_dataframe(self) -> TimeRange: """ - Returns timerange information based on a FreqAI model directory - :param models_path: FreqAI model path - + Returns timerange information based on live backtesting dataframe file :return: timerange calculated from saved live data """ all_assets_start_dates = [] @@ -1592,7 +1587,7 @@ class FreqaiDataKitchen: all_assets_start_dates.append(saved_dataframe.date.min()) all_assets_end_dates.append(saved_dataframe.date.max()) start_date = min(all_assets_start_dates) - end_date = min(all_assets_end_dates) + end_date = max(all_assets_end_dates) # add 1 day to string timerange to ensure BT module will load all dataframe data end_date = end_date + timedelta(days=1) backtesting_timerange = TimeRange( diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index cc6cd3c9b..8d84d70c5 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -334,8 +334,6 @@ class IFreqaiModel(ABC): FreqaiDataKitchen = Data management/analysis tool associated to present pair only """ pair = metadata["pair"] - dk.return_dataframe = dataframe - dk.return_dataframe = dataframe self.dk.set_backtesting_live_dataframe_path(pair) saved_dataframe = self.dk.get_backtesting_live_dataframe()