From e49e361da5481418caf626d1088217bd8103aae5 Mon Sep 17 00:00:00 2001 From: MoonGem <34537029+MoonGem@users.noreply.github.com> Date: Thu, 22 Mar 2018 23:00:47 -0500 Subject: [PATCH] Update hyperopt.py --- freqtrade/optimize/hyperopt.py | 47 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 7dcd46fd2..c290245f6 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -21,7 +21,7 @@ import talib.abstract as ta from hyperopt import STATUS_FAIL, STATUS_OK, Trials, fmin, hp, space_eval, tpe from hyperopt.mongoexp import MongoTrials from pandas import DataFrame - +import fire import freqtrade.vendor.qtpylib.indicators as qtpylib from freqtrade.arguments import Arguments from freqtrade.configuration import Configuration @@ -31,6 +31,18 @@ from freqtrade.optimize.backtesting import Backtesting from user_data.hyperopt_conf import hyperopt_optimize_conf + +class Testz(): + db_name = 'freqtrade_hyperopt' + MongoTrials( + arg='mongo://127.0.0.1:1234/{}/jobs'.format(db_name), + exp_key='exp1' + ) + async = 'Null' + attachments = 'Null' + + + class Hyperopt(Backtesting): """ Hyperopt class, this class contains all the logic to run a hyperopt simulation @@ -68,7 +80,7 @@ class Hyperopt(Backtesting): # Hyperopt Trials self.trials_file = os.path.join('user_data', 'hyperopt_trials.pickle') - self.trials = Trials() + self.trials = Testz() @staticmethod def populate_indicators(dataframe: DataFrame) -> DataFrame: @@ -515,12 +527,6 @@ class Hyperopt(Backtesting): self.logger.info( 'Start scripts/start-mongodb.sh and start-hyperopt-worker.sh manually!' ) - - db_name = 'freqtrade_hyperopt' - self.trials = MongoTrials( - arg='mongo://127.0.0.1:1234/{}/jobs'.format(db_name), - exp_key='exp1' - ) else: self.logger.info('Preparing Trials..') signal.signal(signal.SIGINT, self.signal_handler) @@ -536,26 +542,24 @@ class Hyperopt(Backtesting): self.total_tries ) - try: - # change the Logging format - self.logging.set_format('\n%(message)s') + A = self.generate_optimizer + B = self.hyperopt_space() + C = self.total_tries + def Tests(): best_parameters = fmin( fn=self.generate_optimizer, space=self.hyperopt_space(), algo=tpe.suggest, max_evals=self.total_tries, - trials=self.trials + trials=MongoTrials('mongo://127.0.0.1:1234/freqtrade_hyperopt/jobs') ) - - results = sorted(self.trials.results, key=itemgetter('loss')) - best_result = results[0]['result'] - - except ValueError: - best_parameters = {} - best_result = 'Sorry, Hyperopt was not able to find good parameters. Please ' \ - 'try with more epochs (param: -e).' - + # change the Logging format + self.logging.set_format('\n%(message)s') + # best_parameters = Tests(self) + best_parameters = Tests() + results = sorted(self.trials.results, key=itemgetter('loss')) + best_result = results[0]['result'] # Improve best parameter logging display if best_parameters: best_parameters = space_eval( @@ -586,6 +590,7 @@ class Hyperopt(Backtesting): sys.exit(0) + def start(args: Namespace) -> None: """ Start Backtesting script