Add profit % to sell_reason table
This commit is contained in:
parent
b25f28d1ad
commit
989ab646a9
@ -66,11 +66,13 @@ def generate_text_table_sell_reason(data: Dict[str, Dict], results: DataFrame) -
|
|||||||
:return: pretty printed table with tabulate as string
|
:return: pretty printed table with tabulate as string
|
||||||
"""
|
"""
|
||||||
tabular_data = []
|
tabular_data = []
|
||||||
headers = ['Sell Reason', 'Count', 'Profit', 'Loss']
|
headers = ['Sell Reason', 'Count', 'Profit', 'Loss', 'Profit %']
|
||||||
for reason, count in results['sell_reason'].value_counts().iteritems():
|
for reason, count in results['sell_reason'].value_counts().iteritems():
|
||||||
profit = len(results[(results['sell_reason'] == reason) & (results['profit_abs'] >= 0)])
|
result = results.loc[results['sell_reason'] == reason]
|
||||||
loss = len(results[(results['sell_reason'] == reason) & (results['profit_abs'] < 0)])
|
profit = len(result[result['profit_abs'] >= 0])
|
||||||
tabular_data.append([reason.value, count, profit, loss])
|
loss = len(result[results['profit_abs'] < 0])
|
||||||
|
profit_mean = round(result['profit_percent'].mean() * 100.0, 2)
|
||||||
|
tabular_data.append([reason.value, count, profit, loss, profit_mean])
|
||||||
return tabulate(tabular_data, headers=headers, tablefmt="pipe")
|
return tabulate(tabular_data, headers=headers, tablefmt="pipe")
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ def test_generate_text_table_sell_reason(default_conf, mocker):
|
|||||||
results = pd.DataFrame(
|
results = pd.DataFrame(
|
||||||
{
|
{
|
||||||
'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
|
'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
|
||||||
'profit_percent': [0.1, 0.2, -0.3],
|
'profit_percent': [0.1, 0.2, -0.1],
|
||||||
'profit_abs': [0.2, 0.4, -0.5],
|
'profit_abs': [0.2, 0.4, -0.2],
|
||||||
'trade_duration': [10, 30, 10],
|
'trade_duration': [10, 30, 10],
|
||||||
'profit': [2, 0, 0],
|
'profit': [2, 0, 0],
|
||||||
'loss': [0, 0, 1],
|
'loss': [0, 0, 1],
|
||||||
@ -49,10 +49,10 @@ def test_generate_text_table_sell_reason(default_conf, mocker):
|
|||||||
)
|
)
|
||||||
|
|
||||||
result_str = (
|
result_str = (
|
||||||
'| Sell Reason | Count | Profit | Loss |\n'
|
'| Sell Reason | Count | Profit | Loss | Profit % |\n'
|
||||||
'|:--------------|--------:|---------:|-------:|\n'
|
'|:--------------|--------:|---------:|-------:|-----------:|\n'
|
||||||
'| roi | 2 | 2 | 0 |\n'
|
'| roi | 2 | 2 | 0 | 15 |\n'
|
||||||
'| stop_loss | 1 | 0 | 1 |'
|
'| stop_loss | 1 | 0 | 1 | -10 |'
|
||||||
)
|
)
|
||||||
assert generate_text_table_sell_reason(
|
assert generate_text_table_sell_reason(
|
||||||
data={'ETH/BTC': {}}, results=results) == result_str
|
data={'ETH/BTC': {}}, results=results) == result_str
|
||||||
|
Loading…
Reference in New Issue
Block a user