Make readable hyperopt best parameters result
This commit is contained in:
@@ -8,7 +8,7 @@ from functools import reduce
|
||||
from math import exp
|
||||
from operator import itemgetter
|
||||
|
||||
from hyperopt import fmin, tpe, hp, Trials, STATUS_OK, STATUS_FAIL
|
||||
from hyperopt import fmin, tpe, hp, Trials, STATUS_OK, STATUS_FAIL, space_eval
|
||||
from hyperopt.mongoexp import MongoTrials
|
||||
from pandas import DataFrame
|
||||
|
||||
@@ -209,7 +209,7 @@ def buy_strategy_generator(params):
|
||||
|
||||
|
||||
def start(args):
|
||||
global TOTAL_TRIES, PROCESSED
|
||||
global TOTAL_TRIES, PROCESSED, SPACE
|
||||
TOTAL_TRIES = args.epochs
|
||||
|
||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||
@@ -236,6 +236,11 @@ def start(args):
|
||||
trials = Trials()
|
||||
|
||||
best = fmin(fn=optimizer, space=SPACE, algo=tpe.suggest, max_evals=TOTAL_TRIES, trials=trials)
|
||||
|
||||
# Improve best parameter logging display
|
||||
if best:
|
||||
best = space_eval(SPACE, best)
|
||||
|
||||
logger.info('Best parameters:\n%s', json.dumps(best, indent=4))
|
||||
|
||||
results = sorted(trials.results, key=itemgetter('loss'))
|
||||
|
@@ -77,3 +77,40 @@ def test_no_log_if_loss_does_not_improve(mocker):
|
||||
})
|
||||
|
||||
assert not logger.called
|
||||
|
||||
|
||||
def test_fmin_best_results(mocker, caplog):
|
||||
fmin_result = {
|
||||
"adx": 1,
|
||||
"adx-value": 15.0,
|
||||
"fastd": 1,
|
||||
"fastd-value": 40.0,
|
||||
"green_candle": 1,
|
||||
"mfi": 0,
|
||||
"over_sar": 0,
|
||||
"rsi": 1,
|
||||
"rsi-value": 37.0,
|
||||
"trigger": 2,
|
||||
"uptrend_long_ema": 1,
|
||||
"uptrend_short_ema": 0,
|
||||
"uptrend_sma": 0
|
||||
}
|
||||
|
||||
mocker.patch('freqtrade.optimize.hyperopt.MongoTrials', return_value=create_trials(mocker))
|
||||
mocker.patch('freqtrade.optimize.preprocess')
|
||||
mocker.patch('freqtrade.optimize.load_data')
|
||||
mocker.patch('freqtrade.optimize.hyperopt.fmin', return_value=fmin_result)
|
||||
|
||||
args = mocker.Mock(epochs=1, config='config.json.example')
|
||||
start(args)
|
||||
|
||||
exists = [
|
||||
'Best parameters',
|
||||
'"adx": {\n "enabled": true,\n "value": 15.0\n },',
|
||||
'"green_candle": {\n "enabled": true\n },',
|
||||
'"mfi": {\n "enabled": false\n },',
|
||||
'"trigger": {\n "type": "ao_cross_zero"\n },'
|
||||
]
|
||||
|
||||
for line in exists:
|
||||
assert line in caplog.text
|
||||
|
Reference in New Issue
Block a user