From 6e947346787560085dcdb51970ddaa68e9525597 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 26 Jun 2020 20:21:08 +0200 Subject: [PATCH] Add fee to backtestresult --- freqtrade/optimize/backtesting.py | 18 ++++++++++++------ tests/optimize/test_backtesting.py | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 30418f0d7..7021e85b6 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -40,11 +40,13 @@ class BacktestResult(NamedTuple): profit_percent: float profit_abs: float open_date: datetime + open_rate: float + open_fee: float close_date: datetime + close_rate: float + close_fee: float trade_duration: float open_at_end: bool - open_rate: float - close_rate: float sell_reason: SellType @@ -247,11 +249,13 @@ class Backtesting: profit_percent=trade.calc_profit_ratio(rate=closerate), profit_abs=trade.calc_profit(rate=closerate), open_date=buy_row.date, + open_rate=buy_row.open, + open_fee=self.fee, close_date=sell_row.date, + close_rate=closerate, + close_fee=self.fee, trade_duration=trade_dur, open_at_end=False, - open_rate=buy_row.open, - close_rate=closerate, sell_reason=sell.sell_type ) if partial_ohlcv: @@ -261,12 +265,14 @@ class Backtesting: profit_percent=trade.calc_profit_ratio(rate=sell_row.open), profit_abs=trade.calc_profit(rate=sell_row.open), open_date=buy_row.date, + open_rate=buy_row.open, + open_fee=self.fee, close_date=sell_row.date, + close_rate=sell_row.open, + close_fee=self.fee, trade_duration=int(( sell_row.date - buy_row.date).total_seconds() // 60), open_at_end=True, - open_rate=buy_row.open, - close_rate=sell_row.open, sell_reason=SellType.FORCE_SELL ) logger.debug(f"{pair} - Force selling still open trade, " diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index c0a9e798a..4ee03f6ba 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -462,12 +462,14 @@ def test_backtest(default_conf, fee, mocker, testdatadir) -> None: 'open_date': pd.to_datetime([Arrow(2018, 1, 29, 18, 40, 0).datetime, Arrow(2018, 1, 30, 3, 30, 0).datetime], utc=True ), + 'open_rate': [0.104445, 0.10302485], + 'open_fee': [0.0025, 0.0025], 'close_date': pd.to_datetime([Arrow(2018, 1, 29, 22, 35, 0).datetime, Arrow(2018, 1, 30, 4, 10, 0).datetime], utc=True), + 'close_rate': [0.104969, 0.103541], + 'close_fee': [0.0025, 0.0025], 'trade_duration': [235, 40], 'open_at_end': [False, False], - 'open_rate': [0.104445, 0.10302485], - 'close_rate': [0.104969, 0.103541], 'sell_reason': [SellType.ROI, SellType.ROI] }) pd.testing.assert_frame_equal(results, expected)