minor: add OnlyProfitHyperOptLoss

This commit is contained in:
hroff-1902 2019-07-23 18:51:24 +03:00
parent 41f24898e5
commit 0c2c094db6
3 changed files with 49 additions and 13 deletions

View File

@ -3,27 +3,26 @@ DefaultHyperOptLoss
This module defines the default HyperoptLoss class which is being used for This module defines the default HyperoptLoss class which is being used for
Hyperoptimization. Hyperoptimization.
""" """
from math import exp from math import exp
from pandas import DataFrame from pandas import DataFrame
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
# Define some constants:
# set TARGET_TRADES to suit your number concurrent trades so its realistic # Set TARGET_TRADES to suit your number concurrent trades so its realistic
# to the number of days # to the number of days
TARGET_TRADES = 600 TARGET_TRADES = 600
# This is assumed to be expected avg profit * expected trade count. # This is assumed to be expected avg profit * expected trade count.
# For example, for 0.35% avg per trade (or 0.0035 as ratio) and 1100 trades, # For example, for 0.35% avg per trade (or 0.0035 as ratio) and 1100 trades,
# self.expected_max_profit = 3.85 # expected max profit = 3.85
# Check that the reported Σ% values do not exceed this! # Check that the reported Σ% values do not exceed this!
# Note, this is ratio. 3.85 stated above means 385Σ%. # Note, this is ratio. 3.85 stated above means 385Σ%.
EXPECTED_MAX_PROFIT = 3.0 EXPECTED_MAX_PROFIT = 3.0
# max average trade duration in minutes # Max average trade duration in minutes.
# if eval ends with higher value, we consider it a failed eval # If eval ends with higher value, we consider it a failed eval.
MAX_ACCEPTED_TRADE_DURATION = 300 MAX_ACCEPTED_TRADE_DURATION = 300

View File

@ -0,0 +1,34 @@
"""
OnlyProfitHyperOptLoss
This module defines the alternative HyperOptLoss class which can be used for
Hyperoptimization.
"""
from pandas import DataFrame
from freqtrade.optimize.hyperopt import IHyperOptLoss
# This is assumed to be expected avg profit * expected trade count.
# For example, for 0.35% avg per trade (or 0.0035 as ratio) and 1100 trades,
# expected max profit = 3.85
# Check that the reported Σ% values do not exceed this!
# Note, this is ratio. 3.85 stated above means 385Σ%.
EXPECTED_MAX_PROFIT = 3.0
class OnlyProfitHyperOptLoss(IHyperOptLoss):
"""
Defines the loss function for hyperopt.
This implementation takes only profit into account.
"""
@staticmethod
def hyperopt_loss_function(results: DataFrame, trade_count: int,
*args, **kwargs) -> float:
"""
Objective function, returns smaller number for better results.
"""
total_profit = results.profit_percent.sum()
return max(0, 1 - total_profit / EXPECTED_MAX_PROFIT)

View File

@ -1,8 +1,9 @@
""" """
IHyperOptLoss interface SharpeHyperOptLoss
This module defines the interface for the loss-function for hyperopts
"""
This module defines the alternative HyperOptLoss class which can be used for
Hyperoptimization.
"""
from datetime import datetime from datetime import datetime
from pandas import DataFrame from pandas import DataFrame
@ -13,8 +14,9 @@ from freqtrade.optimize.hyperopt import IHyperOptLoss
class SharpeHyperOptLoss(IHyperOptLoss): class SharpeHyperOptLoss(IHyperOptLoss):
""" """
Defines the a loss function for hyperopt. Defines the loss function for hyperopt.
This implementation uses the sharpe ratio calculation.
This implementation uses the Sharpe Ratio calculation.
""" """
@staticmethod @staticmethod
@ -22,8 +24,9 @@ class SharpeHyperOptLoss(IHyperOptLoss):
min_date: datetime, max_date: datetime, min_date: datetime, max_date: datetime,
*args, **kwargs) -> float: *args, **kwargs) -> float:
""" """
Objective function, returns smaller number for more optimal results Objective function, returns smaller number for more optimal results.
Using sharpe ratio calculation
Uses Sharpe Ratio calculation.
""" """
total_profit = results.profit_percent total_profit = results.profit_percent
days_period = (max_date - min_date).days days_period = (max_date - min_date).days