diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 9266e239e..1312199bc 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -494,6 +494,8 @@ class RPC: profit_all_coin.append(profit_abs) profit_all_ratio.append(profit_ratio) + closed_trade_count = len([t for t in trades if not t.is_open]) + best_pair = Trade.get_best_pair(start_date) trading_volume = Trade.get_trading_volume(start_date) @@ -524,18 +526,18 @@ class RPC: mean_winning_profit = (winning_profit / winning_trades) if winning_trades > 0 else 0 mean_losing_profit = (losing_profit / losing_trades) if losing_trades > 0 else 0 - winrate = winning_trades / closed_trade_count if closed_trade_count > 0 else 0 - loserate = 100 - winrate + winrate = (winning_trades / closed_trade_count)*100 if closed_trade_count > 0 else 0 + loserate = (100 - winrate) - expectancy = 1 + expectancy = 1.0 if mean_winning_profit > 0 and mean_losing_profit > 0: expectancy = (1 + (mean_winning_profit / mean_losing_profit)) * (winrate / 100) - 1 else: if mean_winning_profit == 0: - expectancy = 0 + expectancy = 0.0 expectancy_rate = ( - ((winrate/100) * mean_winning_profit) - + ((winrate/100) * mean_winning_profit) - ((loserate/100) * mean_losing_profit) ) @@ -580,7 +582,7 @@ class RPC: 'profit_all_percent': round(profit_all_ratio_fromstart * 100, 2), 'profit_all_fiat': profit_all_fiat, 'trade_count': len(trades), - 'closed_trade_count': len([t for t in trades if not t.is_open]), + 'closed_trade_count': closed_trade_count, 'first_trade_date': arrow.get(first_date).humanize() if first_date else '', 'first_trade_timestamp': int(first_date.timestamp() * 1000) if first_date else 0, 'latest_trade_date': arrow.get(last_date).humanize() if last_date else '', diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index ff08a0564..9dc151ee8 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -403,6 +403,8 @@ def test_rpc_trade_statistics(default_conf_usdt, ticker, fee, mocker) -> None: assert res['first_trade_timestamp'] == 0 assert res['latest_trade_date'] == '' assert res['latest_trade_timestamp'] == 0 + assert res['expectancy'] == 0 + assert res['expectancy_rate'] == 0 # Create some test data create_mock_trades_usdt(fee) @@ -414,12 +416,15 @@ def test_rpc_trade_statistics(default_conf_usdt, ticker, fee, mocker) -> None: assert pytest.approx(stats['profit_all_coin']) == -77.45964918 assert pytest.approx(stats['profit_all_percent_mean']) == -57.86 assert pytest.approx(stats['profit_all_fiat']) == -85.205614098 + assert pytest.approx(stats['winrate']) == 66.666666667 assert stats['trade_count'] == 7 assert stats['first_trade_date'] == '2 days ago' assert stats['latest_trade_date'] == '17 minutes ago' assert stats['avg_duration'] in ('0:17:40') assert stats['best_pair'] == 'XRP/USDT' assert stats['best_rate'] == 10.0 + assert stats['expectancy'] == 1.0 + assert stats['expectancy_rate'] == 3.64 # Test non-available pair mocker.patch(f'{EXMS}.get_rate', diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 7978a2a23..823b270ef 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -743,6 +743,8 @@ def test_telegram_profit_handle( assert '*Best Performing:* `ETH/USDT: 9.45%`' in msg_mock.call_args_list[-1][0][0] assert '*Max Drawdown:*' in msg_mock.call_args_list[-1][0][0] assert '*Profit factor:*' in msg_mock.call_args_list[-1][0][0] + assert '*Winrate:*' in msg_mock.call_args_list[-1][0][0] + assert '*Expectancy (Rate):*' in msg_mock.call_args_list[-1][0][0] assert '*Trading volume:* `126 USDT`' in msg_mock.call_args_list[-1][0][0]