Merge pull request #4375 from flomerz/pass_processed_data

pass data and config to loss function
This commit is contained in:
Matthias
2021-02-16 20:06:50 +01:00
committed by GitHub
3 changed files with 14 additions and 3 deletions

View File

@@ -546,10 +546,11 @@ class Hyperopt:
)
return self._get_results_dict(backtesting_results, min_date, max_date,
params_dict, params_details)
params_dict, params_details,
processed=processed)
def _get_results_dict(self, backtesting_results, min_date, max_date,
params_dict, params_details):
params_dict, params_details, processed: Dict[str, DataFrame]):
results_metrics = self._calculate_results_metrics(backtesting_results)
results_explanation = self._format_results_explanation_string(results_metrics)
@@ -563,7 +564,8 @@ class Hyperopt:
loss: float = MAX_LOSS
if trade_count >= self.config['hyperopt_min_trades']:
loss = self.calculate_loss(results=backtesting_results, trade_count=trade_count,
min_date=min_date.datetime, max_date=max_date.datetime)
min_date=min_date.datetime, max_date=max_date.datetime,
config=self.config, processed=processed)
return {
'loss': loss,
'params_dict': params_dict,

View File

@@ -1,5 +1,6 @@
from datetime import datetime
from math import exp
from typing import Dict
from pandas import DataFrame
@@ -35,6 +36,7 @@ class SampleHyperOptLoss(IHyperOptLoss):
@staticmethod
def hyperopt_loss_function(results: DataFrame, trade_count: int,
min_date: datetime, max_date: datetime,
processed: Dict[str, DataFrame],
*args, **kwargs) -> float:
"""
Objective function, returns smaller number for better results