def testRSI(self):
     barDs = self.__loadBarDS()
     self.assertAmountsAreEqual(
         indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[14],
         49.15)  # Original value 49.14
     self.assertAmountsAreEqual(
         indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[15],
         52.33)  # Original value 52.32
     self.assertAmountsAreEqual(
         indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[16], 46.07)
     self.assertAmountsAreEqual(
         indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[-1], 49.63)
Example #2
0
 def testRSI(self):
     barDs = self.__loadBarDS()
     self.assertTrue(
         compare(
             indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[14],
             49.15))  # Original value 49.14
     self.assertTrue(
         compare(
             indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[15],
             52.33))  # Original value 52.32
     self.assertTrue(
         compare(
             indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[16], 46.07))
     self.assertTrue(
         compare(
             indicator.RSI(barDs.getCloseDataSeries(), 252, 14)[-1], 49.63))
Example #3
0
 def __init__(self, feed, instrument, rsiPeriod):
     strategy.BacktestingStrategy.__init__(self, feed)
     self.__instrument = instrument
     self.__position = None
     # We'll use adjusted close values instead of regular close values.
     self.setUseAdjustedValues(True)
     self.__prices = feed[instrument].getPriceDataSeries()
     self.__position = None
     self.__rsiPeriod = int(rsiPeriod)
     self.__rsi = indicator.RSI(self.__prices, self.__rsiPeriod)
    def enterLongSignal(self, extPriceBarDS, extPriceDS):
        upper, middle, lower = indicator.BBANDS(extPriceDS,
                                                count=100,
                                                timeperiod=self.bBandsPeriod,
                                                matype=MA_Type.SMA,
                                                nbdevup=self.numStdDev,
                                                nbdevdn=self.numStdDev)
        fastk, fastd = indicator.STOCHF(extPriceBarDS,
                                        count=100,
                                        fastk_period=self.soPeriod,
                                        fastd_period=self.soDPeriod,
                                        fastd_matype=MA_Type.SMA)

        rsi = indicator.RSI(extPriceDS, count=100, timeperiod=self.rsiPeriod)

        longEntryFilter_1 = rsi[-1] <= self.overSoldThreshold
        longEntryFilter_2 = fastd[-1] <= self.overSoldThreshold
        longEntryFilter_3 = cross.cross_below(extPriceDS, lower) > 0
        return longEntryFilter_1 and longEntryFilter_2 and longEntryFilter_3