fix edge testcase
This commit is contained in:
parent
cbfedf8b29
commit
5d04d6ffa7
@ -453,8 +453,6 @@ class Backtesting:
|
|||||||
row_index = indexes[pair]
|
row_index = indexes[pair]
|
||||||
try:
|
try:
|
||||||
row = data[pair][row_index]
|
row = data[pair][row_index]
|
||||||
print('weeee')
|
|
||||||
print(row)
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# missing Data for one pair at the end.
|
# missing Data for one pair at the end.
|
||||||
# Warnings for this are shown during data loading
|
# Warnings for this are shown during data loading
|
||||||
|
@ -29,7 +29,6 @@ from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
|
|||||||
|
|
||||||
tests_start_time = arrow.get(2018, 10, 3)
|
tests_start_time = arrow.get(2018, 10, 3)
|
||||||
timeframe_in_minute = 60
|
timeframe_in_minute = 60
|
||||||
_ohlc = {'date': 0, 'buy': 1, 'open': 2, 'high': 3, 'low': 4, 'close': 5, 'sell': 6, 'volume': 7}
|
|
||||||
|
|
||||||
# Helpers for this test file
|
# Helpers for this test file
|
||||||
|
|
||||||
@ -77,23 +76,23 @@ def _time_on_candle(number):
|
|||||||
# End helper functions
|
# End helper functions
|
||||||
# Open trade should be removed from the end
|
# Open trade should be removed from the end
|
||||||
tc0 = BTContainer(data=[
|
tc0 = BTContainer(data=[
|
||||||
# D O H L C V B S
|
# D O H L C V B S SN
|
||||||
[0, 5000, 5025, 4975, 4987, 6172, 1, 0],
|
[0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
|
||||||
[1, 5000, 5025, 4975, 4987, 6172, 0, 1]], # enter trade (signal on last candle)
|
[1, 5000, 5025, 4975, 4987, 6172, 0, 1, '']], # enter trade (signal on last candle)
|
||||||
stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
|
stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
|
||||||
trades=[]
|
trades=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Two complete trades within dataframe(with sell hit for all)
|
# Two complete trades within dataframe(with sell hit for all)
|
||||||
tc1 = BTContainer(data=[
|
tc1 = BTContainer(data=[
|
||||||
# D O H L C V B S
|
# D O H L C V B S SN
|
||||||
[0, 5000, 5025, 4975, 4987, 6172, 1, 0],
|
[0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
|
||||||
[1, 5000, 5025, 4975, 4987, 6172, 0, 1], # enter trade (signal on last candle)
|
[1, 5000, 5025, 4975, 4987, 6172, 0, 1, ''], # enter trade (signal on last candle)
|
||||||
[2, 5000, 5025, 4975, 4987, 6172, 0, 0], # exit at open
|
[2, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # exit at open
|
||||||
[3, 5000, 5025, 4975, 4987, 6172, 1, 0], # no action
|
[3, 5000, 5025, 4975, 4987, 6172, 1, 0, ''], # no action
|
||||||
[4, 5000, 5025, 4975, 4987, 6172, 0, 0], # should enter the trade
|
[4, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # should enter the trade
|
||||||
[5, 5000, 5025, 4975, 4987, 6172, 0, 1], # no action
|
[5, 5000, 5025, 4975, 4987, 6172, 0, 1, ''], # no action
|
||||||
[6, 5000, 5025, 4975, 4987, 6172, 0, 0], # should sell
|
[6, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # should sell
|
||||||
],
|
],
|
||||||
stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
|
stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
|
||||||
trades=[BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=1, close_tick=2),
|
trades=[BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=1, close_tick=2),
|
||||||
@ -102,10 +101,10 @@ tc1 = BTContainer(data=[
|
|||||||
|
|
||||||
# 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss
|
# 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss
|
||||||
tc2 = BTContainer(data=[
|
tc2 = BTContainer(data=[
|
||||||
# D O H L C V B S
|
# D O H L C V B S SN
|
||||||
[0, 5000, 5025, 4975, 4987, 6172, 1, 0],
|
[0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
|
||||||
[1, 5000, 5025, 4600, 4987, 6172, 0, 0], # enter trade, stoploss hit
|
[1, 5000, 5025, 4600, 4987, 6172, 0, 0, ''], # enter trade, stoploss hit
|
||||||
[2, 5000, 5025, 4975, 4987, 6172, 0, 0],
|
[2, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
|
||||||
],
|
],
|
||||||
stop_loss=-0.01, roi={"0": float('inf')}, profit_perc=-0.01,
|
stop_loss=-0.01, roi={"0": float('inf')}, profit_perc=-0.01,
|
||||||
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
|
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
|
||||||
@ -113,10 +112,10 @@ tc2 = BTContainer(data=[
|
|||||||
|
|
||||||
# 4) Entered, sl 3 %, candle drops 4%, recovers to 1 % = > Trade closed, 3 % loss
|
# 4) Entered, sl 3 %, candle drops 4%, recovers to 1 % = > Trade closed, 3 % loss
|
||||||
tc3 = BTContainer(data=[
|
tc3 = BTContainer(data=[
|
||||||
# D O H L C V B S
|
# D O H L C V B S SN
|
||||||
[0, 5000, 5025, 4975, 4987, 6172, 1, 0],
|
[0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
|
||||||
[1, 5000, 5025, 4800, 4987, 6172, 0, 0], # enter trade, stoploss hit
|
[1, 5000, 5025, 4800, 4987, 6172, 0, 0, ''], # enter trade, stoploss hit
|
||||||
[2, 5000, 5025, 4975, 4987, 6172, 0, 0],
|
[2, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
|
||||||
],
|
],
|
||||||
stop_loss=-0.03, roi={"0": float('inf')}, profit_perc=-0.03,
|
stop_loss=-0.03, roi={"0": float('inf')}, profit_perc=-0.03,
|
||||||
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
|
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
|
||||||
@ -124,10 +123,10 @@ tc3 = BTContainer(data=[
|
|||||||
|
|
||||||
# 5) Stoploss and sell are hit. should sell on stoploss
|
# 5) Stoploss and sell are hit. should sell on stoploss
|
||||||
tc4 = BTContainer(data=[
|
tc4 = BTContainer(data=[
|
||||||
# D O H L C V B S
|
# D O H L C V B S SN
|
||||||
[0, 5000, 5025, 4975, 4987, 6172, 1, 0],
|
[0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
|
||||||
[1, 5000, 5025, 4800, 4987, 6172, 0, 1], # enter trade, stoploss hit, sell signal
|
[1, 5000, 5025, 4800, 4987, 6172, 0, 1, ''], # enter trade, stoploss hit, sell signal
|
||||||
[2, 5000, 5025, 4975, 4987, 6172, 0, 0],
|
[2, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
|
||||||
],
|
],
|
||||||
stop_loss=-0.03, roi={"0": float('inf')}, profit_perc=-0.03,
|
stop_loss=-0.03, roi={"0": float('inf')}, profit_perc=-0.03,
|
||||||
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
|
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
|
||||||
|
@ -584,6 +584,7 @@ def test_backtest_one(default_conf, fee, mocker, testdatadir) -> None:
|
|||||||
'min_rate': [0.1038, 0.10302485],
|
'min_rate': [0.1038, 0.10302485],
|
||||||
'max_rate': [0.10501, 0.1038888],
|
'max_rate': [0.10501, 0.1038888],
|
||||||
'is_open': [False, False],
|
'is_open': [False, False],
|
||||||
|
'buy_signal_name': ['', ''],
|
||||||
})
|
})
|
||||||
pd.testing.assert_frame_equal(results, expected)
|
pd.testing.assert_frame_equal(results, expected)
|
||||||
data_pair = processed[pair]
|
data_pair = processed[pair]
|
||||||
|
Loading…
Reference in New Issue
Block a user