From 26aa1ea32b1cfe4f74a67990ef2d123cb54bf462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Delacotte?= Date: Thu, 26 Feb 2026 19:47:31 +0100 Subject: [PATCH] CustomPerformanceLoss --- CustomPerformanceLoss.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CustomPerformanceLoss.py diff --git a/CustomPerformanceLoss.py b/CustomPerformanceLoss.py new file mode 100644 index 0000000..a595075 --- /dev/null +++ b/CustomPerformanceLoss.py @@ -0,0 +1,30 @@ +from freqtrade.optimize.hyperopt import IHyperOptLoss +from math import sqrt + + +class CustomPerformanceLoss(IHyperOptLoss): + + @staticmethod + def hyperopt_loss_function(results, trade_count, *args, **kwargs): + + total_profit = results['profit_total_abs'] + max_dd = results['max_drawdown'] + profit_factor = results['profit_factor'] + sqn = results['sqn'] + + # Sécurité minimale + if trade_count < 30: + return 1000 + + # Éviter division par zéro + if max_dd == 0: + max_dd = 0.0001 + + # Score principal + performance_score = ( + (profit_factor * sqn * total_profit) + / (max_dd ** 1.5) + ) + + # On retourne l'inverse car hyperopt minimise + return -performance_score \ No newline at end of file