Add support for storing buy candle indicator rows in backtesting results

This commit is contained in:
froggleston 2022-03-16 12:16:24 +00:00
parent 4c268847d4
commit 162e94455b

View File

@ -64,6 +64,7 @@ class Backtesting:
config['dry_run'] = True config['dry_run'] = True
self.strategylist: List[IStrategy] = [] self.strategylist: List[IStrategy] = []
self.all_results: Dict[str, Dict] = {} self.all_results: Dict[str, Dict] = {}
self.processed_dfs: Dict[str, Dict] = {}
self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config) self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config)
self.dataprovider = DataProvider(self.config, None) self.dataprovider = DataProvider(self.config, None)
@ -136,6 +137,10 @@ class Backtesting:
self.config['startup_candle_count'] = self.required_startup self.config['startup_candle_count'] = self.required_startup
self.exchange.validate_required_startup_candles(self.required_startup, self.timeframe) 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.progress = BTProgress()
self.abort = False self.abort = False
@ -636,6 +641,25 @@ class Backtesting:
}) })
self.all_results[self.strategy.get_strategy_name()] = results 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 return min_date, max_date
def start(self) -> None: def start(self) -> None: