backtest_live models tests refactoring
This commit is contained in:
parent
3c002ff752
commit
55ebbeec18
@ -336,6 +336,7 @@ def _validate_freqai_hyperopt(conf: Dict[str, Any]) -> None:
|
||||
|
||||
|
||||
def _validate_freqai_backtest(conf: Dict[str, Any]) -> None:
|
||||
if conf.get('runmode', RunMode.OTHER) == RunMode.BACKTEST:
|
||||
freqai_enabled = conf.get('freqai', {}).get('enabled', False)
|
||||
timerange = conf.get('timerange')
|
||||
freqai_backtest_live_models = conf.get('freqai_backtest_live_models', False)
|
||||
@ -349,6 +350,10 @@ def _validate_freqai_backtest(conf: Dict[str, Any]) -> None:
|
||||
'Using --freqai-backtest-live-models parameter is only '
|
||||
'supported with a FreqAI strategy.')
|
||||
|
||||
if freqai_enabled and not freqai_backtest_live_models and not timerange:
|
||||
raise OperationalException(
|
||||
'Please pass --timerange if you intend to use FreqAI for backtesting.')
|
||||
|
||||
|
||||
def _validate_consumers(conf: Dict[str, Any]) -> None:
|
||||
emc_conf = conf.get('external_message_consumer', {})
|
||||
|
@ -84,11 +84,6 @@ class FreqaiDataKitchen:
|
||||
self.backtest_live_models = config.get("freqai_backtest_live_models", False)
|
||||
|
||||
if not self.live:
|
||||
if (not self.config.get("timerange") and
|
||||
not self.backtest_live_models):
|
||||
raise OperationalException(
|
||||
'Please pass --timerange if you intend to use FreqAI for backtesting.')
|
||||
|
||||
self.full_path = freqai_util.get_full_model_path(self.config)
|
||||
self.full_timerange = self.create_fulltimerange(
|
||||
self.config["timerange"], self.freqai_config.get("train_period_days", 0)
|
||||
|
@ -56,34 +56,6 @@ def test_freqai_backtest_load_data(freqai_conf, mocker, caplog):
|
||||
Backtesting.cleanup()
|
||||
|
||||
|
||||
def test_freqai_backtest_live_models_validations(freqai_conf, mocker, testdatadir, caplog):
|
||||
patch_exchange(mocker)
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist',
|
||||
PropertyMock(return_value=['HULUMULU/USDT', 'XRP/USDT']))
|
||||
mocker.patch('freqtrade.optimize.backtesting.history.load_data')
|
||||
mocker.patch('freqtrade.optimize.backtesting.history.get_timerange', return_value=(now, now))
|
||||
|
||||
patched_configuration_load_config_file(mocker, freqai_conf)
|
||||
|
||||
args = [
|
||||
'backtesting',
|
||||
'--config', 'config.json',
|
||||
'--datadir', str(testdatadir),
|
||||
'--strategy-path', str(Path(__file__).parents[1] / 'strategy/strats'),
|
||||
'--timeframe', '1h',
|
||||
'--timerange', '20220108-20220115',
|
||||
'--freqai-backtest-live-models'
|
||||
]
|
||||
args = get_args(args)
|
||||
with pytest.raises(OperationalException,
|
||||
match=r".* timerange parameter is not supported .*"):
|
||||
setup_optimize_configuration(args, RunMode.BACKTEST)
|
||||
|
||||
Backtesting.cleanup()
|
||||
|
||||
|
||||
def test_freqai_backtest_live_models_model_not_found(freqai_conf, mocker, testdatadir, caplog):
|
||||
patch_exchange(mocker)
|
||||
|
||||
|
@ -1609,7 +1609,7 @@ def test_setup_hyperopt_freqai(mocker, default_conf, caplog) -> None:
|
||||
validate_config_consistency(config)
|
||||
|
||||
|
||||
def test_setup_freqai_backtest_live_models(mocker, default_conf, caplog) -> None:
|
||||
def test_setup_freqai_backtesting(mocker, default_conf, caplog) -> None:
|
||||
patched_configuration_load_config_file(mocker, default_conf)
|
||||
mocker.patch(
|
||||
'freqtrade.configuration.configuration.create_datadir',
|
||||
@ -1633,6 +1633,8 @@ def test_setup_freqai_backtest_live_models(mocker, default_conf, caplog) -> None
|
||||
|
||||
configuration = Configuration(args)
|
||||
config = configuration.get_config()
|
||||
config['runmode'] = RunMode.BACKTEST
|
||||
|
||||
with pytest.raises(
|
||||
OperationalException, match=r".*--freqai-backtest-live-models parameter is only.*"
|
||||
):
|
||||
@ -1646,3 +1648,11 @@ def test_setup_freqai_backtest_live_models(mocker, default_conf, caplog) -> None
|
||||
OperationalException, match=r".* timerange parameter is not supported with .*"
|
||||
):
|
||||
validate_config_consistency(conf)
|
||||
|
||||
conf['timerange'] = None
|
||||
conf['freqai_backtest_live_models'] = False
|
||||
|
||||
with pytest.raises(
|
||||
OperationalException, match=r".* pass --timerange if you intend to use FreqAI .*"
|
||||
):
|
||||
validate_config_consistency(conf)
|
||||
|
Loading…
Reference in New Issue
Block a user