• 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

93.94
/freqtrade/optimize/analysis/recursive_helpers.py
1
import logging
1✔
2
import time
1✔
3
from pathlib import Path
1✔
4
from typing import Any, Dict, List
1✔
5

6
from freqtrade.constants import Config
1✔
7
from freqtrade.exceptions import OperationalException
1✔
8
from freqtrade.optimize.analysis.recursive import RecursiveAnalysis
1✔
9
from freqtrade.resolvers import StrategyResolver
1✔
10

11

12
logger = logging.getLogger(__name__)
1✔
13

14

15
class RecursiveAnalysisSubFunctions:
1✔
16

17
    @staticmethod
1✔
18
    def text_table_recursive_analysis_instances(
1✔
19
            recursive_instances: List[RecursiveAnalysis]):
20
        startups = recursive_instances[0]._startup_candle
1✔
21
        headers = ['indicators']
1✔
22
        for candle in startups:
1✔
23
            headers.append(candle)
1✔
24

25
        data = []
1✔
26
        for inst in recursive_instances:
1✔
27
            if len(inst.dict_recursive) > 0:
1✔
28
                for indicator, values in inst.dict_recursive.items():
1✔
29
                    temp_data = [indicator]
1✔
30
                    for candle in startups:
1✔
31
                        temp_data.append(values.get(int(candle), '-'))
1✔
32
                    data.append(temp_data)
1✔
33

34
        if len(data) > 0:
1✔
35
            from tabulate import tabulate
1✔
36
            table = tabulate(data, headers=headers, tablefmt="orgtbl")
1✔
37
            print(table)
1✔
38
            return table, headers, data
1✔
39

40
        return None, None, data
1✔
41

42
    @staticmethod
1✔
43
    def calculate_config_overrides(config: Config):
1✔
44
        if 'timerange' not in config:
1✔
45
            # setting a timerange is enforced here
46
            raise OperationalException(
1✔
47
                "Please set a timerange. "
48
                "A timerange of 5000 candles are enough for recursive analysis."
49
            )
50

51
        if config.get('backtest_cache') is None:
1✔
52
            config['backtest_cache'] = 'none'
1✔
53
        elif config['backtest_cache'] != 'none':
×
54
            logger.info(f"backtest_cache = "
×
55
                        f"{config['backtest_cache']} detected. "
56
                        f"Inside recursive-analysis it is enforced to be 'none'. "
57
                        f"Changed it to 'none'")
58
            config['backtest_cache'] = 'none'
×
59
        return config
1✔
60

61
    @staticmethod
1✔
62
    def initialize_single_recursive_analysis(config: Config, strategy_obj: Dict[str, Any]):
1✔
63

64
        logger.info(f"Recursive test of {Path(strategy_obj['location']).name} started.")
1✔
65
        start = time.perf_counter()
1✔
66
        current_instance = RecursiveAnalysis(config, strategy_obj)
1✔
67
        current_instance.start()
1✔
68
        elapsed = time.perf_counter() - start
1✔
69
        logger.info(f"Checking recursive and indicator-only lookahead bias of indicators "
1✔
70
                    f"of {Path(strategy_obj['location']).name} "
71
                    f"took {elapsed:.0f} seconds.")
72
        return current_instance
1✔
73

74
    @staticmethod
1✔
75
    def start(config: Config):
1✔
76
        config = RecursiveAnalysisSubFunctions.calculate_config_overrides(config)
1✔
77

78
        strategy_objs = StrategyResolver.search_all_objects(
1✔
79
            config, enum_failed=False, recursive=config.get('recursive_strategy_search', False))
80

81
        RecursiveAnalysis_instances = []
1✔
82

83
        # unify --strategy and --strategy-list to one list
84
        if not (strategy_list := config.get('strategy_list', [])):
1✔
85
            if config.get('strategy') is None:
1✔
86
                raise OperationalException(
1✔
87
                    "No Strategy specified. Please specify a strategy via --strategy"
88
                )
89
            strategy_list = [config['strategy']]
1✔
90

91
        # check if strategies can be properly loaded, only check them if they can be.
92
        for strat in strategy_list:
1✔
93
            for strategy_obj in strategy_objs:
1✔
94
                if strategy_obj['name'] == strat and strategy_obj not in strategy_list:
1✔
95
                    RecursiveAnalysis_instances.append(
1✔
96
                        RecursiveAnalysisSubFunctions.initialize_single_recursive_analysis(
97
                            config, strategy_obj))
98
                    break
1✔
99

100
        # report the results
101
        if RecursiveAnalysis_instances:
1✔
102
            RecursiveAnalysisSubFunctions.text_table_recursive_analysis_instances(
1✔
103
                RecursiveAnalysis_instances)
104
        else:
105
            logger.error("There was no strategy specified through --strategy "
×
106
                         "or timeframe was not specified.")
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