use Config typing in more places

This commit is contained in:
Matthias
2022-09-18 13:31:52 +02:00
parent 667853c504
commit 994c1c5ea0
32 changed files with 79 additions and 61 deletions

View File

@@ -10,6 +10,7 @@ from typing import Any, Dict
from pandas import DataFrame
from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_max_drawdown
from freqtrade.optimize.hyperopt import IHyperOptLoss
@@ -27,7 +28,7 @@ class CalmarHyperOptLoss(IHyperOptLoss):
trade_count: int,
min_date: datetime,
max_date: datetime,
config: Dict,
config: Config,
processed: Dict[str, DataFrame],
backtest_stats: Dict[str, Any],
*args,

View File

@@ -4,10 +4,9 @@ MaxDrawDownRelativeHyperOptLoss
This module defines the alternative HyperOptLoss class which can be used for
Hyperoptimization.
"""
from typing import Dict
from pandas import DataFrame
from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_underwater
from freqtrade.optimize.hyperopt import IHyperOptLoss
@@ -22,7 +21,7 @@ class MaxDrawDownRelativeHyperOptLoss(IHyperOptLoss):
"""
@staticmethod
def hyperopt_loss_function(results: DataFrame, config: Dict,
def hyperopt_loss_function(results: DataFrame, config: Config,
*args, **kwargs) -> float:
"""

View File

@@ -9,6 +9,8 @@ from typing import Any, Dict
from pandas import DataFrame
from freqtrade.constants import Config
class IHyperOptLoss(ABC):
"""
@@ -21,7 +23,7 @@ class IHyperOptLoss(ABC):
@abstractmethod
def hyperopt_loss_function(*, results: DataFrame, trade_count: int,
min_date: datetime, max_date: datetime,
config: Dict, processed: Dict[str, DataFrame],
config: Config, processed: Dict[str, DataFrame],
backtest_stats: Dict[str, Any],
**kwargs) -> float:
"""

View File

@@ -81,7 +81,7 @@ class HyperoptTools():
)
@staticmethod
def try_export_params(config: Dict[str, Any], strategy_name: str, params: Dict):
def try_export_params(config: Config, strategy_name: str, params: Dict):
if params.get(FTHYPT_FILEVERSION, 1) >= 2 and not config.get('disableparamexport', False):
# Export parameters ...
fn = HyperoptTools.get_strategy_filename(config, strategy_name)
@@ -91,7 +91,7 @@ class HyperoptTools():
logger.warning("Strategy not found, not exporting parameter file.")
@staticmethod
def has_space(config: Dict[str, Any], space: str) -> bool:
def has_space(config: Config, space: str) -> bool:
"""
Tell if the space value is contained in the configuration
"""
@@ -131,7 +131,7 @@ class HyperoptTools():
return False
@staticmethod
def load_filtered_results(results_file: Path, config: Dict[str, Any]) -> Tuple[List, int]:
def load_filtered_results(results_file: Path, config: Config) -> Tuple[List, int]:
filteroptions = {
'only_best': config.get('hyperopt_list_best', False),
'only_profitable': config.get('hyperopt_list_profitable', False),
@@ -346,7 +346,7 @@ class HyperoptTools():
return trials
@staticmethod
def get_result_table(config: dict, results: list, total_epochs: int, highlight_best: bool,
def get_result_table(config: Config, results: list, total_epochs: int, highlight_best: bool,
print_colorized: bool, remove_header: int) -> str:
"""
Log result table
@@ -444,7 +444,7 @@ class HyperoptTools():
return table
@staticmethod
def export_csv_file(config: dict, results: list, csv_file: str) -> None:
def export_csv_file(config: Config, results: list, csv_file: str) -> None:
"""
Log result to csv-file
"""

View File

@@ -7,7 +7,8 @@ from typing import Any, Dict, List, Union
from pandas import DataFrame, to_datetime
from tabulate import tabulate
from freqtrade.constants import DATETIME_PRINT_FORMAT, LAST_BT_RESULT_FN, UNLIMITED_STAKE_AMOUNT
from freqtrade.constants import (DATETIME_PRINT_FORMAT, LAST_BT_RESULT_FN, UNLIMITED_STAKE_AMOUNT,
Config)
from freqtrade.data.metrics import (calculate_cagr, calculate_csum, calculate_market_change,
calculate_max_drawdown)
from freqtrade.misc import decimals_per_coin, file_dump_joblib, file_dump_json, round_coin_value
@@ -898,7 +899,7 @@ def show_backtest_result(strategy: str, results: Dict[str, Any], stake_currency:
print()
def show_backtest_results(config: Dict, backtest_stats: Dict):
def show_backtest_results(config: Config, backtest_stats: Dict):
stake_currency = config['stake_currency']
for strategy, results in backtest_stats['strategy'].items():
@@ -918,7 +919,7 @@ def show_backtest_results(config: Dict, backtest_stats: Dict):
print('\nFor more details, please look at the detail tables above')
def show_sorted_pairlist(config: Dict, backtest_stats: Dict):
def show_sorted_pairlist(config: Config, backtest_stats: Dict):
if config.get('backtest_show_pair_list', False):
for strategy, results in backtest_stats['strategy'].items():
print(f"Pairs for Strategy {strategy}: \n[")