Hi Everyone, 

I am new to QuantConnect and am trying to implement a general version of the Fading the Gap Strategy (i.e. easily expandable for several stocks, uses a helper data class), but am having trouble doing so.

  1. My scheduled functions lead to runtime errors because self.CurrentSlice is None. Why is this happening?
  2. Even when I begin my functions checking if self.CurrentSlice is None, I still get runtime errors that a “NoneType is not callable”. Why is this?

 

I apologize for the rather basic questions, but any help would be greatly appreciated. 

Thanks!

 

Initialize() Function Snippet

        SYMBOLS = ["AAPL"]
        NUM_DEVIATIONS = -3 

        # Subscribe to data for our stocks, schedule event handlers, and create
        # data class instances
        self.symbolData = {}
        for symbol in SYMBOLS:
            self.AddEquity(symbol, Resolution.Minute)
            self.symbolData[symbol] = SymbolData(symbol)
            self.Schedule.On(self.DateRules.EveryDay(), 
                            self.TimeRules.BeforeMarketClose(symbol, 0),
                            self.ClosingBar(symbol)) 
            self.Schedule.On(self.DateRules.EveryDay(),
                            self.TimeRules.AfterMarketOpen(symbol, 1),
                            self.OpeningBar(symbol, NUM_DEVIATIONS))
            self.Schedule.On(self.DateRules.EveryDay(),
                            self.TimeRules.AfterMarketOpen(symbol, 60),
                            self.ClosePositions(symbol)) 

 

Scheduled Functions

    def OpeningBar(self, symbol, k):
    	# ADDED FOR DEBUGGING

        if self.CurrentSlice is None:
            return

        data = self.symbolData[symbol]
        data.UpdateWindow(self.CurrentSlice)

        if not data.IsReady():
            return

        if data.CalculateDeviations() < k:
            self.SetHoldings(symbol, 1)




    def ClosingBar(self, symbol):
    	# ADDED FOR DEBUGGING
        if self.CurrentSlice is None:
            return
        self.symbolData[symbol].UpdateWindow(self.CurrentSlice)

 

Helper Class

class SymbolData(Object):
    def __init__(self, symbol):
        self.symbol = symbol
        self.window = RollingWindow[TradeBar](2)
        self.volatility = StandardDeviation(self.symbol, 100)

    def UpdateWindow(self, slice):
        if self.symbol in slice.Bars:
            self.window.Add(slice[symbol])

    def UpdateStandarDeviation(self, time, slice):
        if slice[self.symbol] is not None:
            self.volatility.Update(self.Time, slice[self.symbol].Close)

    def CalculateDeviations(self):
        delta = self.window[0].Open - self.window[1].Close
        deviations = delta / self.volatility.Current.Value
        return deviations

    def IsReady(self):
        return self.window.IsReady and self.volatility.IsReady