From ae52880f819a0df69f9fa6c8fe2ce6e01bcaaadf Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Tue, 2 Jan 2018 16:40:33 +0200 Subject: [PATCH 1/2] improve backtesting result formatting --- freqtrade/optimize/backtesting.py | 18 ++++++++++-------- freqtrade/tests/optimize/test_backtesting.py | 9 +++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 984ca3e72..0a09282b6 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -41,27 +41,29 @@ def generate_text_table( Generates and returns a text table for the given backtest data and the results dataframe :return: pretty printed table with tabulate as str """ + floatfmt = ('s', 'd', '.2f', '.8f', '.1f') tabular_data = [] - headers = ['pair', 'buy count', 'avg profit', 'total profit', 'avg duration'] + headers = ['pair', 'buy count', 'avg profit %', + 'total profit ' + stake_currency, 'avg duration'] for pair in data: result = results[results.currency == pair] tabular_data.append([ pair, len(result.index), - '{:.2f}%'.format(result.profit_percent.mean() * 100.0), - '{:.08f} {}'.format(result.profit_BTC.sum(), stake_currency), - '{:.2f}'.format(result.duration.mean() * ticker_interval), + result.profit_percent.mean() * 100.0, + result.profit_BTC.sum(), + result.duration.mean() * ticker_interval, ]) # Append Total tabular_data.append([ 'TOTAL', len(results.index), - '{:.2f}%'.format(results.profit_percent.mean() * 100.0), - '{:.08f} {}'.format(results.profit_BTC.sum(), stake_currency), - '{:.2f}'.format(results.duration.mean() * ticker_interval), + results.profit_percent.mean() * 100.0, + results.profit_BTC.sum(), + results.duration.mean() * ticker_interval, ]) - return tabulate(tabular_data, headers=headers) + return tabulate(tabular_data, headers=headers, floatfmt=floatfmt) def backtest(stake_amount: float, processed: Dict[str, DataFrame], diff --git a/freqtrade/tests/optimize/test_backtesting.py b/freqtrade/tests/optimize/test_backtesting.py index 94c062cac..e3e34de1d 100644 --- a/freqtrade/tests/optimize/test_backtesting.py +++ b/freqtrade/tests/optimize/test_backtesting.py @@ -18,11 +18,12 @@ def test_generate_text_table(): 'duration': [10, 30] } ) + print(generate_text_table({'BTC_ETH': {}}, results, 'BTC', 5)) assert generate_text_table({'BTC_ETH': {}}, results, 'BTC', 5) == ( - 'pair buy count avg profit total profit avg duration\n' - '------- ----------- ------------ -------------- --------------\n' - 'BTC_ETH 2 15.00% 0.60000000 BTC 100\n' - 'TOTAL 2 15.00% 0.60000000 BTC 100') + 'pair buy count avg profit % total profit BTC avg duration\n' + '------- ----------- -------------- ------------------ --------------\n' + 'BTC_ETH 2 15.00 0.60000000 100.0\n' + 'TOTAL 2 15.00 0.60000000 100.0') def test_get_timeframe(): From 82e9ed2ac291ad7ee72d39ab6ddc51916488ed5d Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Tue, 2 Jan 2018 17:53:47 +0200 Subject: [PATCH 2/2] shorten table title to match table length --- freqtrade/optimize/backtesting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 0a09282b6..47be60802 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -175,6 +175,6 @@ def start(args): config['stake_amount'], preprocess(data), max_open_trades, args.realistic_simulation ) logger.info( - '\n====================== BACKTESTING REPORT ======================================\n%s', + '\n====================== BACKTESTING REPORT ================================\n%s', generate_text_table(data, results, config['stake_currency'], args.ticker_interval) )