Fix wrong intendation for custom-hyperopt check
This commit is contained in:
parent
7be25313a5
commit
07a1c48e8c
@ -1,9 +1,7 @@
|
||||
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
from functools import reduce
|
||||
from math import exp
|
||||
from typing import Any, Callable, Dict, List
|
||||
from datetime import datetime
|
||||
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
@ -33,21 +31,6 @@ class DefaultHyperOpts(IHyperOpt):
|
||||
You can override it with your own hyperopt
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def hyperopt_loss_custom(results: DataFrame, trade_count: int,
|
||||
min_date: datetime, max_date: datetime, *args, **kwargs) -> float:
|
||||
"""
|
||||
Objective function, returns smaller number for more optimal results
|
||||
"""
|
||||
total_profit = results.profit_percent.sum()
|
||||
trade_duration = results.trade_duration.mean()
|
||||
|
||||
trade_loss = 1 - 0.25 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.8)
|
||||
profit_loss = max(0, 1 - total_profit / EXPECTED_MAX_PROFIT)
|
||||
duration_loss = 0.4 * min(trade_duration / MAX_ACCEPTED_TRADE_DURATION, 1)
|
||||
result = trade_loss + profit_loss + duration_loss
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
dataframe['adx'] = ta.ADX(dataframe)
|
||||
|
@ -80,11 +80,11 @@ class Hyperopt(Backtesting):
|
||||
hasattr(self.custom_hyperopt, 'hyperopt_loss_custom')):
|
||||
self.calculate_loss = self.custom_hyperopt.hyperopt_loss_custom # type: ignore
|
||||
|
||||
# Implement fallback to avoid odd crashes when custom-hyperopt fails to load.
|
||||
if not hasattr(self.custom_hyperopt, 'hyperopt_loss_custom'):
|
||||
logger.warning("Could not load hyperopt configuration. "
|
||||
"Falling back to legacy configuration.")
|
||||
raise OperationalException("Could not load hyperopt loss function.")
|
||||
# Implement fallback to avoid odd crashes when custom-hyperopt fails to load.
|
||||
if not hasattr(self.custom_hyperopt, 'hyperopt_loss_custom'):
|
||||
logger.warning("Could not load hyperopt configuration. "
|
||||
"Falling back to legacy configuration.")
|
||||
raise OperationalException("Could not load hyperopt loss function.")
|
||||
|
||||
# Populate functions here (hasattr is slow so should not be run during "regular" operations)
|
||||
if hasattr(self.custom_hyperopt, 'populate_buy_trend'):
|
||||
|
Loading…
Reference in New Issue
Block a user