mhallsmoore / qstrader

QuantStart.com - QSTrader backtesting simulation engine.
https://www.quantstart.com/qstrader/
MIT License
2.93k stars 855 forks source link

Multi-Ticker Backtesting #223

Closed enriqueromualdez closed 8 months ago

enriqueromualdez commented 7 years ago

Hey guys,

I've been working on adding Multi-Ticker backtesting for the past couple of weeks and so far, haven't had any luck with completing this enhancement. I've thought of a few different approaches, but so far, I haven't yet been able to decide on which best approach to take.

My first approach was to combine the separate BarEvents into deque list which would be maxed out by the number of tickers in question. The code snippet below is for a backtest with two tickers:

class TradingSessionMulti(object):
    ....
    self.bev_list = deque(maxlen=len(self.tickers))
    ....

def _run_session(self):
    ....
    self.bev_list.append(event)
         if len(self.bev_list) == 2:

              for event in list(self.bev_list):
                     continue backtest ....

The issue I now face is how to call on all aspects of signal generation, position sizing, risk management, and execution of Events in one call of _run_session().. If I'm not mistaken, _run_session() is only designed to handle one Event at a time.

So far, I've tried using the Threading module, Multiprocessing module, and using a simple for-loop approach, but to no avail.

One approach I've yet to try is the one mentioned on #200 , where multiple BarEvents would be compiled into a DailyBarEvent which would consist of the Event information for all of the tickers within the backtest.

Has anybody else had any success with this enhancement?