From ea0ffbae736950c585810ba9701c69d1dd967610 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 29 Jan 2021 19:06:46 +0100 Subject: [PATCH] use profit_ratio in calculate_cum_profit --- freqtrade/data/btanalysis.py | 12 ++++++------ tests/data/test_btanalysis.py | 2 +- tests/test_plotting.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index c004a4d23..b7c8529ac 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -337,7 +337,7 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str, """ Adds a column `col_name` with the cumulative profit for the given trades array. :param df: DataFrame with date index - :param trades: DataFrame containing trades (requires columns close_date and profit_percent) + :param trades: DataFrame containing trades (requires columns close_date and profit_ratio) :param col_name: Column name that will be assigned the results :param timeframe: Timeframe used during the operations :return: Returns df with one additional column, col_name, containing the cumulative profit. @@ -349,8 +349,8 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str, timeframe_minutes = timeframe_to_minutes(timeframe) # Resample to timeframe to make sure trades match candles _trades_sum = trades.resample(f'{timeframe_minutes}min', on='close_date' - )[['profit_percent']].sum() - df.loc[:, col_name] = _trades_sum['profit_percent'].cumsum() + )[['profit_ratio']].sum() + df.loc[:, col_name] = _trades_sum['profit_ratio'].cumsum() # Set first value to 0 df.loc[df.iloc[0].name, col_name] = 0 # FFill to get continuous @@ -359,13 +359,13 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str, def calculate_max_drawdown(trades: pd.DataFrame, *, date_col: str = 'close_date', - value_col: str = 'profit_percent' + value_col: str = 'profit_ratio' ) -> Tuple[float, pd.Timestamp, pd.Timestamp]: """ Calculate max drawdown and the corresponding close dates - :param trades: DataFrame containing trades (requires columns close_date and profit_percent) + :param trades: DataFrame containing trades (requires columns close_date and profit_ratio) :param date_col: Column in DataFrame to use for dates (defaults to 'close_date') - :param value_col: Column in DataFrame to use for values (defaults to 'profit_percent') + :param value_col: Column in DataFrame to use for values (defaults to 'profit_ratio') :return: Tuple (float, highdate, lowdate) with absolute max drawdown, high and low time :raise: ValueError if trade-dataframe was found empty. """ diff --git a/tests/data/test_btanalysis.py b/tests/data/test_btanalysis.py index a26ada3ba..96ac6f63c 100644 --- a/tests/data/test_btanalysis.py +++ b/tests/data/test_btanalysis.py @@ -142,7 +142,7 @@ def test_extract_trades_of_period(testdatadir): trades = DataFrame( {'pair': [pair, pair, pair, pair], - 'profit_percent': [0.0, 0.1, -0.2, -0.5], + 'profit_ratio': [0.0, 0.1, -0.2, -0.5], 'profit_abs': [0.0, 1, -2, -5], 'open_date': to_datetime([Arrow(2017, 11, 13, 15, 40, 0).datetime, Arrow(2017, 11, 14, 9, 41, 0).datetime, diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 96c9868a9..4c8ac4816 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -179,7 +179,7 @@ def test_plot_trades(testdatadir, caplog): trade_sell = find_trace_in_fig_data(figure.data, 'Sell - Profit') assert isinstance(trade_sell, go.Scatter) assert trade_sell.yaxis == 'y' - assert len(trades.loc[trades['profit_percent'] > 0]) == len(trade_sell.x) + assert len(trades.loc[trades['profit_ratio'] > 0]) == len(trade_sell.x) assert trade_sell.marker.color == 'green' assert trade_sell.marker.symbol == 'square-open' assert trade_sell.text[0] == '4.0%, roi, 15 min' @@ -187,7 +187,7 @@ def test_plot_trades(testdatadir, caplog): trade_sell_loss = find_trace_in_fig_data(figure.data, 'Sell - Loss') assert isinstance(trade_sell_loss, go.Scatter) assert trade_sell_loss.yaxis == 'y' - assert len(trades.loc[trades['profit_percent'] <= 0]) == len(trade_sell_loss.x) + assert len(trades.loc[trades['profit_ratio'] <= 0]) == len(trade_sell_loss.x) assert trade_sell_loss.marker.color == 'red' assert trade_sell_loss.marker.symbol == 'square-open' assert trade_sell_loss.text[5] == '-10.4%, stop_loss, 720 min'