• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

freqtrade / freqtrade / 9394559170

26 Apr 2024 06:36AM UTC coverage: 94.656% (-0.02%) from 94.674%
9394559170

push

github

xmatthias
Loader should be passed as kwarg for clarity

20280 of 21425 relevant lines covered (94.66%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/freqtrade/optimize/hyperopt_loss/hyperopt_loss_max_drawdown_relative.py
1
"""
2
MaxDrawDownRelativeHyperOptLoss
3

4
This module defines the alternative HyperOptLoss class which can be used for
5
Hyperoptimization.
6
"""
7
from pandas import DataFrame
1✔
8

9
from freqtrade.constants import Config
1✔
10
from freqtrade.data.metrics import calculate_underwater
1✔
11
from freqtrade.optimize.hyperopt import IHyperOptLoss
1✔
12

13

14
class MaxDrawDownRelativeHyperOptLoss(IHyperOptLoss):
1✔
15

16
    """
17
    Defines the loss function for hyperopt.
18

19
    This implementation optimizes for max draw down and profit
20
    Less max drawdown more profit -> Lower return value
21
    """
22

23
    @staticmethod
1✔
24
    def hyperopt_loss_function(results: DataFrame, config: Config,
1✔
25
                               *args, **kwargs) -> float:
26

27
        """
28
        Objective function.
29

30
        Uses profit ratio weighted max_drawdown when drawdown is available.
31
        Otherwise directly optimizes profit ratio.
32
        """
33
        total_profit = results['profit_abs'].sum()
1✔
34
        try:
1✔
35
            drawdown_df = calculate_underwater(
1✔
36
                results,
37
                value_col='profit_abs',
38
                starting_balance=config['dry_run_wallet']
39
            )
40
            max_drawdown = abs(min(drawdown_df['drawdown']))
1✔
41
            relative_drawdown = max(drawdown_df['drawdown_relative'])
1✔
42
            if max_drawdown == 0:
1✔
43
                return -total_profit
×
44
            return -total_profit / max_drawdown / relative_drawdown
1✔
45
        except (Exception, ValueError):
×
46
            return -total_profit
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc