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
|
||||
|
||||
df_analyzed = self.strategy.advise_sell(
|
||||
self.strategy.advise_buy(
|
||||
pair_data,
|
||||
{'pair': pair}
|
||||
),
|
||||
self.strategy.advise_buy(pair_data, {'pair': pair}),
|
||||
{'pair': pair}
|
||||
).copy()
|
||||
# Trim startup period from analyzed dataframe
|
||||
|
@ -285,13 +285,11 @@ class Hyperopt:
|
||||
# Apply parameters
|
||||
if HyperoptTools.has_space(self.config, 'buy'):
|
||||
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'):
|
||||
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'):
|
||||
for attr_name, attr in self.backtesting.strategy.enumerate_parameters('protection'):
|
||||
|
@ -193,11 +193,13 @@ class StrategyResolver(IResolver):
|
||||
# register temp path with the bot
|
||||
abs_paths.insert(0, temp.resolve())
|
||||
|
||||
strategy = StrategyResolver._load_object(paths=abs_paths,
|
||||
strategy = StrategyResolver._load_object(
|
||||
paths=abs_paths,
|
||||
object_name=strategy_name,
|
||||
add_source=True,
|
||||
kwargs={'config': config},
|
||||
)
|
||||
|
||||
if strategy:
|
||||
strategy._populate_fun_len = len(getfullargspec(strategy.populate_indicators).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',
|
||||
latest['date'], pair, str(enter), str(exit))
|
||||
timeframe_seconds = timeframe_to_seconds(timeframe)
|
||||
if self.ignore_expired_candle(latest_date=latest_date,
|
||||
if self.ignore_expired_candle(
|
||||
latest_date=latest_date,
|
||||
current_time=datetime.now(timezone.utc),
|
||||
timeframe_seconds=timeframe_seconds,
|
||||
enter=enter):
|
||||
enter=enter
|
||||
):
|
||||
return False, exit, enter_tag_value
|
||||
return enter, exit, enter_tag_value
|
||||
|
||||
def ignore_expired_candle(self, latest_date: datetime, current_time: datetime,
|
||||
timeframe_seconds: int, enter: bool):
|
||||
def ignore_expired_candle(
|
||||
self,
|
||||
latest_date: datetime,
|
||||
current_time: datetime,
|
||||
timeframe_seconds: int,
|
||||
enter: bool
|
||||
):
|
||||
if self.ignore_buying_expired_candle_after and enter:
|
||||
time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds))
|
||||
return time_delta.total_seconds() > self.ignore_buying_expired_candle_after
|
||||
|
@ -46,7 +46,7 @@ class SampleHyperOpt(IHyperOpt):
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def buy_indicator_space() -> List[Dimension]:
|
||||
def indicator_space() -> List[Dimension]:
|
||||
"""
|
||||
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='adx-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
|
||||
@ -157,7 +156,7 @@ class SampleHyperOpt(IHyperOpt):
|
||||
'sell-macd_cross_signal',
|
||||
'sell-sar_reversal'],
|
||||
name='sell-trigger'
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
|
@ -750,6 +750,7 @@ def test_auto_hyperopt_interface(default_conf):
|
||||
# TODO-lev: Should these be 4,4 and 10?
|
||||
assert len(all_params['buy']) == 4
|
||||
assert len(all_params['sell']) == 4
|
||||
# Number of Hyperoptable parameters
|
||||
assert all_params['count'] == 10
|
||||
|
||||
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 'adx' in indicator_df.columns
|
||||
|
||||
buydf = strategy.advise_buy(result, metadata=metadata)
|
||||
assert isinstance(buydf, DataFrame)
|
||||
assert 'buy' in buydf.columns
|
||||
enterdf = strategy.advise_buy(result, metadata=metadata)
|
||||
assert isinstance(enterdf, DataFrame)
|
||||
assert 'buy' in enterdf.columns
|
||||
|
||||
selldf = strategy.advise_sell(result, metadata=metadata)
|
||||
assert isinstance(selldf, DataFrame)
|
||||
assert 'sell' in selldf
|
||||
exitdf = strategy.advise_sell(result, metadata=metadata)
|
||||
assert isinstance(exitdf, DataFrame)
|
||||
assert 'sell' in exitdf
|
||||
|
||||
assert log_has("DEPRECATED: Please migrate to using 'timeframe' instead of 'ticker_interval'.",
|
||||
caplog)
|
||||
|
Loading…
Reference in New Issue
Block a user