Merge pull request #3049 from hroff-1902/hyperopt-no-unlimited
Do not allow unlimited stake_amount for hyperopt
This commit is contained in:
commit
14e7f0bb13
@ -17,10 +17,15 @@ def setup_optimize_configuration(args: Dict[str, Any], method: RunMode) -> Dict[
|
|||||||
"""
|
"""
|
||||||
config = setup_utils_configuration(args, method)
|
config = setup_utils_configuration(args, method)
|
||||||
|
|
||||||
if method == RunMode.BACKTEST:
|
no_unlimited_runmodes = {
|
||||||
if config['stake_amount'] == constants.UNLIMITED_STAKE_AMOUNT:
|
RunMode.BACKTEST: 'backtesting',
|
||||||
raise DependencyException('stake amount could not be "%s" for backtesting' %
|
RunMode.HYPEROPT: 'hyperoptimization',
|
||||||
constants.UNLIMITED_STAKE_AMOUNT)
|
}
|
||||||
|
if (method in no_unlimited_runmodes.keys() and
|
||||||
|
config['stake_amount'] == constants.UNLIMITED_STAKE_AMOUNT):
|
||||||
|
raise DependencyException(
|
||||||
|
f'The value of `stake_amount` cannot be set as "{constants.UNLIMITED_STAKE_AMOUNT}" '
|
||||||
|
f'for {no_unlimited_runmodes[method]}')
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ def test_setup_optimize_configuration_unlimited_stake_amount(mocker, default_con
|
|||||||
'--strategy', 'DefaultStrategy',
|
'--strategy', 'DefaultStrategy',
|
||||||
]
|
]
|
||||||
|
|
||||||
with pytest.raises(DependencyException, match=r'.*stake amount.*'):
|
with pytest.raises(DependencyException, match=r'.`stake_amount`.*'):
|
||||||
setup_optimize_configuration(get_args(args), RunMode.BACKTEST)
|
setup_optimize_configuration(get_args(args), RunMode.BACKTEST)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,10 +10,11 @@ import pytest
|
|||||||
from arrow import Arrow
|
from arrow import Arrow
|
||||||
from filelock import Timeout
|
from filelock import Timeout
|
||||||
|
|
||||||
|
from freqtrade import constants
|
||||||
from freqtrade.commands.optimize_commands import (setup_optimize_configuration,
|
from freqtrade.commands.optimize_commands import (setup_optimize_configuration,
|
||||||
start_hyperopt)
|
start_hyperopt)
|
||||||
from freqtrade.data.history import load_data
|
from freqtrade.data.history import load_data
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import DependencyException, OperationalException
|
||||||
from freqtrade.optimize.default_hyperopt import DefaultHyperOpt
|
from freqtrade.optimize.default_hyperopt import DefaultHyperOpt
|
||||||
from freqtrade.optimize.default_hyperopt_loss import DefaultHyperOptLoss
|
from freqtrade.optimize.default_hyperopt_loss import DefaultHyperOptLoss
|
||||||
from freqtrade.optimize.hyperopt import Hyperopt
|
from freqtrade.optimize.hyperopt import Hyperopt
|
||||||
@ -158,6 +159,21 @@ def test_setup_hyperopt_configuration_with_arguments(mocker, default_conf, caplo
|
|||||||
assert log_has('Parameter --print-all detected ...', caplog)
|
assert log_has('Parameter --print-all detected ...', caplog)
|
||||||
|
|
||||||
|
|
||||||
|
def test_setup_hyperopt_configuration_unlimited_stake_amount(mocker, default_conf, caplog) -> None:
|
||||||
|
default_conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
|
||||||
|
|
||||||
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
|
|
||||||
|
args = [
|
||||||
|
'hyperopt',
|
||||||
|
'--config', 'config.json',
|
||||||
|
'--hyperopt', 'DefaultHyperOpt',
|
||||||
|
]
|
||||||
|
|
||||||
|
with pytest.raises(DependencyException, match=r'.`stake_amount`.*'):
|
||||||
|
setup_optimize_configuration(get_args(args), RunMode.HYPEROPT)
|
||||||
|
|
||||||
|
|
||||||
def test_hyperoptresolver(mocker, default_conf, caplog) -> None:
|
def test_hyperoptresolver(mocker, default_conf, caplog) -> None:
|
||||||
patched_configuration_load_config_file(mocker, default_conf)
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user