Accessing other symbol data

Hello all,
I am attempting to access the minutely data of many symbols in one symbol's instance so I can compare certain statistics to choose the top X symbols to buy at the beginning of the trading day according to a statistic I generate for each symbol at market open. I am having trouble with doing this since each symbol's instance of the script is run one-by-one in the backtest so they can't create some sort of shared dictionary like I would hope. My alternative is to pull each symbol's opening minute bar to get the opening price of each symbol, and then generate the statistic that way. The minute bar data appears to be empty when attempting this, here's a snippet of the code:

# note that this doesn't start with "self" because it's a @classmethod
    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'TQQQ' #testing

    # used to load other symbols data not in is_symbol_qualified(). Only used in backtesting
    @classmethod
    def backtesting_extra_symbols(cls, symbol, md, service, account):
        return symbol == 'SPY' #testing


def on_minute_bar(self, event, md, order, service, account, bar):
        #let's look at the first bar of the trading day
        if (service.system_time > md.market_open_time + service.time_interval(minutes=0)) and (service.system_time < md.market_open_time + service.time_interval(minutes=1)):

            bars = md.bar.daily(start=-90)
            spy = md['SPY'].bar.minute(start = -1, today_only = True)
            print spy

The console shows an empty bar with no data:

BarView(symbol='SPY', length=60, timestamp=array([], dtype=float64), open=array([], dtype=float64), high=array([], dtype=float64), low=array([], dtype=float64), close=array([], dtype=float64), volume=array([], dtype=float64), vwap=array([], dtype=float64), spread=array([], dtype=float64), bidvol=array([], dtype=float64), askvol=array([], dtype=float64), count=array([], dtype=float64), valid=array([], dtype=float64), closing_trade=array([], dtype=float64), opening_trade=array([], dtype=float64))

Is there another way to get the opening prices of each symbol in my universe so I can compare them against eachother?

Thanks.

Comments

  • I use the backtesting_extra_symbols function in many scripts and it should work. I suspect that the reason why you are getting empty bar is because the minute bar for the first minute (9:30) has not yet been formed before 9:31, so the if clause you have there inside the on_minute_bar causes it to access a minute bar before it has been formed. If you change the if clause to read between 9:31 and 9:32, it should return a bar with data.

    One thing to note is that many stocks do not get their open prints until 9:45 or even later.

    An alternate way to access the open price is to access the md.L1 object:

    https://app.cloudquant.com/#/glossary/106

Sign In or Register to comment.