Add more tests to validate buy/sell rows
This commit is contained in:
parent
c35d1b9c9d
commit
54976fa103
@ -485,13 +485,14 @@ def test_backtest(default_conf, fee, mocker) -> None:
|
|||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
|
pair = 'UNITTEST/BTC'
|
||||||
data = optimize.load_data(None, ticker_interval='5m', pairs=['UNITTEST/BTC'])
|
data = optimize.load_data(None, ticker_interval='5m', pairs=['UNITTEST/BTC'])
|
||||||
data = trim_dictlist(data, -200)
|
data = trim_dictlist(data, -200)
|
||||||
|
data_processed = backtesting.tickerdata_to_dataframe(data)
|
||||||
results = backtesting.backtest(
|
results = backtesting.backtest(
|
||||||
{
|
{
|
||||||
'stake_amount': default_conf['stake_amount'],
|
'stake_amount': default_conf['stake_amount'],
|
||||||
'processed': backtesting.tickerdata_to_dataframe(data),
|
'processed': data_processed,
|
||||||
'max_open_trades': 10,
|
'max_open_trades': 10,
|
||||||
'realistic': True
|
'realistic': True
|
||||||
}
|
}
|
||||||
@ -500,7 +501,7 @@ def test_backtest(default_conf, fee, mocker) -> None:
|
|||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
|
|
||||||
expected = pd.DataFrame(
|
expected = pd.DataFrame(
|
||||||
{'pair': ['UNITTEST/BTC', 'UNITTEST/BTC'],
|
{'pair': [pair, pair],
|
||||||
'profit_percent': [0.00148826, 0.00075313],
|
'profit_percent': [0.00148826, 0.00075313],
|
||||||
'profit_abs': [1.49e-06, 7.6e-07],
|
'profit_abs': [1.49e-06, 7.6e-07],
|
||||||
'open_time': [Arrow(2018, 1, 29, 18, 40, 0).datetime,
|
'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],
|
'open_rate': [0.10432, 0.103364],
|
||||||
'close_rate': [0.104999, 0.10396]})
|
'close_rate': [0.104999, 0.10396]})
|
||||||
pd.testing.assert_frame_equal(results, expected)
|
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:
|
def test_backtest_1min_ticker_interval(default_conf, fee, mocker) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user