code: def onBars(self, bars):
      self.__statArbHelper.update()
  
      # These is used only for plotting purposes.
      self.__spread.appendWithDateTime(
          bars.getDateTime(), self.__statArbHelper.getSpread()
      )
      self.__hedgeRatio.appendWithDateTime(
          bars.getDateTime(), self.__statArbHelper.getHedgeRatio()
      )
  
      if bars.getBar(self.__i1) and bars.getBar(self.__i2):
          hedgeRatio = self.__statArbHelper.getHedgeRatio()
          zScore = self.__statArbHelper.getZScore()
          if zScore is not None:
              currentPos = abs(
                  self.getBroker().getShares(self.__i1)
              ) + abs(self.getBroker().getShares(self.__i2))
              if abs(zScore) <= 1 and currentPos != 0:
                  self.reducePosition(self.__i1)
                  self.reducePosition(self.__i2)
              elif (
                  zScore <= -2 and currentPos == 0
              ):  # Buy spread when its value drops below 2 standard deviations.
                  self.buySpread(bars, hedgeRatio)
              elif (
                  zScore >= 2 and currentPos == 0
              ):  # Short spread when its value rises above 2 standard deviations.
                  self.sellSpread(bars, hedgeRatio)
  
imports: from __future__ import print_function
  from pyalgotrade import strategy
  from pyalgotrade import dataseries
  from pyalgotrade.dataseries import aligned
  from pyalgotrade import plotter
  from pyalgotrade.barfeed import yahoofeed
  from pyalgotrade.stratanalyzer import sharpe
  import numpy
  import statsmodels.api
label_desc: Use image node_id 8 for calling the StatArb obj's underlying member method code with example usage: obj.onBars(bars) without return types