From 334e7553e1afbb664575f14c3cf3fd23a12f597d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 29 Sep 2018 13:46:38 +0200 Subject: [PATCH 1/4] Fix hyperopt not working after update of scikit-learn to 0.20.0 --- freqtrade/strategy/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/freqtrade/strategy/__init__.py b/freqtrade/strategy/__init__.py index 38a110bd7..b29e26ef9 100644 --- a/freqtrade/strategy/__init__.py +++ b/freqtrade/strategy/__init__.py @@ -3,7 +3,8 @@ import sys from copy import deepcopy from freqtrade.strategy.interface import IStrategy - +# Import Default-Strategy to have hyperopt correctly resolve +from freqtrade.strategy.default_strategy import DefaultStrategy # noqa: F401 logger = logging.getLogger(__name__) From 1b290ffb5d70b1ef6c8e0a70610245d92d880122 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 29 Sep 2018 13:49:38 +0200 Subject: [PATCH 2/4] Update hyperopt to show errors if non-supported variables are used --- freqtrade/optimize/hyperopt.py | 10 ++++++++- freqtrade/tests/optimize/test_hyperopt.py | 25 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 086cad5aa..9dfaa8ef3 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -41,6 +41,14 @@ class Hyperopt(Backtesting): hyperopt.start() """ def __init__(self, config: Dict[str, Any]) -> None: + if config.get('strategy') and config.get('strategy') != 'DefaultStrategy': + logger.error("Please don't use --strategy for hyperopt.") + logger.error( + "Read the documentation at " + "https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md " + "to understand how to configure hyperopt.") + raise ValueError("--strategy configured but not supported for hyperopt") + super().__init__(config) # set TARGET_TRADES to suit your number concurrent trades so its realistic # to the number of days @@ -152,7 +160,7 @@ class Hyperopt(Backtesting): @staticmethod def generate_roi_table(params: Dict) -> Dict[int, float]: """ - Generate the ROI table thqt will be used by Hyperopt + Generate the ROI table that will be used by Hyperopt """ roi_table = {} roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3'] diff --git a/freqtrade/tests/optimize/test_hyperopt.py b/freqtrade/tests/optimize/test_hyperopt.py index 65a3c2fdb..2035e23df 100644 --- a/freqtrade/tests/optimize/test_hyperopt.py +++ b/freqtrade/tests/optimize/test_hyperopt.py @@ -65,6 +65,31 @@ def test_start(mocker, default_conf, caplog) -> None: assert start_mock.call_count == 1 +def test_start_failure(mocker, default_conf, caplog) -> None: + start_mock = MagicMock() + mocker.patch( + 'freqtrade.configuration.Configuration._load_config_file', + lambda *args, **kwargs: default_conf + ) + mocker.patch('freqtrade.optimize.hyperopt.Hyperopt.start', start_mock) + patch_exchange(mocker) + + args = [ + '--config', 'config.json', + '--strategy', 'TestStrategy', + 'hyperopt', + '--epochs', '5' + ] + args = get_args(args) + StrategyResolver({'strategy': 'DefaultStrategy'}) + with pytest.raises(ValueError): + start(args) + assert log_has( + "Please don't use --strategy for hyperopt.", + caplog.record_tuples + ) + + def test_loss_calculation_prefer_correct_trade_count(hyperopt) -> None: StrategyResolver({'strategy': 'DefaultStrategy'}) From 36e9abc8410f67608f38dac850b9d15755cc5437 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 29 Sep 2018 13:50:02 +0200 Subject: [PATCH 3/4] Manually update scikit-learn to 0.20.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 59d06aca1..4150dc5bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ requests==2.19.1 urllib3==1.22 wrapt==1.10.11 pandas==0.23.4 -scikit-learn==0.19.2 +scikit-learn==0.20.0 scipy==1.1.0 jsonschema==2.6.0 numpy==1.15.2 From 84622dc84b0368bfb1420f87ffcddad7a6807feb Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 29 Sep 2018 14:23:53 +0200 Subject: [PATCH 4/4] Move test for strategy out of constructor --- freqtrade/optimize/hyperopt.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 9dfaa8ef3..4a239ab28 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -41,14 +41,6 @@ class Hyperopt(Backtesting): hyperopt.start() """ def __init__(self, config: Dict[str, Any]) -> None: - if config.get('strategy') and config.get('strategy') != 'DefaultStrategy': - logger.error("Please don't use --strategy for hyperopt.") - logger.error( - "Read the documentation at " - "https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md " - "to understand how to configure hyperopt.") - raise ValueError("--strategy configured but not supported for hyperopt") - super().__init__(config) # set TARGET_TRADES to suit your number concurrent trades so its realistic # to the number of days @@ -410,6 +402,13 @@ def start(args: Namespace) -> None: config['exchange']['key'] = '' config['exchange']['secret'] = '' + if config.get('strategy') and config.get('strategy') != 'DefaultStrategy': + logger.error("Please don't use --strategy for hyperopt.") + logger.error( + "Read the documentation at " + "https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md " + "to understand how to configure hyperopt.") + raise ValueError("--strategy configured but not supported for hyperopt") # Initialize backtesting object hyperopt = Hyperopt(config) hyperopt.start()