From a3b600411570eaf23443c19bb3322b2c36d14cc6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 20 Nov 2018 19:41:07 +0100 Subject: [PATCH] IHyperopt: all methods static, somef ixes for mypy --- freqtrade/optimize/default_hyperopt.py | 3 ++- freqtrade/optimize/hyperopt_interface.py | 21 ++++++++++++++------- freqtrade/optimize/hyperopt_resolver.py | 4 ++-- user_data/hyperopts/sample_hyperopt.py | 3 ++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/freqtrade/optimize/default_hyperopt.py b/freqtrade/optimize/default_hyperopt.py index 723dfde17..6139f8140 100644 --- a/freqtrade/optimize/default_hyperopt.py +++ b/freqtrade/optimize/default_hyperopt.py @@ -36,7 +36,8 @@ class DefaultHyperOpts(IHyperOpt): dataframe['sar'] = ta.SAR(dataframe) return dataframe - def buy_strategy_generator(self, params: Dict[str, Any]) -> Callable: + @staticmethod + def buy_strategy_generator(params: Dict[str, Any]) -> Callable: """ Define the buy strategy parameters to be used by hyperopt """ diff --git a/freqtrade/optimize/hyperopt_interface.py b/freqtrade/optimize/hyperopt_interface.py index 8bc3866b2..d42206658 100644 --- a/freqtrade/optimize/hyperopt_interface.py +++ b/freqtrade/optimize/hyperopt_interface.py @@ -4,9 +4,10 @@ This module defines the interface to apply for hyperopts """ from abc import ABC, abstractmethod -from typing import Dict, Any, Callable +from typing import Dict, Any, Callable, List from pandas import DataFrame +from skopt.space import Dimension class IHyperOpt(ABC): @@ -20,40 +21,46 @@ class IHyperOpt(ABC): ticker_interval -> int: value of the ticker interval to use for the strategy """ + @staticmethod @abstractmethod - def populate_indicators(self, dataframe: DataFrame) -> DataFrame: + def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: """ Populate indicators that will be used in the Buy and Sell strategy :param dataframe: Raw data from the exchange and parsed by parse_ticker_dataframe() :return: a Dataframe with all mandatory indicators for the strategies """ + @staticmethod @abstractmethod - def buy_strategy_generator(self, params: Dict[str, Any]) -> Callable: + def buy_strategy_generator(params: Dict[str, Any]) -> Callable: """ Create a buy strategy generator """ + @staticmethod @abstractmethod - def indicator_space(self) -> Dict[str, Any]: + def indicator_space() -> List[Dimension]: """ Create an indicator space """ + @staticmethod @abstractmethod - def generate_roi_table(self, params: Dict) -> Dict[int, float]: + def generate_roi_table(params: Dict) -> Dict[int, float]: """ Create an roi table """ + @staticmethod @abstractmethod - def stoploss_space(self) -> Dict[str, Any]: + def stoploss_space() -> List[Dimension]: """ Create a stoploss space """ + @staticmethod @abstractmethod - def roi_space(self) -> Dict[str, Any]: + def roi_space() -> List[Dimension]: """ Create a roi space """ diff --git a/freqtrade/optimize/hyperopt_resolver.py b/freqtrade/optimize/hyperopt_resolver.py index 1c3a9d577..3d019e8df 100644 --- a/freqtrade/optimize/hyperopt_resolver.py +++ b/freqtrade/optimize/hyperopt_resolver.py @@ -35,7 +35,7 @@ class HyperOptResolver(object): self.hyperopt = self._load_hyperopt(hyperopt_name, extra_dir=config.get('hyperopt_path')) def _load_hyperopt( - self, hyperopt_name: str, extra_dir: Optional[str] = None) -> Optional[IHyperOpt]: + self, hyperopt_name: str, extra_dir: Optional[str] = None) -> IHyperOpt: """ Search and loads the specified hyperopt. :param hyperopt_name: name of the module to import @@ -75,7 +75,7 @@ class HyperOptResolver(object): # Generate spec based on absolute path spec = importlib.util.spec_from_file_location('user_data.hyperopts', module_path) module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) + spec.loader.exec_module(module) # type: ignore # importlib does not use typehints valid_hyperopts_gen = ( obj for name, obj in inspect.getmembers(module, inspect.isclass) diff --git a/user_data/hyperopts/sample_hyperopt.py b/user_data/hyperopts/sample_hyperopt.py index 83dc5f71a..f11236a82 100644 --- a/user_data/hyperopts/sample_hyperopt.py +++ b/user_data/hyperopts/sample_hyperopt.py @@ -45,7 +45,8 @@ class SampleHyperOpts(IHyperOpt): dataframe['sar'] = ta.SAR(dataframe) return dataframe - def buy_strategy_generator(self, params: Dict[str, Any]) -> Callable: + @staticmethod + def buy_strategy_generator(params: Dict[str, Any]) -> Callable: """ Define the buy strategy parameters to be used by hyperopt """