Binding our modules with a backtesting engine

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 ...

Get Mastering Python for Finance - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.