From 69ac5c1ac7a6178113b8f6df8650661f6f3fa284 Mon Sep 17 00:00:00 2001 From: Felipe Lambert Date: Mon, 8 Jun 2020 14:55:28 -0300 Subject: [PATCH 1/3] change hyperopt return to better copy to strategy file --- freqtrade/optimize/hyperopt.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 3a28de785..58bcbd208 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -12,7 +12,7 @@ from math import ceil from collections import OrderedDict from operator import itemgetter from pathlib import Path -from pprint import pprint +from pprint import pformat from typing import Any, Dict, List, Optional import rapidjson @@ -244,11 +244,21 @@ class Hyperopt: def _params_pretty_print(params, space: str, header: str) -> None: if space in params: space_params = Hyperopt._space_params(params, space, 5) + print(f"\n # {header}") if space == 'stoploss': - print(header, space_params.get('stoploss')) + print(" stoploss =", space_params.get('stoploss')) + elif space == 'roi': + minimal_roi_result = rapidjson.dumps( + OrderedDict( + (str(k), v) for k, v in space_params.items() + ), + default=str, indent=4, number_mode=rapidjson.NM_NATIVE) + minimal_roi_result = minimal_roi_result.replace("\n", "\n ") + print(f" minimal_roi = {minimal_roi_result}") else: - print(header) - pprint(space_params, indent=4) + params_result = pformat(space_params, indent=4).replace("}", "\n}") + params_result = params_result.replace("{", "{\n ").replace("\n", "\n ") + print(f" {space}_params = {params_result}") @staticmethod def _space_params(params, space: str, r: int = None) -> Dict: From 3d9b1077612c272267363c72a1653ec39ffdaa83 Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Sat, 13 Jun 2020 17:12:37 +0300 Subject: [PATCH 2/3] Changes after review --- freqtrade/optimize/hyperopt.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 58bcbd208..1136fc4a7 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -230,6 +230,9 @@ class Hyperopt: if space in ['buy', 'sell']: result_dict.setdefault('params', {}).update(space_params) elif space == 'roi': + # TODO: get rid of OrderedDict when support for python 3.6 will be + # dropped (dicts keep the order as the language feature) + # Convert keys in min_roi dict to strings because # rapidjson cannot dump dicts with integer keys... # OrderedDict is used to keep the numeric order of the items @@ -244,21 +247,24 @@ class Hyperopt: def _params_pretty_print(params, space: str, header: str) -> None: if space in params: space_params = Hyperopt._space_params(params, space, 5) - print(f"\n # {header}") + params_result = f"\n# {header}\n" if space == 'stoploss': - print(" stoploss =", space_params.get('stoploss')) + params_result += f"stoploss = {space_params.get('stoploss')}" elif space == 'roi': minimal_roi_result = rapidjson.dumps( + # TODO: get rid of OrderedDict when support for python 3.6 will be + # dropped (dicts keep the order as the language feature) OrderedDict( (str(k), v) for k, v in space_params.items() ), default=str, indent=4, number_mode=rapidjson.NM_NATIVE) - minimal_roi_result = minimal_roi_result.replace("\n", "\n ") - print(f" minimal_roi = {minimal_roi_result}") + params_result += f"minimal_roi = {minimal_roi_result}" else: - params_result = pformat(space_params, indent=4).replace("}", "\n}") - params_result = params_result.replace("{", "{\n ").replace("\n", "\n ") - print(f" {space}_params = {params_result}") + params_result += f"{space}_params = {pformat(space_params, indent=4)}" + params_result = params_result.replace("}", "\n}").replace("{", "{\n ") + + params_result = params_result.replace("\n", "\n ") + print(params_result) @staticmethod def _space_params(params, space: str, r: int = None) -> Dict: From ea77edce0519bdd7664fd20fd65416f85bdbaada Mon Sep 17 00:00:00 2001 From: hroff-1902 <47309513+hroff-1902@users.noreply.github.com> Date: Sat, 13 Jun 2020 18:54:54 +0300 Subject: [PATCH 3/3] Make flake happy --- freqtrade/optimize/hyperopt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 1136fc4a7..153ae3861 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -251,9 +251,9 @@ class Hyperopt: if space == 'stoploss': params_result += f"stoploss = {space_params.get('stoploss')}" elif space == 'roi': - minimal_roi_result = rapidjson.dumps( # TODO: get rid of OrderedDict when support for python 3.6 will be # dropped (dicts keep the order as the language feature) + minimal_roi_result = rapidjson.dumps( OrderedDict( (str(k), v) for k, v in space_params.items() ),