From d3b0768dd8a82c81d58ca4d9fcd61226573ace68 Mon Sep 17 00:00:00 2001 From: Mikko Ohtamaa Date: Sat, 20 Jul 2024 23:21:34 +0900 Subject: [PATCH 1/4] Turn TradingStrategyUniverse to a slotted class --- tradeexecutor/strategy/trading_strategy_universe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From cf3bdb96d7bab0ad888596d54a944b497ad6f5cc Mon Sep 17 00:00:00 2001 From: Mikko Ohtamaa Date: Sat, 20 Jul 2024 23:27:54 +0900 Subject: [PATCH 2/4] Correctly wrap opt_result, do not have raw value --- tradeexecutor/backtest/optimiser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tradeexecutor/backtest/optimiser.py b/tradeexecutor/backtest/optimiser.py index 1d66cdc94..6cfd5aa39 100644 --- a/tradeexecutor/backtest/optimiser.py +++ b/tradeexecutor/backtest/optimiser.py @@ -311,7 +311,7 @@ def __call__( else: # The backtest crashed with an exception, # likely OutOfBalance - opt_result = self.filtered_result_value + opt_result = OptimiserSearchResult(self.filtered_result_value, negative=False) # Apply result filter and zero out the value for optimiser if needed if not self.result_filter(result): From 8cbb880e982ba2b69cd8727ac4805ff6211b85c5 Mon Sep 17 00:00:00 2001 From: Mikko Ohtamaa Date: Sat, 20 Jul 2024 23:28:15 +0900 Subject: [PATCH 3/4] Correctly wrap opt_result, do not have raw value --- tradeexecutor/backtest/optimiser.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tradeexecutor/backtest/optimiser.py b/tradeexecutor/backtest/optimiser.py index 6cfd5aa39..8ec03111c 100644 --- a/tradeexecutor/backtest/optimiser.py +++ b/tradeexecutor/backtest/optimiser.py @@ -308,15 +308,16 @@ 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 = OptimiserSearchResult(self.filtered_result_value, negative=False) - # 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.combination = combination logger.info("Optimiser for combination %s resulted to %s, exiting child process", combination, opt_result.value) return opt_result From 438322ccdeee3592f76296ad4745e2fbca7337d8 Mon Sep 17 00:00:00 2001 From: Mikko Ohtamaa Date: Sat, 20 Jul 2024 23:28:41 +0900 Subject: [PATCH 4/4] Correctly wrap opt_result, do not have raw value --- tradeexecutor/backtest/optimiser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tradeexecutor/backtest/optimiser.py b/tradeexecutor/backtest/optimiser.py index 8ec03111c..91178b69e 100644 --- a/tradeexecutor/backtest/optimiser.py +++ b/tradeexecutor/backtest/optimiser.py @@ -319,7 +319,7 @@ def __call__( 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