• 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

84.62
/freqtrade/optimize/hyperopt_loss/hyperopt_loss_max_drawdown.py
1
"""
2
MaxDrawDownHyperOptLoss
3

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

9
from pandas import DataFrame
1✔
10

11
from freqtrade.data.metrics import calculate_max_drawdown
1✔
12
from freqtrade.optimize.hyperopt import IHyperOptLoss
1✔
13

14

15
class MaxDrawDownHyperOptLoss(IHyperOptLoss):
1✔
16

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

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

24
    @staticmethod
1✔
25
    def hyperopt_loss_function(results: DataFrame, trade_count: int,
1✔
26
                               min_date: datetime, max_date: datetime,
27
                               *args, **kwargs) -> float:
28

29
        """
30
        Objective function.
31

32
        Uses profit ratio weighted max_drawdown when drawdown is available.
33
        Otherwise directly optimizes profit ratio.
34
        """
35
        total_profit = results['profit_abs'].sum()
1✔
36
        try:
1✔
37
            max_drawdown = calculate_max_drawdown(results, value_col='profit_abs')
1✔
38
        except ValueError:
×
39
            # No losing trade, therefore no drawdown.
40
            return -total_profit
×
41
        return -total_profit / max_drawdown[0]
1✔
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