diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index 078781114..e5c9241f0 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -136,7 +136,10 @@ def start_hyperopt_show(args: Dict[str, Any]) -> None: # Export parameters ... # TODO: make this optional? otherwise it'll overwrite previous parameters ... fn = HyperoptTools.get_strategy_filename(config, strategy_name) - HyperoptTools.export_params(val, strategy_name, fn.with_suffix('.json')) + if fn: + HyperoptTools.export_params(val, strategy_name, fn.with_suffix('.json')) + else: + logger.warn("Strategy not found, not exporting parameter file.") HyperoptTools.show_epoch_details(val, total_epochs, print_json, no_header, header_str="Epoch details") diff --git a/freqtrade/optimize/hyperopt_tools.py b/freqtrade/optimize/hyperopt_tools.py index 0d0f07c8e..dcffab8b2 100755 --- a/freqtrade/optimize/hyperopt_tools.py +++ b/freqtrade/optimize/hyperopt_tools.py @@ -3,7 +3,7 @@ import io import logging from copy import deepcopy from pathlib import Path -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional import rapidjson import tabulate @@ -21,18 +21,19 @@ logger = logging.getLogger(__name__) class HyperoptTools(): @staticmethod - def get_strategy_filename(config: Dict, strategy_name: str) -> Path: + def get_strategy_filename(config: Dict, strategy_name: str) -> Optional[Path]: """ Get Strategy-location (filename) from strategy_name """ from freqtrade.resolvers.strategy_resolver import StrategyResolver directory = Path(config.get('strategy_path', config['user_data_dir'] / USERPATH_STRATEGIES)) strategy_objs = StrategyResolver.search_all_objects(directory, False) - strategy = [s for s in strategy_objs if s['name'] == strategy_name] - if strategy: - strategy = strategy[0] + strategies = [s for s in strategy_objs if s['name'] == strategy_name] + if strategies: + strategy = strategies[0] return Path(strategy['location']) + return None @staticmethod def export_params(params, strategy_name: str, filename: Path):