fine printing for floats in the roi tables (round to 5 digits after the decimal point)

This commit is contained in:
hroff-1902 2019-08-20 22:17:21 +03:00
parent 5b9711c002
commit a12876da92
3 changed files with 14 additions and 4 deletions

View File

@ -113,3 +113,10 @@ def deep_merge_dicts(source, destination):
destination[key] = value destination[key] = value
return destination return destination
def round_dict(d, n):
"""
Rounds float values in the dict to n digits after the decimal point.
"""
return {k: (round(v, n) if isinstance(v, float) else v) for k, v in d.items()}

View File

@ -22,6 +22,7 @@ from skopt.space import Dimension
from freqtrade.configuration import Arguments from freqtrade.configuration import Arguments
from freqtrade.data.history import load_data, get_timeframe from freqtrade.data.history import load_data, get_timeframe
from freqtrade.misc import round_dict
from freqtrade.optimize.backtesting import Backtesting from freqtrade.optimize.backtesting import Backtesting
# Import IHyperOpt and IHyperOptLoss to allow unpickling classes from these modules # Import IHyperOpt and IHyperOptLoss to allow unpickling classes from these modules
from freqtrade.optimize.hyperopt_interface import IHyperOpt # noqa: F4 from freqtrade.optimize.hyperopt_interface import IHyperOpt # noqa: F4
@ -147,7 +148,8 @@ class Hyperopt(Backtesting):
indent=4) indent=4)
if self.has_space('roi'): if self.has_space('roi'):
print("ROI table:") print("ROI table:")
pprint(self.custom_hyperopt.generate_roi_table(params), indent=4) # Round printed values to 5 digits after the decimal point
pprint(round_dict(self.custom_hyperopt.generate_roi_table(params), 5), indent=4)
if self.has_space('stoploss'): if self.has_space('stoploss'):
print(f"Stoploss: {params.get('stoploss')}") print(f"Stoploss: {params.get('stoploss')}")

View File

@ -12,6 +12,7 @@ from pandas import DataFrame
from skopt.space import Dimension, Integer, Real from skopt.space import Dimension, Integer, Real
from freqtrade.exchange import timeframe_to_minutes from freqtrade.exchange import timeframe_to_minutes
from freqtrade.misc import round_dict
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -128,7 +129,7 @@ class IHyperOpt(ABC):
'roi_p3_min': 0.01 * roi_p_scale * roi_p_alpha, 'roi_p3_min': 0.01 * roi_p_scale * roi_p_alpha,
'roi_p3_max': 0.20 * roi_p_scale * roi_p_alpha, 'roi_p3_max': 0.20 * roi_p_scale * roi_p_alpha,
} }
logger.debug(f"Using roi space limits: {roi_limits}") logger.debug(f"Using roi space limits: {round_dict(roi_limits, 5)}")
p = { p = {
'roi_t1': roi_limits['roi_t1_min'], 'roi_t1': roi_limits['roi_t1_min'],
'roi_t2': roi_limits['roi_t2_min'], 'roi_t2': roi_limits['roi_t2_min'],
@ -137,7 +138,7 @@ class IHyperOpt(ABC):
'roi_p2': roi_limits['roi_p2_min'], 'roi_p2': roi_limits['roi_p2_min'],
'roi_p3': roi_limits['roi_p3_min'], 'roi_p3': roi_limits['roi_p3_min'],
} }
logger.info(f"Min roi table: {IHyperOpt.generate_roi_table(p)}") logger.info(f"Min roi table: {round_dict(IHyperOpt.generate_roi_table(p), 5)}")
p = { p = {
'roi_t1': roi_limits['roi_t1_max'], 'roi_t1': roi_limits['roi_t1_max'],
'roi_t2': roi_limits['roi_t2_max'], 'roi_t2': roi_limits['roi_t2_max'],
@ -146,7 +147,7 @@ class IHyperOpt(ABC):
'roi_p2': roi_limits['roi_p2_max'], 'roi_p2': roi_limits['roi_p2_max'],
'roi_p3': roi_limits['roi_p3_max'], 'roi_p3': roi_limits['roi_p3_max'],
} }
logger.info(f"Max roi table: {IHyperOpt.generate_roi_table(p)}") logger.info(f"Max roi table: {round_dict(IHyperOpt.generate_roi_table(p), 5)}")
return [ return [
Integer(roi_limits['roi_t1_min'], roi_limits['roi_t1_max'], name='roi_t1'), Integer(roi_limits['roi_t1_min'], roi_limits['roi_t1_max'], name='roi_t1'),