make --refresh-pairs-cached common option for optimization; added support for it into hyperopt

This commit is contained in:
hroff-1902
2019-04-22 21:24:45 +03:00
parent d3e956f7cc
commit ad85ac3dde
8 changed files with 205 additions and 74 deletions

View File

@@ -20,6 +20,7 @@ from pandas import DataFrame
from skopt import Optimizer
from skopt.space import Dimension
from freqtrade import DependencyException
from freqtrade.arguments import Arguments
from freqtrade.configuration import Configuration
from freqtrade.data.history import load_data
@@ -258,6 +259,8 @@ class Hyperopt(Backtesting):
datadir=Path(self.config['datadir']) if self.config.get('datadir') else None,
pairs=self.config['exchange']['pair_whitelist'],
ticker_interval=self.ticker_interval,
refresh_pairs=self.config.get('refresh_pairs', False),
exchange=self.exchange,
timerange=timerange
)
@@ -265,7 +268,10 @@ class Hyperopt(Backtesting):
self.strategy.advise_indicators = \
self.custom_hyperopt.populate_indicators # type: ignore
dump(self.strategy.tickerdata_to_dataframe(data), TICKERDATA_PICKLE)
# We don't need exchange instance anymore while running hyperopt
self.exchange = None # type: ignore
self.load_previous_results()
cpus = multiprocessing.cpu_count()
@@ -295,22 +301,16 @@ class Hyperopt(Backtesting):
self.log_trials_result()
def start(args: Namespace) -> None:
def setup_configuration(args: Namespace) -> Dict[str, Any]:
"""
Start Backtesting script
Prepare the configuration for the Hyperopt module
:param args: Cli args from Arguments()
:return: None
:return: Configuration
"""
# Remove noisy log messages
logging.getLogger('hyperopt.tpe').setLevel(logging.WARNING)
# Initialize configuration
# Monkey patch the configuration with hyperopt_conf.py
configuration = Configuration(args, RunMode.HYPEROPT)
logger.info('Starting freqtrade in Hyperopt mode')
config = configuration.load_config()
# Ensure we do not use Exchange credentials
config['exchange']['key'] = ''
config['exchange']['secret'] = ''
@@ -320,7 +320,25 @@ def start(args: Namespace) -> None:
"Read the documentation at "
"https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md "
"to understand how to configure hyperopt.")
raise ValueError("--strategy configured but not supported for hyperopt")
raise DependencyException("--strategy configured but not supported for hyperopt")
return config
def start(args: Namespace) -> None:
"""
Start Backtesting script
:param args: Cli args from Arguments()
:return: None
"""
# Initialize configuration
config = setup_configuration(args)
logger.info('Starting freqtrade in Hyperopt mode')
# Remove noisy log messages
logging.getLogger('hyperopt.tpe').setLevel(logging.WARNING)
# Initialize backtesting object
hyperopt = Hyperopt(config)
hyperopt.start()