diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index db0d4c379..fef5df40f 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -61,15 +61,16 @@ class IFreqaiModel(ABC): "data_split_parameters", {}) self.model_training_parameters: Dict[str, Any] = config.get("freqai", {}).get( "model_training_parameters", {}) + self.identifier: str = self.freqai_info.get("identifier", "no_id_provided") self.retrain = False self.first = True self.set_full_path() + self.record_configs() self.follow_mode: bool = self.freqai_info.get("follow_mode", False) self.save_backtest_models: bool = self.freqai_info.get("save_backtest_models", True) if self.save_backtest_models: logger.info('Backtesting module configured to save all models.') self.dd = FreqaiDataDrawer(Path(self.full_path), self.config, self.follow_mode) - self.identifier: str = self.freqai_info.get("identifier", "no_id_provided") self.scanning = False self.ft_params = self.freqai_info["feature_parameters"] self.keras: bool = self.freqai_info.get("keras", False) @@ -526,14 +527,24 @@ class IFreqaiModel(ABC): return file_exists def set_full_path(self) -> None: + """ + Creates and sets the full path for the identifier + """ self.full_path = Path( self.config["user_data_dir"] / "models" / f"{self.freqai_info['identifier']}" ) self.full_path.mkdir(parents=True, exist_ok=True) - shutil.copy( - self.config["config_files"][0], - Path(self.full_path, Path(self.config["config_files"][0]).name), - ) + + def record_configs(self) -> None: + """ + Records configs in the full path for reproducibility + """ + self.config_record_path = self.full_path / Path("configs") + self.config_record_path.mkdir(parents=True, exist_ok=True) + + for config in self.config["config_files"]: + dest_config_path = self.config_record_path / Path(config).name + shutil.copyfile(config, dest_config_path) def extract_data_and_train_model( self, diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index b619c0611..66eb6d696 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -19,7 +19,7 @@ from tests.freqai.conftest import get_patched_freqai_strategy def is_arm() -> bool: machine = platform.machine() - return "arm" in machine or "aarch64" in machine + return "arm" in machine or "aarch74" in machine def is_mac() -> bool: @@ -160,12 +160,12 @@ def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model): @pytest.mark.parametrize( "model, num_files, strat", [ - ("LightGBMRegressor", 6, "freqai_test_strat"), - ("XGBoostRegressor", 6, "freqai_test_strat"), - ("CatboostRegressor", 6, "freqai_test_strat"), - ("XGBoostClassifier", 6, "freqai_test_classifier"), - ("LightGBMClassifier", 6, "freqai_test_classifier"), - ("CatboostClassifier", 6, "freqai_test_classifier") + ("LightGBMRegressor", 7, "freqai_test_strat"), + ("XGBoostRegressor", 7, "freqai_test_strat"), + ("CatboostRegressor", 7, "freqai_test_strat"), + ("XGBoostClassifier", 7, "freqai_test_classifier"), + ("LightGBMClassifier", 7, "freqai_test_classifier"), + ("CatboostClassifier", 7, "freqai_test_classifier") ], ) def test_start_backtesting(mocker, freqai_conf, model, num_files, strat, caplog): @@ -200,6 +200,7 @@ def test_start_backtesting(mocker, freqai_conf, model, num_files, strat, caplog) freqai.start_backtesting(df, metadata, freqai.dk) model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()] + # Changed from 6 to 7 because of the /configs directory assert len(model_folders) == num_files assert log_has_re( "Removed features ", @@ -234,7 +235,9 @@ def test_start_backtesting_subdaily_backtest_period(mocker, freqai_conf): metadata = {"pair": "LTC/BTC"} freqai.start_backtesting(df, metadata, freqai.dk) model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()] - assert len(model_folders) == 9 + + # Changed from 9 to 10 because of the /configs dir + assert len(model_folders) == 10 shutil.rmtree(Path(freqai.dk.full_path)) @@ -260,7 +263,7 @@ def test_start_backtesting_from_existing_folder(mocker, freqai_conf, caplog): freqai.start_backtesting(df, metadata, freqai.dk) model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()] - assert len(model_folders) == 6 + assert len(model_folders) == 7 # without deleting the existing folder structure, re-run