diff --git a/tradeexecutor/backtest/optimiser.py b/tradeexecutor/backtest/optimiser.py index 1d66cdc94..91178b69e 100644 --- a/tradeexecutor/backtest/optimiser.py +++ b/tradeexecutor/backtest/optimiser.py @@ -308,17 +308,18 @@ def __call__( if getattr(result, "exception", None) is None: # Legacy pickle compat opt_result = self.search_func(result) + + # Apply result filter and zero out the value for optimiser if needed + if not self.result_filter(result): + opt_result.value = self.filtered_result_value + else: # The backtest crashed with an exception, # likely OutOfBalance - opt_result = self.filtered_result_value - - # Apply result filter and zero out the value for optimiser if needed - if not self.result_filter(result): - opt_result.value = self.filtered_result_value + opt_result = OptimiserSearchResult(self.filtered_result_value, negative=False) opt_result.combination = combination - logger.info("Optimiser for combination %s resulted to %s, exiting child process", combination, opt_result.value) + logger.info("Optimiser for combination %s resulted to %s, exception is %s, exiting child process", combination, opt_result.value, result.exception) return opt_result diff --git a/tradeexecutor/strategy/trading_strategy_universe.py b/tradeexecutor/strategy/trading_strategy_universe.py index d5247713c..82553dec8 100644 --- a/tradeexecutor/strategy/trading_strategy_universe.py +++ b/tradeexecutor/strategy/trading_strategy_universe.py @@ -120,7 +120,7 @@ def __post_init__(self): assert self.start_at is None and self.end_at is None, f"You can only give history_period or backtesting range. We got {self.start_at}, {self.end_at}, {self.history_period}" -@dataclass +@dataclass(slots=True) class TradingStrategyUniverse(StrategyExecutionUniverse): """A trading strategy universe using our own data feeds.