Extract data generation from generate_text_table
This commit is contained in:
parent
0917b17efd
commit
18a2dad684
@ -104,8 +104,7 @@ def _generate_pair_results(data: Dict[str, Dict], stake_currency: str, max_open_
|
|||||||
return tabular_data
|
return tabular_data
|
||||||
|
|
||||||
|
|
||||||
def generate_text_table(data: Dict[str, Dict], stake_currency: str, max_open_trades: int,
|
def generate_text_table(pair_results: List[Dict[str, Any]], stake_currency: str) -> str:
|
||||||
results: DataFrame, skip_nan: bool = False) -> str:
|
|
||||||
"""
|
"""
|
||||||
Generates and returns a text table for the given backtest data and the results dataframe
|
Generates and returns a text table for the given backtest data and the results dataframe
|
||||||
:param data: Dict of <pair: dataframe> containing data that was used during backtesting.
|
:param data: Dict of <pair: dataframe> containing data that was used during backtesting.
|
||||||
@ -118,7 +117,6 @@ def generate_text_table(data: Dict[str, Dict], stake_currency: str, max_open_tra
|
|||||||
|
|
||||||
headers = _get_line_header('Pair', stake_currency)
|
headers = _get_line_header('Pair', stake_currency)
|
||||||
floatfmt = _get_line_floatfmt()
|
floatfmt = _get_line_floatfmt()
|
||||||
pair_results = _generate_pair_results(data, stake_currency, max_open_trades, results, skip_nan)
|
|
||||||
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']
|
||||||
@ -259,9 +257,10 @@ def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame],
|
|||||||
for strategy, results in all_results.items():
|
for strategy, results in all_results.items():
|
||||||
|
|
||||||
print(f"Result for strategy {strategy}")
|
print(f"Result for strategy {strategy}")
|
||||||
table = generate_text_table(btdata, stake_currency=config['stake_currency'],
|
pair_results = _generate_pair_results(btdata, stake_currency=config['stake_currency'],
|
||||||
max_open_trades=config['max_open_trades'],
|
max_open_trades=config['max_open_trades'],
|
||||||
results=results)
|
results=results, skip_nan=False)
|
||||||
|
table = generate_text_table(pair_results, stake_currency=config['stake_currency'])
|
||||||
if isinstance(table, str):
|
if isinstance(table, str):
|
||||||
print(' BACKTESTING REPORT '.center(len(table.splitlines()[0]), '='))
|
print(' BACKTESTING REPORT '.center(len(table.splitlines()[0]), '='))
|
||||||
print(table)
|
print(table)
|
||||||
@ -275,10 +274,11 @@ def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame],
|
|||||||
print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '='))
|
print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '='))
|
||||||
print(table)
|
print(table)
|
||||||
|
|
||||||
table = generate_text_table(btdata,
|
left_open_results = _generate_pair_results(btdata, stake_currency=config['stake_currency'],
|
||||||
stake_currency=config['stake_currency'],
|
|
||||||
max_open_trades=config['max_open_trades'],
|
max_open_trades=config['max_open_trades'],
|
||||||
results=results.loc[results.open_at_end], skip_nan=True)
|
results=results.loc[results['open_at_end']],
|
||||||
|
skip_nan=True)
|
||||||
|
table = generate_text_table(left_open_results, stake_currency=config['stake_currency'])
|
||||||
if isinstance(table, str):
|
if isinstance(table, str):
|
||||||
print(' LEFT OPEN TRADES REPORT '.center(len(table.splitlines()[0]), '='))
|
print(' LEFT OPEN TRADES REPORT '.center(len(table.splitlines()[0]), '='))
|
||||||
print(table)
|
print(table)
|
||||||
|
@ -6,9 +6,9 @@ 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_sell_reason_stats, generate_text_table,
|
_generate_pair_results, generate_edge_table, generate_sell_reason_stats,
|
||||||
generate_text_table_sell_reason, generate_text_table_strategy,
|
generate_text_table, generate_text_table_sell_reason,
|
||||||
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
|
||||||
|
|
||||||
@ -37,9 +37,12 @@ def test_generate_text_table(default_conf, mocker):
|
|||||||
'| TOTAL | 2 | 15.00 | 30.00 | 0.60000000 |'
|
'| TOTAL | 2 | 15.00 | 30.00 | 0.60000000 |'
|
||||||
' 15.00 | 0:20:00 | 2 | 0 | 0 |'
|
' 15.00 | 0:20:00 | 2 | 0 | 0 |'
|
||||||
)
|
)
|
||||||
assert generate_text_table(data={'ETH/BTC': {}},
|
|
||||||
stake_currency='BTC', max_open_trades=2,
|
pair_results = _generate_pair_results(data={'ETH/BTC': {}}, stake_currency='BTC',
|
||||||
results=results) == result_str
|
max_open_trades=2,
|
||||||
|
results=results)
|
||||||
|
assert generate_text_table(pair_results,
|
||||||
|
stake_currency='BTC') == result_str
|
||||||
|
|
||||||
|
|
||||||
def test_generate_text_table_sell_reason(default_conf):
|
def test_generate_text_table_sell_reason(default_conf):
|
||||||
|
Loading…
Reference in New Issue
Block a user