From 8d933636551860839450bcc4b692069680a026e4 Mon Sep 17 00:00:00 2001 From: Samuel Husso Date: Sat, 23 Dec 2017 09:21:04 +0200 Subject: [PATCH] filter nan values from total_profit and avg_profit --- freqtrade/optimize/hyperopt.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index e1d4e3a56..b3dc3d5e4 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -11,6 +11,7 @@ from operator import itemgetter from hyperopt import fmin, tpe, hp, Trials, STATUS_OK from hyperopt.mongoexp import MongoTrials from pandas import DataFrame +import numpy as np from freqtrade import exchange, optimize from freqtrade.exchange import Bittrex @@ -148,7 +149,9 @@ def optimizer(params): return { 'loss': trade_loss + profit_loss, 'status': STATUS_OK, - 'result': result + 'result': result, + 'total_profit': total_profit, + 'avg_profit': result_data['avg_profit'], } @@ -162,6 +165,10 @@ def format_results(results: DataFrame): ) +def filter_nan(result, filter_key): + return [r for r in result if not np.isnan(r[filter_key])] + + def buy_strategy_generator(params): def populate_buy_trend(dataframe: DataFrame) -> DataFrame: conditions = [] @@ -236,5 +243,10 @@ def start(args): best = fmin(fn=optimizer, space=SPACE, algo=tpe.suggest, max_evals=TOTAL_TRIES, trials=trials) logger.info('Best parameters:\n%s', json.dumps(best, indent=4)) - results = sorted(trials.results, key=itemgetter('loss')) + + filt_res = filter_nan(trials.results, 'total_profit') + filt_res = filter_nan(filt_res, 'avg_profit') + + results = sorted(filt_res, key=itemgetter('loss')) + logger.info('Best Result:\n%s', results[0]['result'])