mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Merge pull request #10221 from freqtrade/hyp/profit-drawdown
improve MaxDrawDownHyperOptLoss
This commit is contained in:
commit
1717733b0f
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user