From 2a1ff7f9b3ea7b52f53e6868294458c4b361fede Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 19 May 2024 09:45:32 +0200 Subject: [PATCH 1/2] Try improve profit-drawdown hyperopt --- .../hyperopt_loss/hyperopt_loss_profit_drawdown.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py b/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py index ac3f82700..6d573414e 100644 --- a/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py +++ b/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py @@ -10,6 +10,7 @@ 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 @@ -20,13 +21,15 @@ 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 * 1 * total_profit)) From 480477d17af19bf0fcbaa1c9f1a87f5134fd3a0c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 19 May 2024 10:03:34 +0200 Subject: [PATCH 2/2] Improve profitdrawdownhyperopt balancing --- .../optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py b/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py index 6d573414e..e5ec6075e 100644 --- a/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py +++ b/freqtrade/optimize/hyperopt_loss/hyperopt_loss_profit_drawdown.py @@ -15,7 +15,7 @@ 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 @@ -32,4 +32,4 @@ class ProfitDrawDownHyperOptLoss(IHyperOptLoss): except ValueError: relative_account_drawdown = 0 - return -1 * (total_profit - (relative_account_drawdown * 1 * total_profit)) + return -1 * (total_profit - (relative_account_drawdown * total_profit) / DRAWDOWN_MULT)