Enhance backtest results with sell reason profit / loss table
This commit is contained in:
		| @@ -183,9 +183,11 @@ class Backtesting: | |||||||
|         Generate small table outlining Backtest results |         Generate small table outlining Backtest results | ||||||
|         """ |         """ | ||||||
|         tabular_data = [] |         tabular_data = [] | ||||||
|         headers = ['Sell Reason', 'Count'] |         headers = ['Sell Reason', 'Count', 'Profit', 'Loss'] | ||||||
|         for reason, count in results['sell_reason'].value_counts().iteritems(): |         for reason, count in results['sell_reason'].value_counts().iteritems(): | ||||||
|             tabular_data.append([reason.value,  count]) |             profit = len(results[(results['sell_reason'] == reason) & (results['profit_abs'] >= 0)]) | ||||||
|  |             loss = len(results[(results['sell_reason'] == reason) & (results['profit_abs'] < 0)]) | ||||||
|  |             tabular_data.append([reason.value, count, profit, loss]) | ||||||
|         return tabulate(tabular_data, headers=headers, tablefmt="pipe") |         return tabulate(tabular_data, headers=headers, tablefmt="pipe") | ||||||
|  |  | ||||||
|     def _generate_text_table_strategy(self, all_results: dict) -> str: |     def _generate_text_table_strategy(self, all_results: dict) -> str: | ||||||
|   | |||||||
| @@ -394,8 +394,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.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], | ||||||
|             'profit': [2, 0, 0], |             'profit': [2, 0, 0], | ||||||
|             'loss': [0, 0, 1], |             'loss': [0, 0, 1], | ||||||
| @@ -404,10 +404,10 @@ def test_generate_text_table_sell_reason(default_conf, mocker): | |||||||
|     ) |     ) | ||||||
|  |  | ||||||
|     result_str = ( |     result_str = ( | ||||||
|         '| Sell Reason   |   Count |\n' |         '| Sell Reason   |   Count |   Profit |   Loss |\n' | ||||||
|         '|:--------------|--------:|\n' |         '|:--------------|--------:|---------:|-------:|\n' | ||||||
|         '| roi           |       2 |\n' |         '| roi           |       2 |        2 |      0 |\n' | ||||||
|         '| stop_loss     |       1 |' |         '| stop_loss     |       1 |        0 |      1 |' | ||||||
|     ) |     ) | ||||||
|     assert backtesting._generate_text_table_sell_reason( |     assert backtesting._generate_text_table_sell_reason( | ||||||
|         data={'ETH/BTC': {}}, results=results) == result_str |         data={'ETH/BTC': {}}, results=results) == result_str | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user