[SQUASH] Use HyperStrategyMixin as part of IStrategy interface.
This commit is contained in:
@@ -70,10 +70,6 @@ class Hyperopt:
|
||||
self.backtesting = Backtesting(self.config)
|
||||
|
||||
if not self.config.get('hyperopt'):
|
||||
if not getattr(self.backtesting.strategy, 'HYPER_STRATEGY', False):
|
||||
raise OperationalException('Strategy is not auto-hyperoptable. Specify --hyperopt '
|
||||
'parameter or add HyperStrategyMixin mixin to your '
|
||||
'strategy class.')
|
||||
self.custom_hyperopt = HyperOptAuto(self.config)
|
||||
else:
|
||||
self.custom_hyperopt = HyperOptResolver.load_hyperopt(self.config)
|
||||
|
@@ -7,7 +7,6 @@ from typing import Any, Callable, Dict, List
|
||||
from pandas import DataFrame
|
||||
from skopt.space import Categorical, Dimension, Integer, Real # noqa
|
||||
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.optimize.hyperopt_interface import IHyperOpt
|
||||
|
||||
|
||||
@@ -19,9 +18,6 @@ class HyperOptAuto(IHyperOpt):
|
||||
"""
|
||||
|
||||
def buy_strategy_generator(self, params: Dict[str, Any]) -> Callable:
|
||||
if not getattr(self.strategy, 'HYPER_STRATEGY', False):
|
||||
raise OperationalException('Strategy must inherit from IHyperStrategy.')
|
||||
|
||||
def populate_buy_trend(dataframe: DataFrame, metadata: dict):
|
||||
for attr_name, attr in self.strategy.enumerate_parameters('buy'):
|
||||
attr.value = params[attr_name]
|
||||
@@ -30,9 +26,6 @@ class HyperOptAuto(IHyperOpt):
|
||||
return populate_buy_trend
|
||||
|
||||
def sell_strategy_generator(self, params: Dict[str, Any]) -> Callable:
|
||||
if not getattr(self.strategy, 'HYPER_STRATEGY', False):
|
||||
raise OperationalException('Strategy must inherit from IHyperStrategy.')
|
||||
|
||||
def populate_buy_trend(dataframe: DataFrame, metadata: dict):
|
||||
for attr_name, attr in self.strategy.enumerate_parameters('sell'):
|
||||
attr.value = params[attr_name]
|
||||
@@ -54,9 +47,6 @@ class HyperOptAuto(IHyperOpt):
|
||||
return default_func
|
||||
|
||||
def _generate_indicator_space(self, category):
|
||||
if not getattr(self.strategy, 'HYPER_STRATEGY', False):
|
||||
raise OperationalException('Strategy must inherit from IHyperStrategy.')
|
||||
|
||||
for attr_name, attr in self.strategy.enumerate_parameters(category):
|
||||
yield attr.get_space(attr_name)
|
||||
|
||||
|
@@ -5,14 +5,14 @@ This module defines the interface to apply for hyperopt
|
||||
import logging
|
||||
import math
|
||||
from abc import ABC
|
||||
from typing import Any, Callable, Dict, List, Union
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
from skopt.space import Categorical, Dimension, Integer, Real
|
||||
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.exchange import timeframe_to_minutes
|
||||
from freqtrade.misc import round_dict
|
||||
from freqtrade.strategy import IStrategy, HyperStrategyMixin
|
||||
from freqtrade.strategy import IStrategy
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -34,7 +34,7 @@ class IHyperOpt(ABC):
|
||||
"""
|
||||
ticker_interval: str # DEPRECATED
|
||||
timeframe: str
|
||||
strategy: Union[IStrategy, HyperStrategyMixin]
|
||||
strategy: IStrategy
|
||||
|
||||
def __init__(self, config: dict) -> None:
|
||||
self.config = config
|
||||
|
Reference in New Issue
Block a user