After defining all of our core modular components, we are now ready to implement the backtesting engine as the BacktestEngine class with the following codes:
class BacktestEngine: def __init__(self, symbol, trade_qty, start='', end=''): self.symbol = symbol self.trade_qty = trade_qty self.market_data_source = MarketDataSource( symbol, tick_event_handler=self.on_tick_event, start=start, end=end ) self.strategy = None self.unfilled_orders = [] self.positions = dict() self.df_rpnl = None
Within the backtest engine, we store the symbol and the number of units to trade. An instance of MarketDataSource is created with the symbol, together with the start and end dates for defining the timeframe of our ...