Backtest¶
- class src.boatwright.Backtest.Backtest(strategy, data, broker, debug=False)¶
- Parameters:
strategy (Strategy) – strategy
broker (BacktestBroker) – broker model
data (DataFrame) – pandas dataFrame with columns: [“datetime”, “open”, “high”, “low”, “close”, “volume”]
debug – boolean toggle to print debugging information
- calculate_signals()¶
data is updated with columns for technical indicators from
strategy.calculate_signals()
drop self.data[0:strategy.calc_prerequisite_data_length()
]. This is the range of data in which not all signals are calculated because there was not yet enough data. :return: None
- run(skip_calculate_signals=False, verbose=False)¶
Execute the backtest.
initialize_data()
is called, updating self.data with technical indicator signals. For each row in self.data,self.strategy.step()
andself.broker.step()
is called triggering and processing any orders. self.data is updated with columns [aum, quote_amount, base_amount]- Parameters:
skip_calculate_signals (bool) – boolean toggle for skipping calculation of technical indicators with strategy.calculate_signals(); i.e. assuming backtest.data is set via some other functionality
verbose – boolean toggle for printing tqdm progress bar to the terminal
- Variables:
self.runtime – duration in seconds to complete the backtest
- Returns:
None