Merge pull request #10221 from freqtrade/hyp/profit-drawdown

improve MaxDrawDownHyperOptLoss
This commit is contained in:
Matthias 2024-05-20 09:01:21 +02:00 committed by GitHub
commit 1717733b0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,23 +10,26 @@ individual needs.
from pandas import DataFrame
from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_max_drawdown
from freqtrade.optimize.hyperopt import IHyperOptLoss
# higher numbers penalize drawdowns more severely
# smaller numbers penalize drawdowns more severely
DRAWDOWN_MULT = 0.075
class ProfitDrawDownHyperOptLoss(IHyperOptLoss):
@staticmethod
def hyperopt_loss_function(results: DataFrame, trade_count: int, *args, **kwargs) -> float:
def hyperopt_loss_function(results: DataFrame, config: Config, *args, **kwargs) -> float:
total_profit = results["profit_abs"].sum()
try:
drawdown = calculate_max_drawdown(results, value_col="profit_abs")
drawdown = calculate_max_drawdown(
results, starting_balance=config["dry_run_wallet"], value_col="profit_abs"
)
relative_account_drawdown = drawdown.relative_account_drawdown
except ValueError:
relative_account_drawdown = 0
return -1 * (total_profit * (1 - relative_account_drawdown * DRAWDOWN_MULT))
return -1 * (total_profit - (relative_account_drawdown * total_profit) / DRAWDOWN_MULT)