update config recording to use all configs, fix tests

This commit is contained in:
Timothy Pogue 2022-10-21 19:48:26 -06:00
parent a85826bf24
commit 5ee3b8cbbb
2 changed files with 28 additions and 14 deletions

View File

@ -61,15 +61,16 @@ class IFreqaiModel(ABC):
"data_split_parameters", {}) "data_split_parameters", {})
self.model_training_parameters: Dict[str, Any] = config.get("freqai", {}).get( self.model_training_parameters: Dict[str, Any] = config.get("freqai", {}).get(
"model_training_parameters", {}) "model_training_parameters", {})
self.identifier: str = self.freqai_info.get("identifier", "no_id_provided")
self.retrain = False self.retrain = False
self.first = True self.first = True
self.set_full_path() self.set_full_path()
self.record_configs()
self.follow_mode: bool = self.freqai_info.get("follow_mode", False) self.follow_mode: bool = self.freqai_info.get("follow_mode", False)
self.save_backtest_models: bool = self.freqai_info.get("save_backtest_models", True) self.save_backtest_models: bool = self.freqai_info.get("save_backtest_models", True)
if self.save_backtest_models: if self.save_backtest_models:
logger.info('Backtesting module configured to save all models.') logger.info('Backtesting module configured to save all models.')
self.dd = FreqaiDataDrawer(Path(self.full_path), self.config, self.follow_mode) 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.scanning = False
self.ft_params = self.freqai_info["feature_parameters"] self.ft_params = self.freqai_info["feature_parameters"]
self.keras: bool = self.freqai_info.get("keras", False) self.keras: bool = self.freqai_info.get("keras", False)
@ -526,14 +527,24 @@ class IFreqaiModel(ABC):
return file_exists return file_exists
def set_full_path(self) -> None: def set_full_path(self) -> None:
"""
Creates and sets the full path for the identifier
"""
self.full_path = Path( self.full_path = Path(
self.config["user_data_dir"] / "models" / f"{self.freqai_info['identifier']}" self.config["user_data_dir"] / "models" / f"{self.freqai_info['identifier']}"
) )
self.full_path.mkdir(parents=True, exist_ok=True) self.full_path.mkdir(parents=True, exist_ok=True)
shutil.copy(
self.config["config_files"][0], def record_configs(self) -> None:
Path(self.full_path, Path(self.config["config_files"][0]).name), """
) 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( def extract_data_and_train_model(
self, self,

View File

@ -19,7 +19,7 @@ from tests.freqai.conftest import get_patched_freqai_strategy
def is_arm() -> bool: def is_arm() -> bool:
machine = platform.machine() machine = platform.machine()
return "arm" in machine or "aarch64" in machine return "arm" in machine or "aarch74" in machine
def is_mac() -> bool: def is_mac() -> bool:
@ -160,12 +160,12 @@ def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"model, num_files, strat", "model, num_files, strat",
[ [
("LightGBMRegressor", 6, "freqai_test_strat"), ("LightGBMRegressor", 7, "freqai_test_strat"),
("XGBoostRegressor", 6, "freqai_test_strat"), ("XGBoostRegressor", 7, "freqai_test_strat"),
("CatboostRegressor", 6, "freqai_test_strat"), ("CatboostRegressor", 7, "freqai_test_strat"),
("XGBoostClassifier", 6, "freqai_test_classifier"), ("XGBoostClassifier", 7, "freqai_test_classifier"),
("LightGBMClassifier", 6, "freqai_test_classifier"), ("LightGBMClassifier", 7, "freqai_test_classifier"),
("CatboostClassifier", 6, "freqai_test_classifier") ("CatboostClassifier", 7, "freqai_test_classifier")
], ],
) )
def test_start_backtesting(mocker, freqai_conf, model, num_files, strat, caplog): 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) freqai.start_backtesting(df, metadata, freqai.dk)
model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()] 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 len(model_folders) == num_files
assert log_has_re( assert log_has_re(
"Removed features ", "Removed features ",
@ -234,7 +235,9 @@ def test_start_backtesting_subdaily_backtest_period(mocker, freqai_conf):
metadata = {"pair": "LTC/BTC"} metadata = {"pair": "LTC/BTC"}
freqai.start_backtesting(df, metadata, freqai.dk) freqai.start_backtesting(df, metadata, freqai.dk)
model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()] 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)) 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) freqai.start_backtesting(df, metadata, freqai.dk)
model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()] 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 # without deleting the existing folder structure, re-run