output duration in a more readable way

This commit is contained in:
Matthias 2018-07-18 20:08:55 +02:00
parent f9f6a3bd04
commit 79b1030435
2 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,7 @@ This module contains the backtesting logic
import logging import logging
import operator import operator
from argparse import Namespace from argparse import Namespace
from datetime import datetime from datetime import datetime, timedelta
from typing import Any, Dict, List, NamedTuple, Optional, Tuple from typing import Any, Dict, List, NamedTuple, Optional, Tuple
import arrow import arrow
@ -88,7 +88,7 @@ class Backtesting(object):
""" """
stake_currency = str(self.config.get('stake_currency')) stake_currency = str(self.config.get('stake_currency'))
floatfmt = ('s', 'd', '.2f', '.2f', '.8f', '.1f') floatfmt = ('s', 'd', '.2f', '.2f', '.8f', '.1f', '.1f', '.1f')
tabular_data = [] tabular_data = []
headers = ['pair', 'buy count', 'avg profit %', 'cum profit %', headers = ['pair', 'buy count', 'avg profit %', 'cum profit %',
'total profit ' + stake_currency, 'avg duration', 'profit', 'loss'] 'total profit ' + stake_currency, 'avg duration', 'profit', 'loss']
@ -100,7 +100,8 @@ class Backtesting(object):
result.profit_percent.mean() * 100.0, result.profit_percent.mean() * 100.0,
result.profit_percent.sum() * 100.0, result.profit_percent.sum() * 100.0,
result.profit_abs.sum(), result.profit_abs.sum(),
result.trade_duration.mean(), str(timedelta(
minutes=round(result.trade_duration.mean()))) if len(result) else 'nan',
len(result[result.profit_abs > 0]), len(result[result.profit_abs > 0]),
len(result[result.profit_abs < 0]) len(result[result.profit_abs < 0])
]) ])
@ -112,7 +113,8 @@ class Backtesting(object):
results.profit_percent.mean() * 100.0, results.profit_percent.mean() * 100.0,
results.profit_percent.sum() * 100.0, results.profit_percent.sum() * 100.0,
results.profit_abs.sum(), results.profit_abs.sum(),
results.trade_duration.mean(), str(timedelta(
minutes=round(results.trade_duration.mean()))) if len(results) else 'nan',
len(results[results.profit_abs > 0]), len(results[results.profit_abs > 0]),
len(results[results.profit_abs < 0]) len(results[results.profit_abs < 0])
]) ])

View File

@ -394,13 +394,12 @@ def test_generate_text_table(default_conf, mocker):
'| pair | buy count | avg profit % | cum profit % | ' '| pair | buy count | avg profit % | cum profit % | '
'total profit BTC | avg duration | profit | loss |\n' 'total profit BTC | avg duration | profit | loss |\n'
'|:--------|------------:|---------------:|---------------:|' '|:--------|------------:|---------------:|---------------:|'
'-------------------:|---------------:|---------:|-------:|\n' '-------------------:|:---------------|---------:|-------:|\n'
'| ETH/BTC | 2 | 15.00 | 30.00 | ' '| ETH/BTC | 2 | 15.00 | 30.00 | '
'0.60000000 | 20.0 | 2 | 0 |\n' '0.60000000 | 0:20:00 | 2 | 0 |\n'
'| TOTAL | 2 | 15.00 | 30.00 | ' '| TOTAL | 2 | 15.00 | 30.00 | '
'0.60000000 | 20.0 | 2 | 0 |' '0.60000000 | 0:20:00 | 2 | 0 |'
) )
print(result_str)
assert backtesting._generate_text_table(data={'ETH/BTC': {}}, results=results) == result_str assert backtesting._generate_text_table(data={'ETH/BTC': {}}, results=results) == result_str