diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index 80c037a3d..5ca64e504 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -909,10 +909,10 @@ class FreqaiDataKitchen: coin, _ = pair.split("/") self.data_path = Path( self.full_path - / str("sub-train" + "-" + pair.split("/")[0] + "_" + str(int(trained_timerange.stopts))) + / f"sub-train-{pair.split('/')[0]}_{int(trained_timerange.stopts)}" ) - self.model_filename = "cb_" + coin.lower() + "_" + str(int(trained_timerange.stopts)) + self.model_filename = f"cb_{coin.lower()}_{int(trained_timerange.stopts)}" def download_all_data_for_training(self, timerange: TimeRange) -> None: """ diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index c393420b5..a8527f9e1 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -210,11 +210,12 @@ class IFreqaiModel(ABC): ) ) if not self.model_exists( - metadata["pair"], dk, trained_timestamp=trained_timestamp.stopts + metadata["pair"], dk, trained_timestamp=int(trained_timestamp.stopts) ): dk.find_features(dataframe_train) self.model = self.train(dataframe_train, metadata["pair"], dk) - self.dd.pair_dict[metadata["pair"]]["trained_timestamp"] = trained_timestamp.stopts + self.dd.pair_dict[metadata["pair"]]["trained_timestamp"] = int( + trained_timestamp.stopts) dk.set_new_model_names(metadata["pair"], trained_timestamp) dk.save_data(self.model, metadata["pair"]) else: diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index 6699ef563..e4df8772c 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -90,7 +90,7 @@ def test_start_backtesting(mocker, freqai_conf): df = freqai.dk.use_strategy_to_populate_indicators(strategy, corr_df, base_df, "LTC/BTC") - metadata = {"pair": "ADA/BTC"} + 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()] @@ -99,6 +99,32 @@ def test_start_backtesting(mocker, freqai_conf): shutil.rmtree(Path(freqai.dk.full_path)) +def test_start_backtesting_subdaily_backtest_period(mocker, freqai_conf): + freqai_conf.update({"timerange": "20180120-20180124"}) + freqai_conf.get("freqai", {}).update({"backtest_period_days": 0.5}) + strategy = get_patched_freqai_strategy(mocker, freqai_conf) + exchange = get_patched_exchange(mocker, freqai_conf) + strategy.dp = DataProvider(freqai_conf, exchange) + strategy.freqai_info = freqai_conf.get("freqai", {}) + freqai = strategy.freqai + freqai.live = False + freqai.dk = FreqaiDataKitchen(freqai_conf, freqai.dd) + timerange = TimeRange.parse_timerange("20180110-20180130") + freqai.dk.load_all_pair_histories(timerange) + sub_timerange = TimeRange.parse_timerange("20180110-20180130") + corr_df, base_df = freqai.dk.get_base_and_corr_dataframes(sub_timerange, "LTC/BTC") + + df = freqai.dk.use_strategy_to_populate_indicators(strategy, corr_df, base_df, "LTC/BTC") + + 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()] + pytest.set_trace() + assert len(model_folders) == 8 + + shutil.rmtree(Path(freqai.dk.full_path)) + + def test_start_backtesting_from_existing_folder(mocker, freqai_conf, caplog): freqai_conf.update({"timerange": "20180120-20180130"}) strategy = get_patched_freqai_strategy(mocker, freqai_conf)