finish refactor of sell_reason table
This commit is contained in:
parent
d17300fd84
commit
876a9e4f44
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Tuple, List
|
from typing import Dict, Tuple, List, Any
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
@ -112,11 +112,10 @@ def generate_text_table(data: Dict[str, Dict], stake_currency: str, max_open_tra
|
|||||||
floatfmt=floatfmt, tablefmt="orgtbl", stralign="right") # type: ignore
|
floatfmt=floatfmt, tablefmt="orgtbl", stralign="right") # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def generate_sell_reason_stats(stake_currency: str, max_open_trades: int,
|
def generate_sell_reason_stats(max_open_trades: int,
|
||||||
results: DataFrame) -> List[Dict]:
|
results: DataFrame) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Generate small table outlining Backtest results
|
Generate small table outlining Backtest results
|
||||||
:param stake_currency: Stakecurrency used
|
|
||||||
:param max_open_trades: Max_open_trades parameter
|
:param max_open_trades: Max_open_trades parameter
|
||||||
:param results: Dataframe containing the backtest result for one strategy
|
:param results: Dataframe containing the backtest result for one strategy
|
||||||
:return: List of Dicts containing the metrics per Sell reason
|
:return: List of Dicts containing the metrics per Sell reason
|
||||||
@ -148,8 +147,7 @@ def generate_sell_reason_stats(stake_currency: str, max_open_trades: int,
|
|||||||
return tabular_data
|
return tabular_data
|
||||||
|
|
||||||
|
|
||||||
def generate_text_table_sell_reason(stake_currency: str,
|
def generate_text_table_sell_reason(sell_reason_stats: Dict[str, Any], stake_currency: str) -> str:
|
||||||
max_open_trades: int, results: DataFrame) -> str:
|
|
||||||
"""
|
"""
|
||||||
Generate small table outlining Backtest results
|
Generate small table outlining Backtest results
|
||||||
:param stake_currency: Stakecurrency used
|
:param stake_currency: Stakecurrency used
|
||||||
@ -168,7 +166,7 @@ def generate_text_table_sell_reason(stake_currency: str,
|
|||||||
f'Tot Profit {stake_currency}',
|
f'Tot Profit {stake_currency}',
|
||||||
'Tot Profit %',
|
'Tot Profit %',
|
||||||
]
|
]
|
||||||
sell_reason_stats = generate_sell_reason_stats(stake_currency, max_open_trades, results)
|
|
||||||
output = [[
|
output = [[
|
||||||
t['sell_reason'], t['trades'], t['wins'], t['draws'], t['losses'],
|
t['sell_reason'], t['trades'], t['wins'], t['draws'], t['losses'],
|
||||||
t['profit_mean_pct'], t['profit_sum_pct'], t['profit_total_abs'], t['profit_pct_total'],
|
t['profit_mean_pct'], t['profit_sum_pct'], t['profit_total_abs'], t['profit_pct_total'],
|
||||||
@ -249,9 +247,11 @@ def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame],
|
|||||||
print(' BACKTESTING REPORT '.center(len(table.splitlines()[0]), '='))
|
print(' BACKTESTING REPORT '.center(len(table.splitlines()[0]), '='))
|
||||||
print(table)
|
print(table)
|
||||||
|
|
||||||
table = generate_text_table_sell_reason(stake_currency=config['stake_currency'],
|
sell_reason_stats = generate_sell_reason_stats(max_open_trades=config['max_open_trades'],
|
||||||
max_open_trades=config['max_open_trades'],
|
|
||||||
results=results)
|
results=results)
|
||||||
|
table = generate_text_table_sell_reason(sell_reason_stats=sell_reason_stats,
|
||||||
|
stake_currency=config['stake_currency'],
|
||||||
|
)
|
||||||
if isinstance(table, str):
|
if isinstance(table, str):
|
||||||
print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '='))
|
print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '='))
|
||||||
print(table)
|
print(table)
|
||||||
|
@ -6,6 +6,7 @@ from arrow import Arrow
|
|||||||
from freqtrade.edge import PairInfo
|
from freqtrade.edge import PairInfo
|
||||||
from freqtrade.optimize.optimize_reports import (
|
from freqtrade.optimize.optimize_reports import (
|
||||||
generate_edge_table, generate_text_table, generate_text_table_sell_reason,
|
generate_edge_table, generate_text_table, generate_text_table_sell_reason,
|
||||||
|
generate_sell_reason_stats,
|
||||||
generate_text_table_strategy, store_backtest_result)
|
generate_text_table_strategy, store_backtest_result)
|
||||||
from freqtrade.strategy.interface import SellType
|
from freqtrade.strategy.interface import SellType
|
||||||
from tests.conftest import patch_exchange
|
from tests.conftest import patch_exchange
|
||||||
@ -65,8 +66,11 @@ def test_generate_text_table_sell_reason(default_conf, mocker):
|
|||||||
'| stop_loss | 1 | 0 | 0 | 1 |'
|
'| stop_loss | 1 | 0 | 0 | 1 |'
|
||||||
' -10 | -10 | -0.2 | -5 |'
|
' -10 | -10 | -0.2 | -5 |'
|
||||||
)
|
)
|
||||||
assert generate_text_table_sell_reason(stake_currency='BTC', max_open_trades=2,
|
|
||||||
results=results) == result_str
|
sell_reason_stats = generate_sell_reason_stats(max_open_trades=2,
|
||||||
|
results=results)
|
||||||
|
assert generate_text_table_sell_reason(sell_reason_stats=sell_reason_stats,
|
||||||
|
stake_currency='BTC') == result_str
|
||||||
|
|
||||||
|
|
||||||
def test_generate_text_table_strategy(default_conf, mocker):
|
def test_generate_text_table_strategy(default_conf, mocker):
|
||||||
|
Loading…
Reference in New Issue
Block a user