adapt functional tests for new version after rebase
This commit is contained in:
parent
30a6e684a6
commit
409465ac8e
@ -9,6 +9,7 @@ from arrow import get as getdate
|
|||||||
|
|
||||||
|
|
||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
|
from freqtrade.strategy.interface import SellType
|
||||||
from freqtrade.tests.conftest import patch_exchange, log_has
|
from freqtrade.tests.conftest import patch_exchange, log_has
|
||||||
|
|
||||||
|
|
||||||
@ -21,8 +22,7 @@ class BTContainer(NamedTuple):
|
|||||||
roi: float
|
roi: float
|
||||||
trades: int
|
trades: int
|
||||||
profit_perc: float
|
profit_perc: float
|
||||||
sl: bool
|
sell_r: SellType
|
||||||
remains: bool
|
|
||||||
|
|
||||||
|
|
||||||
columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'buy', 'sell']
|
columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'buy', 'sell']
|
||||||
@ -40,9 +40,9 @@ data_profit = DataFrame([
|
|||||||
], columns=columns)
|
], columns=columns)
|
||||||
|
|
||||||
tc_profit1 = BTContainer(data=data_profit, stop_loss=-0.01, roi=1, trades=1,
|
tc_profit1 = BTContainer(data=data_profit, stop_loss=-0.01, roi=1, trades=1,
|
||||||
profit_perc=0.10557, sl=False, remains=False) # should be stoploss - drops 8%
|
profit_perc=0.10557, sell_r=SellType.STOP_LOSS) # should be stoploss - drops 8%
|
||||||
tc_profit2 = BTContainer(data=data_profit, stop_loss=-0.10, roi=1,
|
tc_profit2 = BTContainer(data=data_profit, stop_loss=-0.10, roi=1,
|
||||||
trades=1, profit_perc=0.10557, sl=True, remains=False)
|
trades=1, profit_perc=0.10557, sell_r=SellType.STOP_LOSS)
|
||||||
|
|
||||||
|
|
||||||
tc_loss0 = BTContainer(data=DataFrame([
|
tc_loss0 = BTContainer(data=DataFrame([
|
||||||
@ -57,7 +57,7 @@ tc_loss0 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-07-08 22:00:00').datetime, 0.001000,
|
[getdate('2018-07-08 22:00:00').datetime, 0.001000,
|
||||||
0.001011, 0.00098618, 0.00091618, 12345, 0, 0]
|
0.001011, 0.00098618, 0.00091618, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
stop_loss=-0.05, roi=1, trades=1, profit_perc=-0.08839, sl=True, remains=False)
|
stop_loss=-0.05, roi=1, trades=1, profit_perc=-0.08839, sell_r=SellType.STOP_LOSS)
|
||||||
|
|
||||||
|
|
||||||
# Test 1 Minus 8% Close
|
# Test 1 Minus 8% Close
|
||||||
@ -71,8 +71,8 @@ tc1 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9955, 9975, 9955, 9990, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9955, 9975, 9955, 9990, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9990, 9990, 9990, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9990, 9990, 9990, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.01, roi=1, trades=1, profit_perc=-0.01, sl=True, remains=False) # should be
|
# stop_loss=-0.01, roi=1, trades=1, profit_perc=-0.01, sell_r=SellType.STOP_LOSS) # should be
|
||||||
stop_loss=-0.01, roi=1, trades=1, profit_perc=0.071, sl=False, remains=True) #
|
stop_loss=-0.01, roi=1, trades=1, profit_perc=-0.003, sell_r=SellType.FORCE_SELL) #
|
||||||
|
|
||||||
|
|
||||||
# Test 2 Minus 4% Low, minus 1% close
|
# Test 2 Minus 4% Low, minus 1% close
|
||||||
@ -86,8 +86,8 @@ tc2 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9875, 9900, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9875, 9900, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.03, roi=1, trades=1, profit_perc=-0.03, sl=True, remains=False) #should be
|
# stop_loss=-0.03, roi=1, trades=1, profit_perc=-0.03, sell_r=SellType.STOP_LOSS) #should be
|
||||||
stop_loss=-0.03, roi=1, trades=1, profit_perc=-0.00999, sl=False, remains=True) #
|
stop_loss=-0.03, roi=1, trades=1, profit_perc=-0.012, sell_r=SellType.FORCE_SELL) #
|
||||||
|
|
||||||
|
|
||||||
# Test 3 Candle drops 4%, Recovers 1%.
|
# Test 3 Candle drops 4%, Recovers 1%.
|
||||||
@ -104,8 +104,8 @@ tc3 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 8000, 8000, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 8000, 8000, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9950, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9950, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.02, roi=1, trades=2, profit_perc=-0.4, sl=True, remains=False) #should be
|
# stop_loss=-0.02, roi=1, trades=2, profit_perc=-0.4, sell_r=SellType.STOP_LOSS) #should be
|
||||||
stop_loss=-0.02, roi=1, trades=1, profit_perc=-0.19999, sl=True, remains=False) #
|
stop_loss=-0.02, roi=1, trades=1, profit_perc=-0.012, sell_r=SellType.FORCE_SELL) #
|
||||||
|
|
||||||
|
|
||||||
# Test 4 Minus 3% / recovery +15%
|
# Test 4 Minus 3% / recovery +15%
|
||||||
@ -119,8 +119,8 @@ tc4 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9875, 9900, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9875, 9900, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.02, roi=0.06, trades=1, profit_perc=-0.02, sl=False, remains=False) #should be
|
# stop_loss=-0.02, roi=0.06, trades=1, profit_perc=-0.02, sell_r=SellType.STOP_LOSS) #should be
|
||||||
stop_loss=-0.02, roi=0.06, trades=1, profit_perc=-0.141, sl=True, remains=False)
|
stop_loss=-0.02, roi=0.06, trades=1, profit_perc=-0.012, sell_r=SellType.FORCE_SELL)
|
||||||
|
|
||||||
# Test 5 / Drops 0.5% Closes +20%
|
# Test 5 / Drops 0.5% Closes +20%
|
||||||
# Candle Data for test 5
|
# Candle Data for test 5
|
||||||
@ -133,8 +133,8 @@ tc5 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9945, 9900, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9945, 9900, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.01, roi=0.03, trades=1, profit_perc=0.03, sl=False, remains=False) #should be
|
# stop_loss=-0.01, roi=0.03, trades=1, profit_perc=0.03, sell_r=SellType.ROI) #should be
|
||||||
stop_loss=-0.01, roi=0.03, trades=1, profit_perc=0.197, sl=False, remains=False)
|
stop_loss=-0.01, roi=0.03, trades=1, profit_perc=-0.012, sell_r=SellType.FORCE_SELL)
|
||||||
|
|
||||||
# Test 6 / Drops 3% / Recovers 6% Positive / Closes 1% positve
|
# Test 6 / Drops 3% / Recovers 6% Positive / Closes 1% positve
|
||||||
# Candle Data for test 6
|
# Candle Data for test 6
|
||||||
@ -147,8 +147,8 @@ tc6 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9945, 9900, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9945, 9900, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.02, roi=0.05, trades=1, profit_perc=-0.02, sl=False, remains=False) #should be
|
# stop_loss=-0.02, roi=0.05, trades=1, profit_perc=-0.02, sell_r=SellType.STOP_LOSS) #should be
|
||||||
stop_loss=-0.02, roi=0.05, trades=1, profit_perc=-0.025, sl=False, remains=True) #
|
stop_loss=-0.02, roi=0.05, trades=1, profit_perc=-0.012, sell_r=SellType.FORCE_SELL) #
|
||||||
|
|
||||||
# Test 7 - 6% Positive / 1% Negative / Close 1% Positve
|
# Test 7 - 6% Positive / 1% Negative / Close 1% Positve
|
||||||
# Candle Data for test 7
|
# Candle Data for test 7
|
||||||
@ -161,8 +161,8 @@ tc7 = BTContainer(data=DataFrame([
|
|||||||
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9945, 9900, 12345, 0, 0],
|
[getdate('2018-06-10 11:00:00').datetime, 9925, 9975, 9945, 9900, 12345, 0, 0],
|
||||||
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
[getdate('2018-06-10 12:00:00').datetime, 9900, 9950, 9850, 9900, 12345, 0, 0]
|
||||||
], columns=columns),
|
], columns=columns),
|
||||||
# stop_loss=-0.02, roi=0.03, trades=1, profit_perc=-0.03, sl=False, remains=False) #should be
|
# stop_loss=-0.02, roi=0.03, trades=1, profit_perc=0.03, sell_r=SellType.ROI) #should be
|
||||||
stop_loss=-0.02, roi=0.03, trades=1, profit_perc=-0.025, sl=False, remains=True) #
|
stop_loss=-0.02, roi=0.03, trades=1, profit_perc=-0.012, sell_r=SellType.FORCE_SELL) #
|
||||||
|
|
||||||
TESTS = [
|
TESTS = [
|
||||||
# tc_profit1,
|
# tc_profit1,
|
||||||
@ -186,12 +186,11 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data) -> None:
|
|||||||
default_conf["stoploss"] = data.stop_loss
|
default_conf["stoploss"] = data.stop_loss
|
||||||
default_conf["minimal_roi"] = {"0": data.roi}
|
default_conf["minimal_roi"] = {"0": data.roi}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
||||||
mocker.patch.multiple('freqtrade.analyze.Analyze',
|
|
||||||
populate_sell_trend=MagicMock(return_value=data.data),
|
|
||||||
populate_buy_trend=MagicMock(return_value=data.data))
|
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
|
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
|
backtesting.advise_buy = lambda a, m: data.data
|
||||||
|
backtesting.advise_sell = lambda a, m: data.data
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
|
|
||||||
pair = 'UNITTEST/BTC'
|
pair = 'UNITTEST/BTC'
|
||||||
@ -202,20 +201,19 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data) -> None:
|
|||||||
'stake_amount': default_conf['stake_amount'],
|
'stake_amount': default_conf['stake_amount'],
|
||||||
'processed': data_processed,
|
'processed': data_processed,
|
||||||
'max_open_trades': 10,
|
'max_open_trades': 10,
|
||||||
'realistic': True
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
print(results.T)
|
print(results.T)
|
||||||
|
|
||||||
assert len(results) == data.trades
|
assert len(results) == data.trades
|
||||||
assert round(results["profit_percent"].sum(), 3) == round(data.profit_perc, 3)
|
assert round(results["profit_percent"].sum(), 3) == round(data.profit_perc, 3)
|
||||||
if data.sl:
|
if data.sell_r == SellType.STOP_LOSS:
|
||||||
assert log_has("Stop loss hit.", caplog.record_tuples)
|
assert log_has("Stop loss hit.", caplog.record_tuples)
|
||||||
else:
|
else:
|
||||||
assert not log_has("Stop loss hit.", caplog.record_tuples)
|
assert not log_has("Stop loss hit.", caplog.record_tuples)
|
||||||
log_test = (f'Force_selling still open trade UNITTEST/BTC with '
|
log_test = (f'Force_selling still open trade UNITTEST/BTC with '
|
||||||
f'{results.iloc[-1].profit_percent} perc - {results.iloc[-1].profit_abs}')
|
f'{results.iloc[-1].profit_percent} perc - {results.iloc[-1].profit_abs}')
|
||||||
if data.remains:
|
if data.sell_r == SellType.FORCE_SELL:
|
||||||
assert log_has(log_test,
|
assert log_has(log_test,
|
||||||
caplog.record_tuples)
|
caplog.record_tuples)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user