Update some tests for updated backtest interface
This commit is contained in:
parent
7373b39015
commit
faf5cfa66d
@ -807,8 +807,8 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
return self.populate_buy_trend(dataframe) # type: ignore
|
return self.populate_buy_trend(dataframe) # type: ignore
|
||||||
else:
|
else:
|
||||||
df = self.populate_buy_trend(dataframe, metadata)
|
df = self.populate_buy_trend(dataframe, metadata)
|
||||||
# TODO-lev: IF both buy and enter_long exist, this will fail.
|
if 'enter_long' not in df.columns:
|
||||||
df = df.rename({'buy': 'enter_long', 'buy_tag': 'long_tag'}, axis='columns')
|
df = df.rename({'buy': 'enter_long', 'buy_tag': 'long_tag'}, axis='columns')
|
||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
@ -829,8 +829,9 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
return self.populate_sell_trend(dataframe) # type: ignore
|
return self.populate_sell_trend(dataframe) # type: ignore
|
||||||
else:
|
else:
|
||||||
df = self.populate_sell_trend(dataframe, metadata)
|
df = self.populate_sell_trend(dataframe, metadata)
|
||||||
# TODO-lev: IF both sell and exit_long exist, this will fail at a later point
|
if 'exit_long' not in df.columns:
|
||||||
return df.rename({'sell': 'exit_long'}, axis='columns')
|
df = df.rename({'sell': 'exit_long'}, axis='columns')
|
||||||
|
return df
|
||||||
|
|
||||||
def leverage(self, pair: str, current_time: datetime, current_rate: float,
|
def leverage(self, pair: str, current_time: datetime, current_rate: float,
|
||||||
proposed_leverage: float, max_leverage: float,
|
proposed_leverage: float, max_leverage: float,
|
||||||
|
@ -44,8 +44,12 @@ def _get_frame_time_from_offset(offset):
|
|||||||
|
|
||||||
|
|
||||||
def _build_backtest_dataframe(data):
|
def _build_backtest_dataframe(data):
|
||||||
columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'buy', 'sell']
|
columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'enter_long', 'exit_long',
|
||||||
columns = columns + ['buy_tag'] if len(data[0]) == 9 else columns
|
'enter_short', 'exit_short']
|
||||||
|
if len(data[0]) == 8:
|
||||||
|
# No short columns
|
||||||
|
data = [d + [0, 0] for d in data]
|
||||||
|
columns = columns + ['long_tag'] if len(data[0]) == 11 else columns
|
||||||
|
|
||||||
frame = DataFrame.from_records(data, columns=columns)
|
frame = DataFrame.from_records(data, columns=columns)
|
||||||
frame['date'] = frame['date'].apply(_get_frame_time_from_offset)
|
frame['date'] = frame['date'].apply(_get_frame_time_from_offset)
|
||||||
|
@ -519,12 +519,12 @@ tc32 = BTContainer(data=[
|
|||||||
# Test 33: trailing_stop should be triggered immediately on trade open candle.
|
# Test 33: trailing_stop should be triggered immediately on trade open candle.
|
||||||
# stop-loss: 1%, ROI: 10% (should not apply)
|
# stop-loss: 1%, ROI: 10% (should not apply)
|
||||||
tc33 = BTContainer(data=[
|
tc33 = BTContainer(data=[
|
||||||
# D O H L C V B S BT
|
# D O H L C V EL XL ES Xs BT
|
||||||
[0, 5000, 5050, 4950, 5000, 6172, 1, 0, 'buy_signal_01'],
|
[0, 5000, 5050, 4950, 5000, 6172, 1, 0, 0, 0, 'buy_signal_01'],
|
||||||
[1, 5000, 5500, 5000, 4900, 6172, 0, 0, None], # enter trade (signal on last candle) and stop
|
[1, 5000, 5500, 5000, 4900, 6172, 0, 0, 0, 0, None], # enter trade (signal on last candle) and stop
|
||||||
[2, 4900, 5250, 4500, 5100, 6172, 0, 0, None],
|
[2, 4900, 5250, 4500, 5100, 6172, 0, 0, 0, 0, None],
|
||||||
[3, 5100, 5100, 4650, 4750, 6172, 0, 0, None],
|
[3, 5100, 5100, 4650, 4750, 6172, 0, 0, 0, 0, None],
|
||||||
[4, 4750, 4950, 4350, 4750, 6172, 0, 0, None]],
|
[4, 4750, 4950, 4350, 4750, 6172, 0, 0, 0, 0, None]],
|
||||||
stop_loss=-0.01, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True,
|
stop_loss=-0.01, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True,
|
||||||
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02,
|
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02,
|
||||||
trailing_stop_positive=0.01, use_custom_stoploss=True,
|
trailing_stop_positive=0.01, use_custom_stoploss=True,
|
||||||
@ -571,6 +571,7 @@ TESTS = [
|
|||||||
tc31,
|
tc31,
|
||||||
tc32,
|
tc32,
|
||||||
tc33,
|
tc33,
|
||||||
|
# TODO-lev: Add tests for short here
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user