Merge pull request #6181 from freqtrade/simplify_optimizereports
Simplify optimizereports
This commit is contained in:
commit
7f20f6834b
@ -76,6 +76,7 @@ class Hyperopt:
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
self.backtesting = Backtesting(self.config)
|
self.backtesting = Backtesting(self.config)
|
||||||
|
self.pairlist = self.backtesting.pairlists.whitelist
|
||||||
|
|
||||||
if not self.config.get('hyperopt'):
|
if not self.config.get('hyperopt'):
|
||||||
self.custom_hyperopt = HyperOptAuto(self.config)
|
self.custom_hyperopt = HyperOptAuto(self.config)
|
||||||
@ -332,7 +333,7 @@ class Hyperopt:
|
|||||||
params_details = self._get_params_details(params_dict)
|
params_details = self._get_params_details(params_dict)
|
||||||
|
|
||||||
strat_stats = generate_strategy_stats(
|
strat_stats = generate_strategy_stats(
|
||||||
processed, self.backtesting.strategy.get_strategy_name(),
|
self.pairlist, self.backtesting.strategy.get_strategy_name(),
|
||||||
backtesting_results, min_date, max_date, market_change=0
|
backtesting_results, min_date, max_date, market_change=0
|
||||||
)
|
)
|
||||||
results_explanation = HyperoptTools.format_results_explanation_string(
|
results_explanation = HyperoptTools.format_results_explanation_string(
|
||||||
|
@ -99,11 +99,11 @@ def _generate_result_line(result: DataFrame, starting_balance: int, first_column
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def generate_pair_metrics(data: Dict[str, Dict], stake_currency: str, starting_balance: int,
|
def generate_pair_metrics(pairlist: List[str], stake_currency: str, starting_balance: int,
|
||||||
results: DataFrame, skip_nan: bool = False) -> List[Dict]:
|
results: DataFrame, skip_nan: bool = False) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Generates and returns a list for the given backtest data and the results dataframe
|
Generates and returns a list for the given backtest data and the results dataframe
|
||||||
:param data: Dict of <pair: dataframe> containing data that was used during backtesting.
|
:param pairlist: Pairlist used
|
||||||
:param stake_currency: stake-currency - used to correctly name headers
|
:param stake_currency: stake-currency - used to correctly name headers
|
||||||
:param starting_balance: Starting balance
|
:param starting_balance: Starting balance
|
||||||
:param results: Dataframe containing the backtest results
|
:param results: Dataframe containing the backtest results
|
||||||
@ -113,7 +113,7 @@ def generate_pair_metrics(data: Dict[str, Dict], stake_currency: str, starting_b
|
|||||||
|
|
||||||
tabular_data = []
|
tabular_data = []
|
||||||
|
|
||||||
for pair in data:
|
for pair in pairlist:
|
||||||
result = results[results['pair'] == pair]
|
result = results[results['pair'] == pair]
|
||||||
if skip_nan and result['profit_abs'].isnull().all():
|
if skip_nan and result['profit_abs'].isnull().all():
|
||||||
continue
|
continue
|
||||||
@ -345,14 +345,14 @@ def generate_daily_stats(results: DataFrame) -> Dict[str, Any]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def generate_strategy_stats(btdata: Dict[str, DataFrame],
|
def generate_strategy_stats(pairlist: List[str],
|
||||||
strategy: str,
|
strategy: str,
|
||||||
content: Dict[str, Any],
|
content: Dict[str, Any],
|
||||||
min_date: datetime, max_date: datetime,
|
min_date: datetime, max_date: datetime,
|
||||||
market_change: float
|
market_change: float
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
:param btdata: Backtest data
|
:param pairlist: List of pairs to backtest
|
||||||
:param strategy: Strategy name
|
:param strategy: Strategy name
|
||||||
:param content: Backtest result data in the format:
|
:param content: Backtest result data in the format:
|
||||||
{'results: results, 'config: config}}.
|
{'results: results, 'config: config}}.
|
||||||
@ -365,11 +365,11 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame],
|
|||||||
if not isinstance(results, DataFrame):
|
if not isinstance(results, DataFrame):
|
||||||
return {}
|
return {}
|
||||||
config = content['config']
|
config = content['config']
|
||||||
max_open_trades = min(config['max_open_trades'], len(btdata.keys()))
|
max_open_trades = min(config['max_open_trades'], len(pairlist))
|
||||||
starting_balance = config['dry_run_wallet']
|
starting_balance = config['dry_run_wallet']
|
||||||
stake_currency = config['stake_currency']
|
stake_currency = config['stake_currency']
|
||||||
|
|
||||||
pair_results = generate_pair_metrics(btdata, stake_currency=stake_currency,
|
pair_results = generate_pair_metrics(pairlist, stake_currency=stake_currency,
|
||||||
starting_balance=starting_balance,
|
starting_balance=starting_balance,
|
||||||
results=results, skip_nan=False)
|
results=results, skip_nan=False)
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame],
|
|||||||
|
|
||||||
sell_reason_stats = generate_sell_reason_stats(max_open_trades=max_open_trades,
|
sell_reason_stats = generate_sell_reason_stats(max_open_trades=max_open_trades,
|
||||||
results=results)
|
results=results)
|
||||||
left_open_results = generate_pair_metrics(btdata, stake_currency=stake_currency,
|
left_open_results = generate_pair_metrics(pairlist, stake_currency=stake_currency,
|
||||||
starting_balance=starting_balance,
|
starting_balance=starting_balance,
|
||||||
results=results.loc[results['is_open']],
|
results=results.loc[results['is_open']],
|
||||||
skip_nan=True)
|
skip_nan=True)
|
||||||
@ -422,7 +422,7 @@ def generate_strategy_stats(btdata: Dict[str, DataFrame],
|
|||||||
|
|
||||||
'trades_per_day': round(len(results) / backtest_days, 2),
|
'trades_per_day': round(len(results) / backtest_days, 2),
|
||||||
'market_change': market_change,
|
'market_change': market_change,
|
||||||
'pairlist': list(btdata.keys()),
|
'pairlist': pairlist,
|
||||||
'stake_amount': config['stake_amount'],
|
'stake_amount': config['stake_amount'],
|
||||||
'stake_currency': config['stake_currency'],
|
'stake_currency': config['stake_currency'],
|
||||||
'stake_currency_decimals': decimals_per_coin(config['stake_currency']),
|
'stake_currency_decimals': decimals_per_coin(config['stake_currency']),
|
||||||
@ -511,9 +511,9 @@ def generate_backtest_stats(btdata: Dict[str, DataFrame],
|
|||||||
"""
|
"""
|
||||||
result: Dict[str, Any] = {'strategy': {}}
|
result: Dict[str, Any] = {'strategy': {}}
|
||||||
market_change = calculate_market_change(btdata, 'close')
|
market_change = calculate_market_change(btdata, 'close')
|
||||||
|
pairlist = list(btdata.keys())
|
||||||
for strategy, content in all_results.items():
|
for strategy, content in all_results.items():
|
||||||
strat_stats = generate_strategy_stats(btdata, strategy, content,
|
strat_stats = generate_strategy_stats(pairlist, strategy, content,
|
||||||
min_date, max_date, market_change=market_change)
|
min_date, max_date, market_change=market_change)
|
||||||
result['strategy'][strategy] = strat_stats
|
result['strategy'][strategy] = strat_stats
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ def test_hyperopt_format_results(hyperopt):
|
|||||||
'backtest_start_time': 1619718665,
|
'backtest_start_time': 1619718665,
|
||||||
'backtest_end_time': 1619718665,
|
'backtest_end_time': 1619718665,
|
||||||
}
|
}
|
||||||
results_metrics = generate_strategy_stats({'XRP/BTC': None}, '', bt_result,
|
results_metrics = generate_strategy_stats(['XRP/BTC'], '', bt_result,
|
||||||
Arrow(2017, 11, 14, 19, 32, 00),
|
Arrow(2017, 11, 14, 19, 32, 00),
|
||||||
Arrow(2017, 12, 14, 19, 32, 00), market_change=0)
|
Arrow(2017, 12, 14, 19, 32, 00), market_change=0)
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ def test_text_table_bt_results():
|
|||||||
' 0:20:00 | 2 0 1 66.7 |'
|
' 0:20:00 | 2 0 1 66.7 |'
|
||||||
)
|
)
|
||||||
|
|
||||||
pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC',
|
pair_results = generate_pair_metrics(['ETH/BTC'], stake_currency='BTC',
|
||||||
starting_balance=4, results=results)
|
starting_balance=4, results=results)
|
||||||
assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str
|
assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ def test_generate_pair_metrics():
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC',
|
pair_results = generate_pair_metrics(['ETH/BTC'], stake_currency='BTC',
|
||||||
starting_balance=2, results=results)
|
starting_balance=2, results=results)
|
||||||
assert isinstance(pair_results, list)
|
assert isinstance(pair_results, list)
|
||||||
assert len(pair_results) == 2
|
assert len(pair_results) == 2
|
||||||
|
Loading…
Reference in New Issue
Block a user