From 4812bcc28b04f0202b36f7340c0870fa6c7259ed Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Sat, 22 Jul 2023 09:13:24 +0900 Subject: [PATCH] flake8 fiz --- freqtrade/data/metrics.py | 4 ++-- freqtrade/optimize/optimize_reports/bt_output.py | 2 +- .../optimize/optimize_reports/optimize_reports.py | 5 ++--- freqtrade/rpc/rpc.py | 11 +++++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/freqtrade/data/metrics.py b/freqtrade/data/metrics.py index fe0d03522..294f66a66 100644 --- a/freqtrade/data/metrics.py +++ b/freqtrade/data/metrics.py @@ -244,9 +244,9 @@ def calculate_expectancy_ratio(trades: pd.DataFrame) -> float: if (average_loss > 0): risk_reward_ratio = average_win / average_loss winrate = nb_win_trades / len(trades) - expectancy = ((1 + risk_reward_ratio) * winrate) - 1 + expectancy_ratio = ((1 + risk_reward_ratio) * winrate) - 1 - return expectancy + return expectancy_ratio def calculate_sortino(trades: pd.DataFrame, min_date: datetime, max_date: datetime, diff --git a/freqtrade/optimize/optimize_reports/bt_output.py b/freqtrade/optimize/optimize_reports/bt_output.py index 15d1030f2..e833c5ce4 100644 --- a/freqtrade/optimize/optimize_reports/bt_output.py +++ b/freqtrade/optimize/optimize_reports/bt_output.py @@ -234,7 +234,7 @@ def text_table_add_metrics(strat_results: Dict) -> str: ('Profit factor', f'{strat_results["profit_factor"]:.2f}' if 'profit_factor' in strat_results else 'N/A'), ('Expectancy Ratio', f"{strat_results['expectancy_ratio']:.2f}" if 'expectancy_ratio' - in strat_results else 'N/A'), + in strat_results else 'N/A'), ('Trades per day', strat_results['trades_per_day']), ('Avg. daily profit %', f"{(strat_results['profit_total'] / strat_results['backtest_days']):.2%}"), diff --git a/freqtrade/optimize/optimize_reports/optimize_reports.py b/freqtrade/optimize/optimize_reports/optimize_reports.py index 854469975..e555077a8 100644 --- a/freqtrade/optimize/optimize_reports/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports/optimize_reports.py @@ -7,9 +7,8 @@ from pandas import DataFrame, concat, to_datetime from freqtrade.constants import BACKTEST_BREAKDOWNS, DATETIME_PRINT_FORMAT, IntOrInf from freqtrade.data.metrics import (calculate_cagr, calculate_calmar, calculate_csum, - calculate_expectancy, calculate_expectancy_ratio, - calculate_market_change, calculate_max_drawdown, - calculate_sharpe, calculate_sortino) + calculate_expectancy_ratio, calculate_market_change, + calculate_max_drawdown, calculate_sharpe, calculate_sortino) from freqtrade.misc import decimals_per_coin, round_coin_value diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 440de5460..e9adec793 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -530,10 +530,13 @@ class RPC: winrate = (winning_trades / closed_trade_count) if closed_trade_count > 0 else 0 loserate = (1 - winrate) - expectancy, expectancy_ratio = self.__calc_expectancy(mean_winning_profit, - mean_losing_profit, - winrate, - loserate) + # expectancy, expectancy_ratio = self.__calc_expectancy(mean_winning_profit, + # mean_losing_profit, + # winrate, + # loserate) + + expectancy = calculate_expectancy(trades) + expectancy_ratio = calculate_expectancy_ratio(trades) trades_df = DataFrame([{'close_date': trade.close_date.strftime(DATETIME_PRINT_FORMAT), 'profit_abs': trade.close_profit_abs}