Manual merge of some conflicts in hyperopt
This commit is contained in:
parent
86342efa7a
commit
54694dd3a4
@ -165,13 +165,16 @@ class Hyperopt:
|
|||||||
result: Dict = {}
|
result: Dict = {}
|
||||||
|
|
||||||
if self.has_space('buy'):
|
if self.has_space('buy'):
|
||||||
result['buy'] = {p.name: params.get(p.name) for p in self.hyperopt_space('buy')}
|
result['buy'] = {p.name: params.get(p.name)
|
||||||
|
for p in self.hyperopt_space('buy')}
|
||||||
if self.has_space('sell'):
|
if self.has_space('sell'):
|
||||||
result['sell'] = {p.name: params.get(p.name) for p in self.hyperopt_space('sell')}
|
result['sell'] = {p.name: params.get(p.name)
|
||||||
|
for p in self.hyperopt_space('sell')}
|
||||||
if self.has_space('roi'):
|
if self.has_space('roi'):
|
||||||
result['roi'] = self.custom_hyperopt.generate_roi_table(params)
|
result['roi'] = self.custom_hyperopt.generate_roi_table(params)
|
||||||
if self.has_space('stoploss'):
|
if self.has_space('stoploss'):
|
||||||
result['stoploss'] = params.get('stoploss')
|
result['stoploss'] = {p.name: params.get(p.name)
|
||||||
|
for p in self.hyperopt_space('stoploss')}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -193,38 +196,48 @@ class Hyperopt:
|
|||||||
|
|
||||||
if print_json:
|
if print_json:
|
||||||
result_dict: Dict = {}
|
result_dict: Dict = {}
|
||||||
result_params_dict: Dict = {}
|
for s in ['buy', 'sell', 'roi', 'stoploss']:
|
||||||
if 'buy' in params:
|
Hyperopt._params_update_for_json(result_dict, params, s)
|
||||||
result_params_dict.update(params['buy'])
|
print(rapidjson.dumps(result_dict, default=str, number_mode=rapidjson.NM_NATIVE))
|
||||||
if 'sell' in params:
|
|
||||||
result_params_dict.update(params['sell'])
|
else:
|
||||||
if result_params_dict:
|
Hyperopt._params_pretty_print(params, 'buy', "Buy hyperspace params:")
|
||||||
result_dict['params'] = result_params_dict
|
Hyperopt._params_pretty_print(params, 'sell', "Sell hyperspace params:")
|
||||||
if 'roi' in params:
|
Hyperopt._params_pretty_print(params, 'roi', "ROI table:")
|
||||||
|
Hyperopt._params_pretty_print(params, 'stoploss', "Stoploss:")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _params_update_for_json(result_dict, params, space: str):
|
||||||
|
if space in params:
|
||||||
|
space_params = Hyperopt._space_params(params, space)
|
||||||
|
if space in ['buy', 'sell']:
|
||||||
|
result_dict.setdefault('params', {}).update(space_params)
|
||||||
|
elif space == 'roi':
|
||||||
# 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
|
||||||
# in the dict.
|
# in the dict.
|
||||||
result_dict['minimal_roi'] = OrderedDict(
|
result_dict['minimal_roi'] = OrderedDict(
|
||||||
(str(k), v) for k, v in params['roi'].items()
|
(str(k), v) for k, v in space_params.items()
|
||||||
)
|
)
|
||||||
if 'stoploss' in params:
|
else: # 'stoploss'
|
||||||
result_dict['stoploss'] = params['stoploss']
|
result_dict.update(space_params)
|
||||||
print(rapidjson.dumps(result_dict, default=str, number_mode=rapidjson.NM_NATIVE))
|
|
||||||
else:
|
@staticmethod
|
||||||
if 'buy' in params:
|
def _params_pretty_print(params, space: str, header: str):
|
||||||
print('Buy hyperspace params:')
|
if space in params:
|
||||||
pprint(params['buy'], indent=4)
|
space_params = Hyperopt._space_params(params, space, 5)
|
||||||
if 'sell' in params:
|
if space == 'stoploss':
|
||||||
print('Sell hyperspace params:')
|
print(header, space_params.get('stoploss'))
|
||||||
pprint(params['sell'], indent=4)
|
else:
|
||||||
if 'roi' in params:
|
print(header)
|
||||||
print("ROI table:")
|
pprint(space_params, indent=4)
|
||||||
# Round printed values to 5 digits after the decimal point
|
|
||||||
pprint(round_dict(params['roi'], 5), indent=4)
|
@staticmethod
|
||||||
if 'stoploss' in params:
|
def _space_params(params, space: str, r: int = None) -> Dict:
|
||||||
# Also round to 5 digits after the decimal point
|
d = params[space]
|
||||||
print(f"Stoploss: {round(params['stoploss'], 5)}")
|
# Round floats to `r` digits after the decimal point if requested
|
||||||
|
return round_dict(d, r) if r else d
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_best_loss(results, current_best_loss) -> bool:
|
def is_best_loss(results, current_best_loss) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user