From 4eb903835839dfb1d52a218415d447f6f90f4f80 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 11 Nov 2021 13:55:55 +0100 Subject: [PATCH] Some more fixes to % formatting --- freqtrade/optimize/hyperopt_tools.py | 8 ++++---- freqtrade/optimize/optimize_reports.py | 10 +++++----- freqtrade/persistence/models.py | 3 ++- freqtrade/plot/plotting.py | 4 ++-- freqtrade/plugins/pairlist/PriceFilter.py | 2 +- freqtrade/plugins/pairlist/SpreadFilter.py | 2 +- freqtrade/rpc/rpc.py | 3 +-- freqtrade/strategy/interface.py | 2 +- tests/rpc/test_rpc.py | 10 +++++----- tests/test_freqtradebot.py | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/freqtrade/optimize/hyperopt_tools.py b/freqtrade/optimize/hyperopt_tools.py index 0b2efa5c2..1204320da 100755 --- a/freqtrade/optimize/hyperopt_tools.py +++ b/freqtrade/optimize/hyperopt_tools.py @@ -284,10 +284,10 @@ class HyperoptTools(): return (f"{results_metrics['total_trades']:6d} trades. " f"{results_metrics['wins']}/{results_metrics['draws']}" f"/{results_metrics['losses']} Wins/Draws/Losses. " - f"Avg profit {results_metrics['profit_mean'] * 100: 6.2f}%. " - f"Median profit {results_metrics['profit_median'] * 100: 6.2f}%. " - f"Total profit {results_metrics['profit_total_abs']: 11.8f} {stake_currency} " - f"({results_metrics['profit_total'] * 100: 7.2f}%). " + f"Avg profit {results_metrics['profit_mean']:7.2%}. " + f"Median profit {results_metrics['profit_median']:7.2%}. " + f"Total profit {results_metrics['profit_total_abs']:11.8f} {stake_currency} " + f"({results_metrics['profit_total']:8.2%}). " f"Avg duration {results_metrics['holding_avg']} min." ) diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 14d928e54..417bb54ae 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -725,7 +725,7 @@ def text_table_add_metrics(strat_results: Dict) -> str: strat_results['stake_currency'])), ('Absolute profit ', round_coin_value(strat_results['profit_total_abs'], strat_results['stake_currency'])), - ('Total profit %', f"{round(strat_results['profit_total'] * 100, 2)}%"), + ('Total profit %', f"{strat_results['profit_total']:.2%}"), ('Trades per day', strat_results['trades_per_day']), ('Avg. daily profit %', f"{round(strat_results['profit_total'] / strat_results['backtest_days'] * 100, 2)}%"), @@ -738,9 +738,9 @@ def text_table_add_metrics(strat_results: Dict) -> str: f"{round(strat_results['best_pair']['profit_sum_pct'], 2)}%"), ('Worst Pair', f"{strat_results['worst_pair']['key']} " f"{round(strat_results['worst_pair']['profit_sum_pct'], 2)}%"), - ('Best trade', f"{best_trade['pair']} {round(best_trade['profit_ratio'] * 100, 2)}%"), + ('Best trade', f"{best_trade['pair']} {best_trade['profit_ratio']:.2%}"), ('Worst trade', f"{worst_trade['pair']} " - f"{round(worst_trade['profit_ratio'] * 100, 2)}%"), + f"{worst_trade['profit_ratio']:.2%}"), ('Best day', round_coin_value(strat_results['backtest_best_day_abs'], strat_results['stake_currency'])), @@ -758,7 +758,7 @@ def text_table_add_metrics(strat_results: Dict) -> str: ('Max balance', round_coin_value(strat_results['csum_max'], strat_results['stake_currency'])), - ('Drawdown', f"{round(strat_results['max_drawdown'] * 100, 2)}%"), + ('Drawdown', f"{strat_results['max_drawdown']:.2%}"), ('Drawdown', round_coin_value(strat_results['max_drawdown_abs'], strat_results['stake_currency'])), ('Drawdown high', round_coin_value(strat_results['max_drawdown_high'], @@ -767,7 +767,7 @@ def text_table_add_metrics(strat_results: Dict) -> str: strat_results['stake_currency'])), ('Drawdown Start', strat_results['drawdown_start']), ('Drawdown End', strat_results['drawdown_end']), - ('Market change', f"{round(strat_results['market_change'] * 100, 2)}%"), + ('Market change', f"{strat_results['market_change']:.2%}"), ] return tabulate(metrics, headers=["Metric", "Value"], tablefmt="orgtbl") diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index df3b71acb..2fcdd58bb 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -972,6 +972,7 @@ class Trade(_DECL_BASE, LocalTrade): if not any(item["mix_tag"] == mix_tag for item in return_list): return_list.append({'mix_tag': mix_tag, 'profit': profit, + 'profit_pct': round(profit * 100, 2), 'profit_abs': profit_abs, 'count': count}) else: @@ -980,11 +981,11 @@ class Trade(_DECL_BASE, LocalTrade): return_list[i] = { 'mix_tag': mix_tag, 'profit': profit + return_list[i]["profit"], + 'profit_pct': round(profit + return_list[i]["profit"] * 100, 2), 'profit_abs': profit_abs + return_list[i]["profit_abs"], 'count': 1 + return_list[i]["count"]} i += 1 - [x.update({'profit': round(x['profit'] * 100, 2)}) for x in return_list] return return_list @staticmethod diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index 509c03e90..d2b51f3a2 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -169,8 +169,8 @@ def add_max_drawdown(fig, row, trades: pd.DataFrame, df_comb: pd.DataFrame, df_comb.loc[timeframe_to_prev_date(timeframe, lowdate), 'cum_profit'], ], mode='markers', - name=f"Max drawdown {max_drawdown * 100:.2f}%", - text=f"Max drawdown {max_drawdown * 100:.2f}%", + name=f"Max drawdown {max_drawdown:.2%}", + text=f"Max drawdown {max_drawdown:.2%}", marker=dict( symbol='square-open', size=9, diff --git a/freqtrade/plugins/pairlist/PriceFilter.py b/freqtrade/plugins/pairlist/PriceFilter.py index 5b5afb557..7704ea9aa 100644 --- a/freqtrade/plugins/pairlist/PriceFilter.py +++ b/freqtrade/plugins/pairlist/PriceFilter.py @@ -82,7 +82,7 @@ class PriceFilter(IPairList): changeperc = compare / ticker['last'] if changeperc > self._low_price_ratio: self.log_once(f"Removed {pair} from whitelist, " - f"because 1 unit is {changeperc * 100:.3f}%", logger.info) + f"because 1 unit is {changeperc:.3%}", logger.info) return False # Perform low_amount check diff --git a/freqtrade/plugins/pairlist/SpreadFilter.py b/freqtrade/plugins/pairlist/SpreadFilter.py index 1b152774b..20cc97c6a 100644 --- a/freqtrade/plugins/pairlist/SpreadFilter.py +++ b/freqtrade/plugins/pairlist/SpreadFilter.py @@ -47,7 +47,7 @@ class SpreadFilter(IPairList): spread = 1 - ticker['bid'] / ticker['ask'] if spread > self._max_spread_ratio: self.log_once(f"Removed {pair} from whitelist, because spread " - f"{spread * 100:.3f}% > {self._max_spread_ratio * 100}%", + f"{spread * 100:.3%} > {self._max_spread_ratio:.3%}", logger.info) return False else: diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index db021029b..de066d123 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -224,9 +224,8 @@ class RPC: trade.pair, refresh=False, side="sell") except (PricingError, ExchangeError): current_rate = NAN - trade_percent = (100 * trade.calc_profit_ratio(current_rate)) trade_profit = trade.calc_profit(current_rate) - profit_str = f'{trade_percent:.2f}%' + profit_str = f'{trade.calc_profit_ratio(current_rate):.2%}' if self._fiat_converter: fiat_profit = self._fiat_converter.convert_amount( trade_profit, diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 47a226f16..d4b496ed0 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -765,7 +765,7 @@ class IStrategy(ABC, HyperStrategyMixin): if self.trailing_stop_positive is not None and high_profit > sl_offset: stop_loss_value = self.trailing_stop_positive logger.debug(f"{trade.pair} - Using positive stoploss: {stop_loss_value} " - f"offset: {sl_offset:.4g} profit: {current_profit:.4f}%") + f"offset: {sl_offset:.4g} profit: {current_profit:.2%}") trade.adjust_stop_loss(high or current_rate, stop_loss_value) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 945217b8a..2852ada81 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -1004,7 +1004,7 @@ def test_mix_tag_performance_handle(default_conf, ticker, limit_buy_order, fee, assert len(res) == 1 assert res[0]['mix_tag'] == 'Other Other' assert res[0]['count'] == 1 - assert prec_satoshi(res[0]['profit'], 6.2) + assert prec_satoshi(res[0]['profit_pct'], 6.2) trade.buy_tag = "TESTBUY" trade.sell_reason = "TESTSELL" @@ -1013,7 +1013,7 @@ def test_mix_tag_performance_handle(default_conf, ticker, limit_buy_order, fee, assert len(res) == 1 assert res[0]['mix_tag'] == 'TESTBUY TESTSELL' assert res[0]['count'] == 1 - assert prec_satoshi(res[0]['profit'], 6.2) + assert prec_satoshi(res[0]['profit_pct'], 6.2) def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee): @@ -1032,10 +1032,10 @@ def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee): assert len(res) == 2 assert res[0]['mix_tag'] == 'TEST1 sell_signal' assert res[0]['count'] == 1 - assert prec_satoshi(res[0]['profit'], 0.5) + assert prec_satoshi(res[0]['profit_pct'], 0.5) assert res[1]['mix_tag'] == 'Other roi' assert res[1]['count'] == 1 - assert prec_satoshi(res[1]['profit'], 1.0) + assert prec_satoshi(res[1]['profit_pct'], 1.0) # Test for a specific pair res = rpc._rpc_mix_tag_performance('ETC/BTC') @@ -1043,7 +1043,7 @@ def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee): assert len(res) == 1 assert res[0]['count'] == 1 assert res[0]['mix_tag'] == 'TEST1 sell_signal' - assert prec_satoshi(res[0]['profit'], 0.5) + assert prec_satoshi(res[0]['profit_pct'], 0.5) def test_rpc_count(mocker, default_conf, ticker, fee) -> None: diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 1f9b1d6b3..629fed76b 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3352,7 +3352,7 @@ def test_trailing_stop_loss_positive( ) # stop-loss not reached, adjusted stoploss assert freqtrade.handle_trade(trade) is False - caplog_text = f"ETH/USDT - Using positive stoploss: 0.01 offset: {offset} profit: 0.0249%" + caplog_text = f"ETH/USDT - Using positive stoploss: 0.01 offset: {offset} profit: 2.49%" if trail_if_reached: assert not log_has(caplog_text, caplog) assert not log_has("ETH/USDT - Adjusting stoploss...", caplog) @@ -3372,7 +3372,7 @@ def test_trailing_stop_loss_positive( ) assert freqtrade.handle_trade(trade) is False assert log_has( - f"ETH/USDT - Using positive stoploss: 0.01 offset: {offset} profit: 0.0572%", + f"ETH/USDT - Using positive stoploss: 0.01 offset: {offset} profit: 5.72%", caplog ) assert log_has("ETH/USDT - Adjusting stoploss...", caplog)