unit tests for optimize.hyperopt

This commit is contained in:
Janne Sinivirta
2017-12-26 10:08:10 +02:00
parent 7b0beb0afa
commit 7f44ba6df4
2 changed files with 86 additions and 9 deletions

View File

@@ -25,12 +25,10 @@ logging.getLogger('hyperopt.tpe').setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
# set TARGET_TRADES to suit your number concurrent trades so its realistic to 20days of data
TARGET_TRADES = 1100
TOTAL_TRIES = None
_CURRENT_TRIES = 0
CURRENT_BEST_LOSS = 100
# this is expexted avg profit * expected trade count
@@ -111,6 +109,13 @@ def log_results(results):
sys.stdout.flush()
def calculate_loss(total_profit: float, trade_count: int):
""" objective function, returns smaller number for more optimal results """
trade_loss = 1 - 0.35 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.2)
profit_loss = max(0, 1 - total_profit / EXPECTED_MAX_PROFIT)
return trade_loss + profit_loss
def optimizer(params):
global _CURRENT_TRIES
@@ -129,9 +134,8 @@ def optimizer(params):
'loss': float('inf')
}
trade_loss = 1 - 0.35 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.2)
profit_loss = max(0, 1 - total_profit / EXPECTED_MAX_PROFIT)
loss = trade_loss + profit_loss
loss = calculate_loss(total_profit, trade_count)
_CURRENT_TRIES += 1
log_results({