Update hyperopt.py

This commit is contained in:
MoonGem 2018-03-22 23:00:47 -05:00 committed by GitHub
parent 8d65452631
commit e49e361da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ import talib.abstract as ta
from hyperopt import STATUS_FAIL, STATUS_OK, Trials, fmin, hp, space_eval, tpe from hyperopt import STATUS_FAIL, STATUS_OK, Trials, fmin, hp, space_eval, tpe
from hyperopt.mongoexp import MongoTrials from hyperopt.mongoexp import MongoTrials
from pandas import DataFrame from pandas import DataFrame
import fire
import freqtrade.vendor.qtpylib.indicators as qtpylib import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.arguments import Arguments from freqtrade.arguments import Arguments
from freqtrade.configuration import Configuration from freqtrade.configuration import Configuration
@ -31,6 +31,18 @@ from freqtrade.optimize.backtesting import Backtesting
from user_data.hyperopt_conf import hyperopt_optimize_conf 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): class Hyperopt(Backtesting):
""" """
Hyperopt class, this class contains all the logic to run a hyperopt simulation Hyperopt class, this class contains all the logic to run a hyperopt simulation
@ -68,7 +80,7 @@ class Hyperopt(Backtesting):
# Hyperopt Trials # Hyperopt Trials
self.trials_file = os.path.join('user_data', 'hyperopt_trials.pickle') self.trials_file = os.path.join('user_data', 'hyperopt_trials.pickle')
self.trials = Trials() self.trials = Testz()
@staticmethod @staticmethod
def populate_indicators(dataframe: DataFrame) -> DataFrame: def populate_indicators(dataframe: DataFrame) -> DataFrame:
@ -515,12 +527,6 @@ class Hyperopt(Backtesting):
self.logger.info( self.logger.info(
'Start scripts/start-mongodb.sh and start-hyperopt-worker.sh manually!' '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: else:
self.logger.info('Preparing Trials..') self.logger.info('Preparing Trials..')
signal.signal(signal.SIGINT, self.signal_handler) signal.signal(signal.SIGINT, self.signal_handler)
@ -536,26 +542,24 @@ class Hyperopt(Backtesting):
self.total_tries self.total_tries
) )
try: A = self.generate_optimizer
# change the Logging format B = self.hyperopt_space()
self.logging.set_format('\n%(message)s') C = self.total_tries
def Tests():
best_parameters = fmin( best_parameters = fmin(
fn=self.generate_optimizer, fn=self.generate_optimizer,
space=self.hyperopt_space(), space=self.hyperopt_space(),
algo=tpe.suggest, algo=tpe.suggest,
max_evals=self.total_tries, max_evals=self.total_tries,
trials=self.trials trials=MongoTrials('mongo://127.0.0.1:1234/freqtrade_hyperopt/jobs')
) )
# change the Logging format
results = sorted(self.trials.results, key=itemgetter('loss')) self.logging.set_format('\n%(message)s')
best_result = results[0]['result'] # best_parameters = Tests(self)
best_parameters = Tests()
except ValueError: results = sorted(self.trials.results, key=itemgetter('loss'))
best_parameters = {} best_result = results[0]['result']
best_result = 'Sorry, Hyperopt was not able to find good parameters. Please ' \
'try with more epochs (param: -e).'
# Improve best parameter logging display # Improve best parameter logging display
if best_parameters: if best_parameters:
best_parameters = space_eval( best_parameters = space_eval(
@ -586,6 +590,7 @@ class Hyperopt(Backtesting):
sys.exit(0) sys.exit(0)
def start(args: Namespace) -> None: def start(args: Namespace) -> None:
""" """
Start Backtesting script Start Backtesting script