Ejemplo n.º 1
0
 def __init__(self, dataSeries, period, numStdDev, maxLen=None):
     self.__sma = ma.SMA(dataSeries, period, maxLen=maxLen)
     self.__stdDev = stats.StdDev(dataSeries, period, maxLen=maxLen)
     self.__upperBand = dataseries.SequenceDataSeries(maxLen)
     self.__lowerBand = dataseries.SequenceDataSeries(maxLen)
     self.__numStdDev = numStdDev
     # It is important to subscribe after sma and stddev since we'll use those values.
     dataSeries.getNewValueEvent().subscribe(self.__onNewValue)
Ejemplo n.º 2
0
    def testStdDev_Bounded(self):
        values = [1, 1, 2, 3, 5]
        seqDS = dataseries.SequenceDataSeries()
        stdDev = stats.StdDev(seqDS, 2, maxLen=2)
        
        for value in values:
            seqDS.append(value)

        self.assertEqual(stdDev[0], numpy.array([2, 3]).std())
        self.assertEqual(stdDev[1], numpy.array([3, 5]).std())
Ejemplo n.º 3
0
 def testStdDev_1(self):
     values = [1, 1, 2, 3, 5]
     seqDS = dataseries.SequenceDataSeries()
     stdDev = stats.StdDev(seqDS, 1)
     
     for value in values:
         seqDS.append(value)
     
     for i in stdDev:
         self.assertEqual(i, 0)
Ejemplo n.º 4
0
    def testStdDev(self):
        values = [1, 1, 2, 3, 5]
        seqDS = dataseries.SequenceDataSeries()
        stdDev = stats.StdDev(seqDS, 2)
        
        for value in values:
            seqDS.append(value)

        self.assertEqual(stdDev[0], None)
        self.assertEqual(stdDev[1], numpy.array([1, 1]).std())
        self.assertEqual(stdDev[2], numpy.array([1, 2]).std())
        self.assertEqual(stdDev[3], numpy.array([2, 3]).std())
        self.assertEqual(stdDev[4], numpy.array([3, 5]).std())
Ejemplo n.º 5
0
    def __init__(self, feed):
        super().__init__()

        stdDevPeriod = 90
        smaPeriod = 20

        self.__returns = {}
        self.__stdDev = {}
        self.__ma = {}

        for instrument in feed.getRegisteredInstruments():
            priceDS = feed[instrument].getAdjCloseDataSeries()
            # Returns over the adjusted close values.
            self.__returns[instrument] = roc.RateOfChange(priceDS, 1)
            # StdDev over those returns.
            self.__stdDev[instrument] = stats.StdDev(self.__returns[instrument], stdDevPeriod)
            # MA over the adjusted close values.
            self.__ma[instrument] = ma.SMA(priceDS, smaPeriod)