Use "combined" enter_tag column

This commit is contained in:
Matthias
2021-09-26 15:20:59 +02:00
parent 2a678bdbb4
commit 4fd00db630
6 changed files with 20 additions and 25 deletions

View File

@@ -18,7 +18,7 @@ class BTrade(NamedTuple):
sell_reason: SellType
open_tick: int
close_tick: int
buy_tag: Optional[str] = None
enter_tag: Optional[str] = None
class BTContainer(NamedTuple):
@@ -49,15 +49,13 @@ def _build_backtest_dataframe(data):
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
columns = columns + ['enter_tag'] if len(data[0]) == 11 else columns
frame = DataFrame.from_records(data, columns=columns)
frame['date'] = frame['date'].apply(_get_frame_time_from_offset)
# Ensure floats are in place
for column in ['open', 'high', 'low', 'close', 'volume']:
frame[column] = frame[column].astype('float64')
if 'long_tag' not in columns:
frame['long_tag'] = None
if 'short_tag' not in columns:
frame['short_tag'] = None
if 'enter_tag' not in columns:
frame['enter_tag'] = None
return frame

View File

@@ -532,7 +532,7 @@ tc33 = BTContainer(data=[
sell_reason=SellType.TRAILING_STOP_LOSS,
open_tick=1,
close_tick=1,
buy_tag='buy_signal_01'
enter_tag='buy_signal_01'
)]
)
@@ -621,6 +621,6 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data) -> None:
for c, trade in enumerate(data.trades):
res = results.iloc[c]
assert res.sell_reason == trade.sell_reason.value
assert res.buy_tag == trade.buy_tag
assert res.buy_tag == trade.enter_tag
assert res.open_date == _get_frame_time_from_offset(trade.open_tick)
assert res.close_date == _get_frame_time_from_offset(trade.close_tick)