From e0fd880c11572ff83aa444008c33805964426a41 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 11 Nov 2021 15:58:30 +0100 Subject: [PATCH] Improve some more pct formattings --- freqtrade/data/converter.py | 2 +- freqtrade/optimize/optimize_reports.py | 8 ++++---- freqtrade/plot/plotting.py | 2 +- freqtrade/plugins/pairlist/PriceFilter.py | 2 +- freqtrade/plugins/pairlist/SpreadFilter.py | 2 +- tests/test_plotting.py | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/freqtrade/data/converter.py b/freqtrade/data/converter.py index ca6464965..d592b4990 100644 --- a/freqtrade/data/converter.py +++ b/freqtrade/data/converter.py @@ -113,7 +113,7 @@ def ohlcv_fill_up_missing_data(dataframe: DataFrame, timeframe: str, pair: str) pct_missing = (len_after - len_before) / len_before if len_before > 0 else 0 if len_before != len_after: message = (f"Missing data fillup for {pair}: before: {len_before} - after: {len_after}" - f" - {round(pct_missing * 100, 2)}%") + f" - {pct_missing:.2%}") if pct_missing > 0.01: logger.info(message) else: diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 417bb54ae..c4002fcbe 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -728,16 +728,16 @@ def text_table_add_metrics(strat_results: Dict) -> str: ('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)}%"), + f"{(strat_results['profit_total'] / strat_results['backtest_days']):.2%}"), ('Avg. stake amount', round_coin_value(strat_results['avg_stake_amount'], strat_results['stake_currency'])), ('Total trade volume', round_coin_value(strat_results['total_volume'], strat_results['stake_currency'])), ('', ''), # Empty line to improve readability ('Best Pair', f"{strat_results['best_pair']['key']} " - f"{round(strat_results['best_pair']['profit_sum_pct'], 2)}%"), + f"{strat_results['best_pair']['profit_sum']:.2%}"), ('Worst Pair', f"{strat_results['worst_pair']['key']} " - f"{round(strat_results['worst_pair']['profit_sum_pct'], 2)}%"), + f"{strat_results['worst_pair']['profit_sum']:.2%}"), ('Best trade', f"{best_trade['pair']} {best_trade['profit_ratio']:.2%}"), ('Worst trade', f"{worst_trade['pair']} " f"{worst_trade['profit_ratio']:.2%}"), @@ -864,5 +864,5 @@ def show_sorted_pairlist(config: Dict, backtest_stats: Dict): print(f"Pairs for Strategy {strategy}: \n[") for result in results['results_per_pair']: if result["key"] != 'TOTAL': - print(f'"{result["key"]}", // {round(result["profit_mean_pct"], 2)}%') + print(f'"{result["key"]}", // {result["profit_mean"]:.2%}') print("]") diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index d2b51f3a2..6d44d56b1 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -192,7 +192,7 @@ def plot_trades(fig, trades: pd.DataFrame) -> make_subplots: # Trades can be empty if trades is not None and len(trades) > 0: # Create description for sell summarizing the trade - trades['desc'] = trades.apply(lambda row: f"{round(row['profit_ratio'] * 100, 1)}%, " + trades['desc'] = trades.apply(lambda row: f"{row['profit_ratio']:.2%}, " f"{row['sell_reason']}, " f"{row['trade_duration']} min", axis=1) diff --git a/freqtrade/plugins/pairlist/PriceFilter.py b/freqtrade/plugins/pairlist/PriceFilter.py index 7704ea9aa..63623d8c8 100644 --- a/freqtrade/plugins/pairlist/PriceFilter.py +++ b/freqtrade/plugins/pairlist/PriceFilter.py @@ -50,7 +50,7 @@ class PriceFilter(IPairList): """ active_price_filters = [] if self._low_price_ratio != 0: - active_price_filters.append(f"below {self._low_price_ratio * 100}%") + active_price_filters.append(f"below {self._low_price_ratio:.1%}") if self._min_price != 0: active_price_filters.append(f"below {self._min_price:.8f}") if self._max_price != 0: diff --git a/freqtrade/plugins/pairlist/SpreadFilter.py b/freqtrade/plugins/pairlist/SpreadFilter.py index 20cc97c6a..2d6e728ec 100644 --- a/freqtrade/plugins/pairlist/SpreadFilter.py +++ b/freqtrade/plugins/pairlist/SpreadFilter.py @@ -34,7 +34,7 @@ class SpreadFilter(IPairList): Short whitelist method description - used for startup-messages """ return (f"{self.name} - Filtering pairs with ask/bid diff above " - f"{self._max_spread_ratio * 100}%.") + f"{self._max_spread_ratio:.2%}.") def _validate_pair(self, pair: str, ticker: Dict[str, Any]) -> bool: """ diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 8cbe7f863..8a40f4a20 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -171,7 +171,7 @@ def test_plot_trades(testdatadir, caplog): assert len(trades) == len(trade_buy.x) assert trade_buy.marker.color == 'cyan' assert trade_buy.marker.symbol == 'circle-open' - assert trade_buy.text[0] == '4.0%, roi, 15 min' + assert trade_buy.text[0] == '3.99%, roi, 15 min' trade_sell = find_trace_in_fig_data(figure.data, 'Sell - Profit') assert isinstance(trade_sell, go.Scatter) @@ -179,7 +179,7 @@ def test_plot_trades(testdatadir, caplog): 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' + assert trade_sell.text[0] == '3.99%, roi, 15 min' trade_sell_loss = find_trace_in_fig_data(figure.data, 'Sell - Loss') assert isinstance(trade_sell_loss, go.Scatter) @@ -187,7 +187,7 @@ def test_plot_trades(testdatadir, caplog): 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' + assert trade_sell_loss.text[5] == '-10.45%, stop_loss, 720 min' def test_generate_candlestick_graph_no_signals_no_trades(default_conf, mocker, testdatadir, caplog):