Merge pull request #231 from gcarq/fix/hyperopt-filter-nan

filter nan values from total_profit and avg_profit
This commit is contained in:
Janne Sinivirta 2017-12-23 15:07:40 +02:00 committed by GitHub
commit efe0d77dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ from operator import itemgetter
from hyperopt import fmin, tpe, hp, Trials, STATUS_OK from hyperopt import fmin, tpe, hp, Trials, STATUS_OK
from hyperopt.mongoexp import MongoTrials from hyperopt.mongoexp import MongoTrials
from pandas import DataFrame from pandas import DataFrame
import numpy as np
from freqtrade import exchange, optimize from freqtrade import exchange, optimize
from freqtrade.exchange import Bittrex from freqtrade.exchange import Bittrex
@ -148,7 +149,9 @@ def optimizer(params):
return { return {
'loss': trade_loss + profit_loss, 'loss': trade_loss + profit_loss,
'status': STATUS_OK, '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 buy_strategy_generator(params):
def populate_buy_trend(dataframe: DataFrame) -> DataFrame: def populate_buy_trend(dataframe: DataFrame) -> DataFrame:
conditions = [] conditions = []
@ -236,5 +243,10 @@ def start(args):
best = fmin(fn=optimizer, space=SPACE, algo=tpe.suggest, max_evals=TOTAL_TRIES, trials=trials) 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)) 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']) logger.info('Best Result:\n%s', results[0]['result'])