예제 #1
0
 def __init__(self, feed, instrument, bBandsPeriod, smaPeriod_short,
              smaPeriod_long, slope_period):
     strategy.BacktestingStrategy.__init__(self, feed)
     self.__instrument = instrument
     self.__prices = feed[instrument].getPriceDataSeries()
     self.__sma_short = ma.SMA(self.__prices, smaPeriod_short)
     self.__sma_long = ma.SMA(self.__prices, smaPeriod_long)
     self.__bbands = bollinger.BollingerBands(
         feed[instrument].getCloseDataSeries(), bBandsPeriod, 2)
     self.__slope = linreg.Slope(self.__prices, slope_period)
     self.__middle_slope = linreg.Slope(self.__bbands.getMiddleBand(),
                                        slope_period)
     self.__longPos = None
     self.__shortPos = None
     self.slope_period = slope_period
예제 #2
0
 def __buildSlope(self,
                  values,
                  period,
                  slopeMaxLen=dataseries.DEFAULT_MAX_LEN):
     seqDS = dataseries.SequenceDataSeries()
     ret = linreg.Slope(seqDS, period, slopeMaxLen)
     for value in values:
         seqDS.append(value)
     return ret