Rename method to be public

This commit is contained in:
Matthias 2020-05-25 19:50:09 +02:00
parent 18a2dad684
commit db257e9f7f
2 changed files with 41 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import logging
from datetime import timedelta
from pathlib import Path
from typing import Dict, Tuple, List, Any
from typing import Dict, List, Any
from pandas import DataFrame
from tabulate import tabulate
@ -59,7 +59,7 @@ def _generate_result_line(result: DataFrame, max_open_trades: int, first_column:
'trades': len(result.index),
'profit_mean': result.profit_percent.mean(),
'profit_mean_pct': result.profit_percent.mean() * 100.0,
'profit_sum': result.profit_percent.sum() * 100.0,
'profit_sum': result.profit_percent.sum(),
'profit_sum_pct': result.profit_percent.sum() * 100.0,
'profit_total_abs': result.profit_abs.sum(),
'profit_total_pct': result.profit_percent.sum() * 100.0 / max_open_trades,
@ -78,7 +78,7 @@ def _generate_result_line(result: DataFrame, max_open_trades: int, first_column:
}
def _generate_pair_results(data: Dict[str, Dict], stake_currency: str, max_open_trades: int,
def generate_pair_results(data: Dict[str, Dict], stake_currency: str, max_open_trades: int,
results: DataFrame, skip_nan: bool = False) -> List[Dict]:
"""
Generates and returns a list for the given backtest data and the results dataframe
@ -161,7 +161,8 @@ def generate_sell_reason_stats(max_open_trades: int,
return tabular_data
def generate_text_table_sell_reason(sell_reason_stats: List[Dict[str, Any]], stake_currency: str) -> str:
def generate_text_table_sell_reason(sell_reason_stats: List[Dict[str, Any]],
stake_currency: str) -> str:
"""
Generate small table outlining Backtest results
:param stake_currency: Stakecurrency used
@ -257,7 +258,7 @@ def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame],
for strategy, results in all_results.items():
print(f"Result for strategy {strategy}")
pair_results = _generate_pair_results(btdata, stake_currency=config['stake_currency'],
pair_results = generate_pair_results(btdata, stake_currency=config['stake_currency'],
max_open_trades=config['max_open_trades'],
results=results, skip_nan=False)
table = generate_text_table(pair_results, stake_currency=config['stake_currency'])
@ -274,7 +275,7 @@ def show_backtest_results(config: Dict, btdata: Dict[str, DataFrame],
print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '='))
print(table)
left_open_results = _generate_pair_results(btdata, stake_currency=config['stake_currency'],
left_open_results = generate_pair_results(btdata, stake_currency=config['stake_currency'],
max_open_trades=config['max_open_trades'],
results=results.loc[results['open_at_end']],
skip_nan=True)

View File

@ -6,7 +6,7 @@ from arrow import Arrow
from freqtrade.edge import PairInfo
from freqtrade.optimize.optimize_reports import (
_generate_pair_results, generate_edge_table, generate_sell_reason_stats,
generate_pair_results, generate_edge_table, generate_sell_reason_stats,
generate_text_table, generate_text_table_sell_reason,
generate_text_table_strategy, store_backtest_result)
from freqtrade.strategy.interface import SellType
@ -38,13 +38,37 @@ def test_generate_text_table(default_conf, mocker):
' 15.00 | 0:20:00 | 2 | 0 | 0 |'
)
pair_results = _generate_pair_results(data={'ETH/BTC': {}}, stake_currency='BTC',
max_open_trades=2,
results=results)
pair_results = generate_pair_results(data={'ETH/BTC': {}}, stake_currency='BTC',
max_open_trades=2, results=results)
assert generate_text_table(pair_results,
stake_currency='BTC') == result_str
def test_generate_pair_results(default_conf, mocker):
results = pd.DataFrame(
{
'pair': ['ETH/BTC', 'ETH/BTC'],
'profit_percent': [0.1, 0.2],
'profit_abs': [0.2, 0.4],
'trade_duration': [10, 30],
'wins': [2, 0],
'draws': [0, 0],
'losses': [0, 0]
}
)
pair_results = generate_pair_results(data={'ETH/BTC': {}}, stake_currency='BTC',
max_open_trades=2, results=results)
assert isinstance(pair_results, list)
assert len(pair_results) == 2
assert pair_results[-1]['key'] == 'TOTAL'
assert (
pytest.approx(pair_results[-1]['profit_mean_pct']) == pair_results[-1]['profit_mean'] * 100)
assert (
pytest.approx(pair_results[-1]['profit_sum_pct']) == pair_results[-1]['profit_sum'] * 100)
def test_generate_text_table_sell_reason(default_conf):
results = pd.DataFrame(