Add test for protections-hyperopt
This commit is contained in:
parent
a661e0db6e
commit
3c41223333
@ -433,7 +433,7 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
stoploss = -0.05
|
stoploss = -0.05
|
||||||
timeframe = '15m'
|
timeframe = '15m'
|
||||||
# Define the parameter spaces
|
# Define the parameter spaces
|
||||||
coolback_lookback = IntParameter(2, 48, default=5, space="protection", optimize=True)
|
cooldown_lookback = IntParameter(2, 48, default=5, space="protection", optimize=True)
|
||||||
stop_duration = IntParameter(12, 200, default=5, space="protection", optimize=True)
|
stop_duration = IntParameter(12, 200, default=5, space="protection", optimize=True)
|
||||||
use_stop_protection = CategoricalParameter([True, False], default=True, space="protection", optimize=True)
|
use_stop_protection = CategoricalParameter([True, False], default=True, space="protection", optimize=True)
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ class MyAwesomeStrategy(IStrategy):
|
|||||||
|
|
||||||
prot.append({
|
prot.append({
|
||||||
"method": "CooldownPeriod",
|
"method": "CooldownPeriod",
|
||||||
"stop_duration_candles": self.coolback_lookback.value
|
"stop_duration_candles": self.cooldown_lookback.value
|
||||||
})
|
})
|
||||||
if self.use_stop_protection.value:
|
if self.use_stop_protection.value:
|
||||||
prot.append({
|
prot.append({
|
||||||
|
@ -294,7 +294,8 @@ class HyperStrategyMixin(object):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if category not in ('buy', 'sell', 'protection', None):
|
if category not in ('buy', 'sell', 'protection', None):
|
||||||
raise OperationalException('Category must be one of: "buy", "sell", "protection", None.')
|
raise OperationalException(
|
||||||
|
'Category must be one of: "buy", "sell", "protection", None.')
|
||||||
|
|
||||||
if category is None:
|
if category is None:
|
||||||
params = self.ft_buy_params + self.ft_sell_params + self.ft_protection_params
|
params = self.ft_buy_params + self.ft_sell_params + self.ft_protection_params
|
||||||
|
@ -1003,6 +1003,8 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
|||||||
hyperopt_conf.update({
|
hyperopt_conf.update({
|
||||||
'strategy': 'HyperoptableStrategy',
|
'strategy': 'HyperoptableStrategy',
|
||||||
'user_data_dir': Path(tmpdir),
|
'user_data_dir': Path(tmpdir),
|
||||||
|
'hyperopt_random_state': 42,
|
||||||
|
'spaces': ['buy', 'sell', 'protection']
|
||||||
})
|
})
|
||||||
hyperopt = Hyperopt(hyperopt_conf)
|
hyperopt = Hyperopt(hyperopt_conf)
|
||||||
assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto)
|
assert isinstance(hyperopt.custom_hyperopt, HyperOptAuto)
|
||||||
@ -1010,12 +1012,18 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
|||||||
|
|
||||||
assert hyperopt.backtesting.strategy.buy_rsi.in_space is True
|
assert hyperopt.backtesting.strategy.buy_rsi.in_space is True
|
||||||
assert hyperopt.backtesting.strategy.buy_rsi.value == 35
|
assert hyperopt.backtesting.strategy.buy_rsi.value == 35
|
||||||
|
assert hyperopt.backtesting.strategy.sell_rsi.value == 74
|
||||||
|
assert hyperopt.backtesting.strategy.protection_cooldown_lookback.value == 30
|
||||||
buy_rsi_range = hyperopt.backtesting.strategy.buy_rsi.range
|
buy_rsi_range = hyperopt.backtesting.strategy.buy_rsi.range
|
||||||
assert isinstance(buy_rsi_range, range)
|
assert isinstance(buy_rsi_range, range)
|
||||||
# Range from 0 - 50 (inclusive)
|
# Range from 0 - 50 (inclusive)
|
||||||
assert len(list(buy_rsi_range)) == 51
|
assert len(list(buy_rsi_range)) == 51
|
||||||
|
|
||||||
hyperopt.start()
|
hyperopt.start()
|
||||||
|
# All values should've changed.
|
||||||
|
assert hyperopt.backtesting.strategy.protection_cooldown_lookback.value != 30
|
||||||
|
assert hyperopt.backtesting.strategy.buy_rsi.value != 35
|
||||||
|
assert hyperopt.backtesting.strategy.sell_rsi.value != 74
|
||||||
|
|
||||||
|
|
||||||
def test_SKDecimal():
|
def test_SKDecimal():
|
||||||
|
@ -64,6 +64,17 @@ class HyperoptableStrategy(IStrategy):
|
|||||||
sell_rsi = IntParameter(low=50, high=100, default=70, space='sell')
|
sell_rsi = IntParameter(low=50, high=100, default=70, space='sell')
|
||||||
sell_minusdi = DecimalParameter(low=0, high=1, default=0.5001, decimals=3, space='sell',
|
sell_minusdi = DecimalParameter(low=0, high=1, default=0.5001, decimals=3, space='sell',
|
||||||
load=False)
|
load=False)
|
||||||
|
protection_cooldown_lookback = IntParameter([0, 50], default=30)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def protections(self):
|
||||||
|
prot = []
|
||||||
|
|
||||||
|
prot.append({
|
||||||
|
"method": "CooldownPeriod",
|
||||||
|
"stop_duration_candles": self.protection_cooldown_lookback.value
|
||||||
|
})
|
||||||
|
return prot
|
||||||
|
|
||||||
def informative_pairs(self):
|
def informative_pairs(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user