Merge pull request #3461 from felpasl/format_minimal_roi_opt
change hyperopt output to print ready to copy to strategy
This commit is contained in:
commit
dfc44e5b32
@ -12,7 +12,7 @@ from math import ceil
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pprint import pprint
|
from pprint import pformat
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
import rapidjson
|
import rapidjson
|
||||||
@ -230,6 +230,9 @@ class Hyperopt:
|
|||||||
if space in ['buy', 'sell']:
|
if space in ['buy', 'sell']:
|
||||||
result_dict.setdefault('params', {}).update(space_params)
|
result_dict.setdefault('params', {}).update(space_params)
|
||||||
elif space == 'roi':
|
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
|
# Convert keys in min_roi dict to strings because
|
||||||
# rapidjson cannot dump dicts with integer keys...
|
# rapidjson cannot dump dicts with integer keys...
|
||||||
# OrderedDict is used to keep the numeric order of the items
|
# OrderedDict is used to keep the numeric order of the items
|
||||||
@ -244,11 +247,24 @@ class Hyperopt:
|
|||||||
def _params_pretty_print(params, space: str, header: str) -> None:
|
def _params_pretty_print(params, space: str, header: str) -> None:
|
||||||
if space in params:
|
if space in params:
|
||||||
space_params = Hyperopt._space_params(params, space, 5)
|
space_params = Hyperopt._space_params(params, space, 5)
|
||||||
|
params_result = f"\n# {header}\n"
|
||||||
if space == 'stoploss':
|
if space == 'stoploss':
|
||||||
print(header, space_params.get('stoploss'))
|
params_result += f"stoploss = {space_params.get('stoploss')}"
|
||||||
|
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)
|
||||||
|
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)
|
||||||
|
params_result += f"minimal_roi = {minimal_roi_result}"
|
||||||
else:
|
else:
|
||||||
print(header)
|
params_result += f"{space}_params = {pformat(space_params, indent=4)}"
|
||||||
pprint(space_params, indent=4)
|
params_result = params_result.replace("}", "\n}").replace("{", "{\n ")
|
||||||
|
|
||||||
|
params_result = params_result.replace("\n", "\n ")
|
||||||
|
print(params_result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _space_params(params, space: str, r: int = None) -> Dict:
|
def _space_params(params, space: str, r: int = None) -> Dict:
|
||||||
|
Loading…
Reference in New Issue
Block a user