Merge branch 'develop' into align_userdata

This commit is contained in:
Matthias 2019-08-02 20:08:26 +02:00
commit 39e8e507d9
3 changed files with 18 additions and 11 deletions

View File

@ -30,7 +30,7 @@ def load_backtest_data(filename) -> pd.DataFrame:
filename = Path(filename) filename = Path(filename)
if not filename.is_file(): if not filename.is_file():
raise ValueError("File {filename} does not exist.") raise ValueError(f"File {filename} does not exist.")
with filename.open() as file: with filename.open() as file:
data = json_load(file) data = json_load(file)

View File

@ -78,6 +78,12 @@ class Hyperopt(Backtesting):
self.max_open_trades = 0 self.max_open_trades = 0
self.position_stacking = self.config.get('position_stacking', False), self.position_stacking = self.config.get('position_stacking', False),
if self.has_space('sell'):
# Make sure experimental is enabled
if 'experimental' not in self.config:
self.config['experimental'] = {}
self.config['experimental']['use_sell_signal'] = True
@staticmethod @staticmethod
def get_lock_filename(config) -> str: def get_lock_filename(config) -> str:
@ -129,13 +135,14 @@ class Hyperopt(Backtesting):
""" """
results = sorted(self.trials, key=itemgetter('loss')) results = sorted(self.trials, key=itemgetter('loss'))
best_result = results[0] best_result = results[0]
params = best_result['params']
log_str = self.format_results_logstring(best_result) log_str = self.format_results_logstring(best_result)
print(f"\nBest result:\n{log_str}\nwith values:") print(f"\nBest result:\n{log_str}\nwith values:")
pprint(best_result['params'], indent=4) pprint(params, indent=4)
if 'roi_t1' in best_result['params']: if self.has_space('roi'):
print("ROI table:") print("ROI table:")
pprint(self.custom_hyperopt.generate_roi_table(best_result['params']), indent=4) pprint(self.custom_hyperopt.generate_roi_table(params), indent=4)
def log_results(self, results) -> None: def log_results(self, results) -> None:
""" """
@ -167,9 +174,7 @@ class Hyperopt(Backtesting):
""" """
Tell if a space value is contained in the configuration Tell if a space value is contained in the configuration
""" """
if space in self.config['spaces'] or 'all' in self.config['spaces']: return any(s in self.config['spaces'] for s in [space, 'all'])
return True
return False
def hyperopt_space(self) -> List[Dimension]: def hyperopt_space(self) -> List[Dimension]:
""" """
@ -177,16 +182,16 @@ class Hyperopt(Backtesting):
""" """
spaces: List[Dimension] = [] spaces: List[Dimension] = []
if self.has_space('buy'): if self.has_space('buy'):
logger.debug("Hyperopt has 'buy' space")
spaces += self.custom_hyperopt.indicator_space() spaces += self.custom_hyperopt.indicator_space()
if self.has_space('sell'): if self.has_space('sell'):
logger.debug("Hyperopt has 'sell' space")
spaces += self.custom_hyperopt.sell_indicator_space() spaces += self.custom_hyperopt.sell_indicator_space()
# Make sure experimental is enabled
if 'experimental' not in self.config:
self.config['experimental'] = {}
self.config['experimental']['use_sell_signal'] = True
if self.has_space('roi'): if self.has_space('roi'):
logger.debug("Hyperopt has 'roi' space")
spaces += self.custom_hyperopt.roi_space() spaces += self.custom_hyperopt.roi_space()
if self.has_space('stoploss'): if self.has_space('stoploss'):
logger.debug("Hyperopt has 'stoploss' space")
spaces += self.custom_hyperopt.stoploss_space() spaces += self.custom_hyperopt.stoploss_space()
return spaces return spaces

View File

@ -26,6 +26,7 @@ from freqtrade.tests.conftest import (get_args, log_has, log_has_re,
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def hyperopt(default_conf, mocker): def hyperopt(default_conf, mocker):
default_conf.update({'spaces': ['all']})
patch_exchange(mocker) patch_exchange(mocker)
return Hyperopt(default_conf) return Hyperopt(default_conf)
@ -458,6 +459,7 @@ def test_start_calls_optimizer(mocker, default_conf, caplog, capsys) -> None:
hyperopt = Hyperopt(default_conf) hyperopt = Hyperopt(default_conf)
hyperopt.strategy.tickerdata_to_dataframe = MagicMock() hyperopt.strategy.tickerdata_to_dataframe = MagicMock()
hyperopt.custom_hyperopt.generate_roi_table = MagicMock(return_value={})
hyperopt.start() hyperopt.start()