• 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

96.43
/freqtrade/commands/hyperopt_commands.py
1
import logging
1✔
2
from operator import itemgetter
1✔
3
from typing import Any, Dict
1✔
4

5
from colorama import init as colorama_init
1✔
6

7
from freqtrade.configuration import setup_utils_configuration
1✔
8
from freqtrade.data.btanalysis import get_latest_hyperopt_file
1✔
9
from freqtrade.enums import RunMode
1✔
10
from freqtrade.exceptions import OperationalException
1✔
11
from freqtrade.optimize.optimize_reports import show_backtest_result
1✔
12

13

14
logger = logging.getLogger(__name__)
1✔
15

16

17
def start_hyperopt_list(args: Dict[str, Any]) -> None:
1✔
18
    """
19
    List hyperopt epochs previously evaluated
20
    """
21
    from freqtrade.optimize.hyperopt_tools import HyperoptTools
1✔
22

23
    config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
1✔
24

25
    print_colorized = config.get('print_colorized', False)
1✔
26
    print_json = config.get('print_json', False)
1✔
27
    export_csv = config.get('export_csv')
1✔
28
    no_details = config.get('hyperopt_list_no_details', False)
1✔
29
    no_header = False
1✔
30

31
    results_file = get_latest_hyperopt_file(
1✔
32
        config['user_data_dir'] / 'hyperopt_results',
33
        config.get('hyperoptexportfilename'))
34

35
    # Previous evaluations
36
    epochs, total_epochs = HyperoptTools.load_filtered_results(results_file, config)
1✔
37

38
    if print_colorized:
1✔
39
        colorama_init(autoreset=True)
1✔
40

41
    if not export_csv:
1✔
42
        try:
1✔
43
            print(HyperoptTools.get_result_table(config, epochs, total_epochs,
1✔
44
                                                 not config.get('hyperopt_list_best', False),
45
                                                 print_colorized, 0))
46
        except KeyboardInterrupt:
×
47
            print('User interrupted..')
×
48

49
    if epochs and not no_details:
1✔
50
        sorted_epochs = sorted(epochs, key=itemgetter('loss'))
1✔
51
        results = sorted_epochs[0]
1✔
52
        HyperoptTools.show_epoch_details(results, total_epochs, print_json, no_header)
1✔
53

54
    if epochs and export_csv:
1✔
55
        HyperoptTools.export_csv_file(
1✔
56
            config, epochs, export_csv
57
        )
58

59

60
def start_hyperopt_show(args: Dict[str, Any]) -> None:
1✔
61
    """
62
    Show details of a hyperopt epoch previously evaluated
63
    """
64
    from freqtrade.optimize.hyperopt_tools import HyperoptTools
1✔
65

66
    config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
1✔
67

68
    print_json = config.get('print_json', False)
1✔
69
    no_header = config.get('hyperopt_show_no_header', False)
1✔
70
    results_file = get_latest_hyperopt_file(
1✔
71
        config['user_data_dir'] / 'hyperopt_results',
72
        config.get('hyperoptexportfilename'))
73

74
    n = config.get('hyperopt_show_index', -1)
1✔
75

76
    # Previous evaluations
77
    epochs, total_epochs = HyperoptTools.load_filtered_results(results_file, config)
1✔
78

79
    filtered_epochs = len(epochs)
1✔
80

81
    if n > filtered_epochs:
1✔
82
        raise OperationalException(
1✔
83
            f"The index of the epoch to show should be less than {filtered_epochs + 1}.")
84
    if n < -filtered_epochs:
1✔
85
        raise OperationalException(
1✔
86
            f"The index of the epoch to show should be greater than {-filtered_epochs - 1}.")
87

88
    # Translate epoch index from human-readable format to pythonic
89
    if n > 0:
1✔
90
        n -= 1
1✔
91

92
    if epochs:
1✔
93
        val = epochs[n]
1✔
94

95
        metrics = val['results_metrics']
1✔
96
        if 'strategy_name' in metrics:
1✔
97
            strategy_name = metrics['strategy_name']
1✔
98
            show_backtest_result(strategy_name, metrics,
1✔
99
                                 metrics['stake_currency'], config.get('backtest_breakdown', []))
100

101
            HyperoptTools.try_export_params(config, strategy_name, val)
1✔
102

103
        HyperoptTools.show_epoch_details(val, total_epochs, print_json, no_header,
1✔
104
                                         header_str="Epoch details")
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