From 54976fa103ba9ae2a9cfa2cd5b612cd4bd79531a Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 6 Jul 2018 19:45:58 +0200 Subject: [PATCH] Add more tests to validate buy/sell rows --- freqtrade/tests/optimize/test_backtesting.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/freqtrade/tests/optimize/test_backtesting.py b/freqtrade/tests/optimize/test_backtesting.py index 10fd1351b..4af9c444e 100644 --- a/freqtrade/tests/optimize/test_backtesting.py +++ b/freqtrade/tests/optimize/test_backtesting.py @@ -485,13 +485,14 @@ def test_backtest(default_conf, fee, mocker) -> None: mocker.patch('freqtrade.exchange.Exchange.get_fee', fee) patch_exchange(mocker) backtesting = Backtesting(default_conf) - + pair = 'UNITTEST/BTC' data = optimize.load_data(None, ticker_interval='5m', pairs=['UNITTEST/BTC']) data = trim_dictlist(data, -200) + data_processed = backtesting.tickerdata_to_dataframe(data) results = backtesting.backtest( { 'stake_amount': default_conf['stake_amount'], - 'processed': backtesting.tickerdata_to_dataframe(data), + 'processed': data_processed, 'max_open_trades': 10, 'realistic': True } @@ -500,7 +501,7 @@ def test_backtest(default_conf, fee, mocker) -> None: assert len(results) == 2 expected = pd.DataFrame( - {'pair': ['UNITTEST/BTC', 'UNITTEST/BTC'], + {'pair': [pair, pair], 'profit_percent': [0.00148826, 0.00075313], 'profit_abs': [1.49e-06, 7.6e-07], 'open_time': [Arrow(2018, 1, 29, 18, 40, 0).datetime, @@ -514,6 +515,15 @@ def test_backtest(default_conf, fee, mocker) -> None: 'open_rate': [0.10432, 0.103364], 'close_rate': [0.104999, 0.10396]}) pd.testing.assert_frame_equal(results, expected) + data_pair = data_processed[pair] + # Check open trade + for _, t in results.iterrows(): + ln = data_pair.loc[data_pair["date"] == t["open_time"]] + assert ln is not None + assert round(ln.iloc[0]["close"], 6) == round(t["open_rate"], 6) + # check close trade + ln = data_pair.loc[data_pair["date"] == t["close_time"]] + assert round(ln.iloc[0]["close"], 6) == round(t["close_rate"], 6) def test_backtest_1min_ticker_interval(default_conf, fee, mocker) -> None: