Merge pull request #4535 from freqtrade/fix/backtestperformance

Improve backtest performance after enabling compounding
This commit is contained in:
Matthias
2021-03-13 16:51:00 +01:00
committed by GitHub
6 changed files with 67 additions and 9 deletions

View File

@@ -199,7 +199,7 @@ def create_mock_trades(fee, use_db: bool = True):
if use_db:
Trade.session.add(trade)
else:
LocalTrade.trades.append(trade)
LocalTrade.add_bt_trade(trade)
# Simulate dry_run entries
trade = mock_trade_1(fee)

View File

@@ -29,6 +29,7 @@ def mock_trade_1(fee):
fee_open=fee.return_value,
fee_close=fee.return_value,
is_open=True,
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=17),
open_rate=0.123,
exchange='bittrex',
open_order_id='dry_run_buy_12345',
@@ -183,6 +184,7 @@ def mock_trade_4(fee):
amount_requested=124.0,
fee_open=fee.return_value,
fee_close=fee.return_value,
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=14),
is_open=True,
open_rate=0.123,
exchange='bittrex',
@@ -234,6 +236,7 @@ def mock_trade_5(fee):
amount_requested=124.0,
fee_open=fee.return_value,
fee_close=fee.return_value,
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=12),
is_open=True,
open_rate=0.123,
exchange='bittrex',
@@ -284,6 +287,7 @@ def mock_trade_6(fee):
stake_amount=0.001,
amount=2.0,
amount_requested=2.0,
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
fee_open=fee.return_value,
fee_close=fee.return_value,
is_open=True,

View File

@@ -1,5 +1,6 @@
# pragma pylint: disable=missing-docstring, C0103
import logging
from datetime import datetime, timedelta, timezone
from types import FunctionType
from unittest.mock import MagicMock
@@ -1044,6 +1045,7 @@ def test_fee_updated(fee):
def test_total_open_trades_stakes(fee, use_db):
Trade.use_db = use_db
Trade.reset_trades()
res = Trade.total_open_trades_stakes()
assert res == 0
create_mock_trades(fee, use_db)
@@ -1053,6 +1055,26 @@ def test_total_open_trades_stakes(fee, use_db):
Trade.use_db = True
@pytest.mark.usefixtures("init_persistence")
@pytest.mark.parametrize('use_db', [True, False])
def test_get_trades_proxy(fee, use_db):
Trade.use_db = use_db
Trade.reset_trades()
create_mock_trades(fee, use_db)
trades = Trade.get_trades_proxy()
assert len(trades) == 6
assert isinstance(trades[0], Trade)
assert len(Trade.get_trades_proxy(is_open=True)) == 4
assert len(Trade.get_trades_proxy(is_open=False)) == 2
opendate = datetime.now(tz=timezone.utc) - timedelta(minutes=15)
assert len(Trade.get_trades_proxy(open_date=opendate)) == 3
Trade.use_db = True
@pytest.mark.usefixtures("init_persistence")
def test_get_overall_performance(fee):
@@ -1196,6 +1218,6 @@ def test_Trade_object_idem():
# Fails if only a column is added without corresponding parent field
for item in localtrade:
if (not item.startswith('__')
and item not in ('trades', )
and item not in ('trades', 'trades_open', 'total_profit')
and type(getattr(LocalTrade, item)) not in (property, FunctionType)):
assert item in trade