From 162e94455b3cf928ac68bd895a7674f1dbe0ce8b Mon Sep 17 00:00:00 2001 From: froggleston Date: Wed, 16 Mar 2022 12:16:24 +0000 Subject: [PATCH] Add support for storing buy candle indicator rows in backtesting results --- freqtrade/optimize/backtesting.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 79c861ee8..1a8c0903c 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -64,7 +64,8 @@ class Backtesting: config['dry_run'] = True self.strategylist: List[IStrategy] = [] self.all_results: Dict[str, Dict] = {} - + self.processed_dfs: Dict[str, Dict] = {} + self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config) self.dataprovider = DataProvider(self.config, None) @@ -136,6 +137,10 @@ class Backtesting: self.config['startup_candle_count'] = self.required_startup self.exchange.validate_required_startup_candles(self.required_startup, self.timeframe) + self.enable_backtest_signal_candle_export = False + if self.config.get('enable_backtest_signal_candle_export', None) is not None: + self.enable_backtest_signal_candle_export = bool(self.config.get('enable_backtest_signal_candle_export')) + self.progress = BTProgress() self.abort = False @@ -636,6 +641,25 @@ class Backtesting: }) self.all_results[self.strategy.get_strategy_name()] = results + if self.enable_backtest_signal_candle_export: + signal_candles_only = {} + for pair in preprocessed_tmp.keys(): + signal_candles_only_df = DataFrame() + + pairdf = preprocessed_tmp[pair] + resdf = results['results'] + pairresults = resdf.loc[(resdf["pair"] == pair)] + + if pairdf.shape[0] > 0: + for t, v in pairresults.open_date.items(): + allinds = pairdf.loc[(pairdf['date'] < v)] + signal_inds = allinds.iloc[[-1]] + signal_candles_only_df = signal_candles_only_df.append(signal_inds) + + signal_candles_only[pair] = signal_candles_only_df + + self.processed_dfs[self.strategy.get_strategy_name()] = signal_candles_only + return min_date, max_date def start(self) -> None: