Add drawdown column to strategy summary table.

This commit is contained in:
Rokas Kupstys 2021-05-15 12:00:01 +03:00
parent edcfa94093
commit e1dc1357ce
3 changed files with 39 additions and 15 deletions

View File

@ -473,11 +473,11 @@ There will be an additional table comparing win/losses of the different strategi
Detailed output for all strategies one after the other will be available, so make sure to scroll up to see the details per strategy. Detailed output for all strategies one after the other will be available, so make sure to scroll up to see the details per strategy.
``` ```
=========================================================== STRATEGY SUMMARY =========================================================== =========================================================== STRATEGY SUMMARY =========================================================================
| Strategy | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Wins | Draws | Losses | | Strategy | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % | Avg Duration | Wins | Draws | Losses | Drawdown % |
|:------------|-------:|---------------:|---------------:|-----------------:|---------------:|:---------------|------:|-------:|-------:| |:------------|-------:|---------------:|---------------:|-----------------:|---------------:|:---------------|------:|-------:|-------:|-----------:|
| Strategy1 | 429 | 0.36 | 152.41 | 0.00762792 | 76.20 | 4:12:00 | 186 | 0 | 243 | | Strategy1 | 429 | 0.36 | 152.41 | 0.00762792 | 76.20 | 4:12:00 | 186 | 0 | 243 | 45.2 |
| Strategy2 | 1487 | -0.13 | -197.58 | -0.00988917 | -98.79 | 4:43:00 | 662 | 0 | 825 | | Strategy2 | 1487 | -0.13 | -197.58 | -0.00988917 | -98.79 | 4:43:00 | 662 | 0 | 825 | 241.68 |
``` ```
## Next step ## Next step

View File

@ -164,6 +164,17 @@ def generate_strategy_comparison(all_results: Dict) -> List[Dict]:
tabular_data.append(_generate_result_line( tabular_data.append(_generate_result_line(
results['results'], results['config']['dry_run_wallet'], strategy) results['results'], results['config']['dry_run_wallet'], strategy)
) )
try:
max_drawdown_per, _, _, _, _ = calculate_max_drawdown(results['results'],
value_col='profit_ratio')
max_drawdown_abs, _, _, _, _ = calculate_max_drawdown(results['results'],
value_col='profit_abs')
except ValueError:
max_drawdown_per = 0
max_drawdown_abs = 0
tabular_data[-1]['max_drawdown_per'] = round(max_drawdown_per * 100, 2)
tabular_data[-1]['max_drawdown_abs'] = \
round_coin_value(max_drawdown_abs, results['config']['stake_currency'], False)
return tabular_data return tabular_data
@ -485,10 +496,15 @@ def text_table_strategy(strategy_results, stake_currency: str) -> str:
""" """
floatfmt = _get_line_floatfmt(stake_currency) floatfmt = _get_line_floatfmt(stake_currency)
headers = _get_line_header('Strategy', stake_currency) headers = _get_line_header('Strategy', stake_currency)
# _get_line_header() is also used for per-pair summary. Per-pair drawdown is mostly useless
# therefore we slip this column in only for strategy summary here.
headers.append(f'Drawdown {stake_currency}')
headers.append('Drawdown %')
output = [[ output = [[
t['key'], t['trades'], t['profit_mean_pct'], t['profit_sum_pct'], t['profit_total_abs'], t['key'], t['trades'], t['profit_mean_pct'], t['profit_sum_pct'], t['profit_total_abs'],
t['profit_total_pct'], t['duration_avg'], t['wins'], t['draws'], t['losses'] t['profit_total_pct'], t['duration_avg'], t['wins'], t['draws'], t['losses'],
t['max_drawdown_abs'], t['max_drawdown_per']
] for t in strategy_results] ] for t in strategy_results]
# Ignore type as floatfmt does allow tuples but mypy does not know that # Ignore type as floatfmt does allow tuples but mypy does not know that
return tabulate(output, headers=headers, return tabulate(output, headers=headers,

View File

@ -1,3 +1,4 @@
import datetime
import re import re
from datetime import timedelta from datetime import timedelta
from pathlib import Path from pathlib import Path
@ -325,9 +326,12 @@ def test_text_table_strategy(default_conf):
default_conf['max_open_trades'] = 2 default_conf['max_open_trades'] = 2
default_conf['dry_run_wallet'] = 3 default_conf['dry_run_wallet'] = 3
results = {} results = {}
date = datetime.datetime(year=2020, month=1, day=1, hour=12, minute=30)
delta = datetime.timedelta(days=1)
results['TestStrategy1'] = {'results': pd.DataFrame( results['TestStrategy1'] = {'results': pd.DataFrame(
{ {
'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'], 'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
'close_date': [date, date + delta, date + delta * 2],
'profit_ratio': [0.1, 0.2, 0.3], 'profit_ratio': [0.1, 0.2, 0.3],
'profit_abs': [0.2, 0.4, 0.5], 'profit_abs': [0.2, 0.4, 0.5],
'trade_duration': [10, 30, 10], 'trade_duration': [10, 30, 10],
@ -340,6 +344,7 @@ def test_text_table_strategy(default_conf):
results['TestStrategy2'] = {'results': pd.DataFrame( results['TestStrategy2'] = {'results': pd.DataFrame(
{ {
'pair': ['LTC/BTC', 'LTC/BTC', 'LTC/BTC'], 'pair': ['LTC/BTC', 'LTC/BTC', 'LTC/BTC'],
'close_date': [date, date + delta, date + delta * 2],
'profit_ratio': [0.4, 0.2, 0.3], 'profit_ratio': [0.4, 0.2, 0.3],
'profit_abs': [0.4, 0.4, 0.5], 'profit_abs': [0.4, 0.4, 0.5],
'trade_duration': [15, 30, 15], 'trade_duration': [15, 30, 15],
@ -351,18 +356,21 @@ def test_text_table_strategy(default_conf):
), 'config': default_conf} ), 'config': default_conf}
result_str = ( result_str = (
'| Strategy | Buys | Avg Profit % | Cum Profit % | Tot' '| Strategy | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC '
' Profit BTC | Tot Profit % | Avg Duration | Wins | Draws | Losses |\n' '| Tot Profit % | Avg Duration | Wins | Draws | Losses | Drawdown BTC '
'|---------------+--------+----------------+----------------+------------------+' '| Drawdown % |\n'
'----------------+----------------+--------+---------+----------|\n' '|---------------+--------+----------------+----------------+------------------'
'| TestStrategy1 | 3 | 20.00 | 60.00 | 1.10000000 |' '+----------------+----------------+--------+---------+----------+----------------'
' 36.67 | 0:17:00 | 3 | 0 | 0 |\n' '+--------------|\n'
'| TestStrategy2 | 3 | 30.00 | 90.00 | 1.30000000 |' '| TestStrategy1 | 3 | 20.00 | 60.00 | 1.10000000 '
' 43.33 | 0:20:00 | 3 | 0 | 0 |' '| 36.67 | 0:17:00 | 3 | 0 | 0 | 0 '
'| 0 |\n'
'| TestStrategy2 | 3 | 30.00 | 90.00 | 1.30000000 '
'| 43.33 | 0:20:00 | 3 | 0 | 0 | 0 '
'| 0 |'
) )
strategy_results = generate_strategy_comparison(all_results=results) strategy_results = generate_strategy_comparison(all_results=results)
assert text_table_strategy(strategy_results, 'BTC') == result_str assert text_table_strategy(strategy_results, 'BTC') == result_str