merged with feat/short after feat/short added styling and comment changes PR
This commit is contained in:
commit
5ca3f49cb5
@ -232,10 +232,7 @@ class Backtesting:
|
|||||||
pair_data.loc[:, 'buy_tag'] = None # cleanup if buy_tag is exist
|
pair_data.loc[:, 'buy_tag'] = None # cleanup if buy_tag is exist
|
||||||
|
|
||||||
df_analyzed = self.strategy.advise_sell(
|
df_analyzed = self.strategy.advise_sell(
|
||||||
self.strategy.advise_buy(
|
self.strategy.advise_buy(pair_data, {'pair': pair}),
|
||||||
pair_data,
|
|
||||||
{'pair': pair}
|
|
||||||
),
|
|
||||||
{'pair': pair}
|
{'pair': pair}
|
||||||
).copy()
|
).copy()
|
||||||
# Trim startup period from analyzed dataframe
|
# Trim startup period from analyzed dataframe
|
||||||
|
@ -285,13 +285,11 @@ class Hyperopt:
|
|||||||
# Apply parameters
|
# Apply parameters
|
||||||
if HyperoptTools.has_space(self.config, 'buy'):
|
if HyperoptTools.has_space(self.config, 'buy'):
|
||||||
self.backtesting.strategy.advise_buy = ( # type: ignore
|
self.backtesting.strategy.advise_buy = ( # type: ignore
|
||||||
self.custom_hyperopt.buy_strategy_generator(params_dict)
|
self.custom_hyperopt.buy_strategy_generator(params_dict))
|
||||||
)
|
|
||||||
|
|
||||||
if HyperoptTools.has_space(self.config, 'sell'):
|
if HyperoptTools.has_space(self.config, 'sell'):
|
||||||
self.backtesting.strategy.advise_sell = ( # type: ignore
|
self.backtesting.strategy.advise_sell = ( # type: ignore
|
||||||
self.custom_hyperopt.sell_strategy_generator(params_dict)
|
self.custom_hyperopt.sell_strategy_generator(params_dict))
|
||||||
)
|
|
||||||
|
|
||||||
if HyperoptTools.has_space(self.config, 'protection'):
|
if HyperoptTools.has_space(self.config, 'protection'):
|
||||||
for attr_name, attr in self.backtesting.strategy.enumerate_parameters('protection'):
|
for attr_name, attr in self.backtesting.strategy.enumerate_parameters('protection'):
|
||||||
|
@ -193,11 +193,13 @@ class StrategyResolver(IResolver):
|
|||||||
# register temp path with the bot
|
# register temp path with the bot
|
||||||
abs_paths.insert(0, temp.resolve())
|
abs_paths.insert(0, temp.resolve())
|
||||||
|
|
||||||
strategy = StrategyResolver._load_object(paths=abs_paths,
|
strategy = StrategyResolver._load_object(
|
||||||
object_name=strategy_name,
|
paths=abs_paths,
|
||||||
add_source=True,
|
object_name=strategy_name,
|
||||||
kwargs={'config': config},
|
add_source=True,
|
||||||
)
|
kwargs={'config': config},
|
||||||
|
)
|
||||||
|
|
||||||
if strategy:
|
if strategy:
|
||||||
strategy._populate_fun_len = len(getfullargspec(strategy.populate_indicators).args)
|
strategy._populate_fun_len = len(getfullargspec(strategy.populate_indicators).args)
|
||||||
strategy._buy_fun_len = len(getfullargspec(strategy.populate_buy_trend).args)
|
strategy._buy_fun_len = len(getfullargspec(strategy.populate_buy_trend).args)
|
||||||
|
@ -553,15 +553,22 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
logger.debug(f'trigger: %s (pair=%s) {enter_type.value}=%s {exit_type.value}=%s',
|
logger.debug(f'trigger: %s (pair=%s) {enter_type.value}=%s {exit_type.value}=%s',
|
||||||
latest['date'], pair, str(enter), str(exit))
|
latest['date'], pair, str(enter), str(exit))
|
||||||
timeframe_seconds = timeframe_to_seconds(timeframe)
|
timeframe_seconds = timeframe_to_seconds(timeframe)
|
||||||
if self.ignore_expired_candle(latest_date=latest_date,
|
if self.ignore_expired_candle(
|
||||||
current_time=datetime.now(timezone.utc),
|
latest_date=latest_date,
|
||||||
timeframe_seconds=timeframe_seconds,
|
current_time=datetime.now(timezone.utc),
|
||||||
enter=enter):
|
timeframe_seconds=timeframe_seconds,
|
||||||
|
enter=enter
|
||||||
|
):
|
||||||
return False, exit, enter_tag_value
|
return False, exit, enter_tag_value
|
||||||
return enter, exit, enter_tag_value
|
return enter, exit, enter_tag_value
|
||||||
|
|
||||||
def ignore_expired_candle(self, latest_date: datetime, current_time: datetime,
|
def ignore_expired_candle(
|
||||||
timeframe_seconds: int, enter: bool):
|
self,
|
||||||
|
latest_date: datetime,
|
||||||
|
current_time: datetime,
|
||||||
|
timeframe_seconds: int,
|
||||||
|
enter: bool
|
||||||
|
):
|
||||||
if self.ignore_buying_expired_candle_after and enter:
|
if self.ignore_buying_expired_candle_after and enter:
|
||||||
time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds))
|
time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds))
|
||||||
return time_delta.total_seconds() > self.ignore_buying_expired_candle_after
|
return time_delta.total_seconds() > self.ignore_buying_expired_candle_after
|
||||||
|
@ -46,7 +46,7 @@ class SampleHyperOpt(IHyperOpt):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def buy_indicator_space() -> List[Dimension]:
|
def indicator_space() -> List[Dimension]:
|
||||||
"""
|
"""
|
||||||
Define your Hyperopt space for searching buy strategy parameters.
|
Define your Hyperopt space for searching buy strategy parameters.
|
||||||
"""
|
"""
|
||||||
@ -63,8 +63,7 @@ class SampleHyperOpt(IHyperOpt):
|
|||||||
Categorical([True, False], name='fastd-enabled'),
|
Categorical([True, False], name='fastd-enabled'),
|
||||||
Categorical([True, False], name='adx-enabled'),
|
Categorical([True, False], name='adx-enabled'),
|
||||||
Categorical([True, False], name='rsi-enabled'),
|
Categorical([True, False], name='rsi-enabled'),
|
||||||
Categorical(['boll', 'macd_cross_signal', 'sar_reversal'], name='trigger'),
|
Categorical(['boll', 'macd_cross_signal', 'sar_reversal'], name='trigger')
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -157,7 +156,7 @@ class SampleHyperOpt(IHyperOpt):
|
|||||||
'sell-macd_cross_signal',
|
'sell-macd_cross_signal',
|
||||||
'sell-sar_reversal'],
|
'sell-sar_reversal'],
|
||||||
name='sell-trigger'
|
name='sell-trigger'
|
||||||
),
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -750,6 +750,7 @@ def test_auto_hyperopt_interface(default_conf):
|
|||||||
# TODO-lev: Should these be 4,4 and 10?
|
# TODO-lev: Should these be 4,4 and 10?
|
||||||
assert len(all_params['buy']) == 4
|
assert len(all_params['buy']) == 4
|
||||||
assert len(all_params['sell']) == 4
|
assert len(all_params['sell']) == 4
|
||||||
|
# Number of Hyperoptable parameters
|
||||||
assert all_params['count'] == 10
|
assert all_params['count'] == 10
|
||||||
|
|
||||||
strategy.__class__.sell_rsi = IntParameter([0, 10], default=5, space='buy')
|
strategy.__class__.sell_rsi = IntParameter([0, 10], default=5, space='buy')
|
||||||
|
@ -385,13 +385,13 @@ def test_call_deprecated_function(result, monkeypatch, default_conf, caplog):
|
|||||||
assert isinstance(indicator_df, DataFrame)
|
assert isinstance(indicator_df, DataFrame)
|
||||||
assert 'adx' in indicator_df.columns
|
assert 'adx' in indicator_df.columns
|
||||||
|
|
||||||
buydf = strategy.advise_buy(result, metadata=metadata)
|
enterdf = strategy.advise_buy(result, metadata=metadata)
|
||||||
assert isinstance(buydf, DataFrame)
|
assert isinstance(enterdf, DataFrame)
|
||||||
assert 'buy' in buydf.columns
|
assert 'buy' in enterdf.columns
|
||||||
|
|
||||||
selldf = strategy.advise_sell(result, metadata=metadata)
|
exitdf = strategy.advise_sell(result, metadata=metadata)
|
||||||
assert isinstance(selldf, DataFrame)
|
assert isinstance(exitdf, DataFrame)
|
||||||
assert 'sell' in selldf
|
assert 'sell' in exitdf
|
||||||
|
|
||||||
assert log_has("DEPRECATED: Please migrate to using 'timeframe' instead of 'ticker_interval'.",
|
assert log_has("DEPRECATED: Please migrate to using 'timeframe' instead of 'ticker_interval'.",
|
||||||
caplog)
|
caplog)
|
||||||
|
Loading…
Reference in New Issue
Block a user