示例#1
0
    def testIncremental_Recursive(self):
        size = 20
        ds1 = dataseries.SequenceDataSeries()
        ds2 = dataseries.SequenceDataSeries()
        ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
        # Align the aligned dataseries again with respect to each other.
        ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
        now = datetime.datetime.now()

        for i in range(size):
            ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
            ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)

            self.assertEqual(len(ads1), len(ads2))
            self.assertEqual(ads1[:], ads2[:])
            self.assertEqual(ads1.getDateTimes()[:], ads2.getDateTimes()[:])
示例#2
0
 def __init__(self, ds1, ds2, windowSize):
     # We're going to use datetime aligned versions of the dataseries.
     self.__ds1, self.__ds2 = aligned.datetime_aligned(ds1, ds2)
     self.__windowSize = windowSize
     self.__hedgeRatio = None
     self.__spread = None
     self.__spreadMean = None
     self.__spreadStd = None
     self.__zScore = None
示例#3
0
    def testNotAligned_Recursive(self):
        size = 20
        ds1 = dataseries.SequenceDataSeries()
        ds2 = dataseries.SequenceDataSeries()
        ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
        # Align the aligned dataseries again with respect to each other.
        ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
        now = datetime.datetime.now()

        for i in range(size):
            if i % 2 == 0:
                ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
            else:
                ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)

        self.assertEqual(len(ds1), len(ds2))

        for ads in [ads1, ads2]:
            self.assertEqual(len(ads), 0)
            self.assertEqual(ads.getValueAbsolute(0), None)
            self.assertEqual(ads.getDateTimes(), [])
示例#4
0
    def testBoundedSources(self):
        ds1 = dataseries.SequenceDataSeries(1)
        ds2 = dataseries.SequenceDataSeries(1)
        ads1, ads2 = aligned.datetime_aligned(ds1, ds2)

        now = datetime.datetime.now()
        ds1.appendWithDateTime(now + datetime.timedelta(seconds=1), 1)
        ds1.appendWithDateTime(now + datetime.timedelta(seconds=2), 2)
        ds1.appendWithDateTime(now + datetime.timedelta(seconds=3), 3)
        ds2.appendWithDateTime(now + datetime.timedelta(seconds=2), 2)
        ds2.appendWithDateTime(now + datetime.timedelta(seconds=3), 3)
        ds2.appendWithDateTime(now + datetime.timedelta(seconds=4), 4)

        self.assertEqual(ads1[:], [2, 3])
        self.assertEqual(ads2[:], [2, 3])
示例#5
0
    def testPartiallyAligned_Recursive(self):
        size = 20
        commonDateTimes = []
        ds1 = dataseries.SequenceDataSeries()
        ds2 = dataseries.SequenceDataSeries()
        ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
        # Align the aligned dataseries again with respect to each other.
        ads1, ads2 = aligned.datetime_aligned(ads1, ads2)
        now = datetime.datetime.now()

        for i in range(size):
            if i % 3 == 0:
                commonDateTimes.append(now + datetime.timedelta(seconds=i))
                ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
                ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
            elif i % 2 == 0:
                ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
            else:
                ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)

        self.assertEqual(len(ads1), len(ads2))
        self.assertEqual(ads1[:], ads2[:])
        self.assertEqual(ads1.getDateTimes(), commonDateTimes)
        self.assertEqual(ads2.getDateTimes(), commonDateTimes)
示例#6
0
    def testFullyAligned(self):
        size = 20
        ds1 = dataseries.SequenceDataSeries()
        ds2 = dataseries.SequenceDataSeries()
        ads1, ads2 = aligned.datetime_aligned(ds1, ds2)
        now = datetime.datetime.now()

        for i in range(size):
            ds1.appendWithDateTime(now + datetime.timedelta(seconds=i), i)
            ds2.appendWithDateTime(now + datetime.timedelta(seconds=i), i)

        self.assertEqual(len(ds1), len(ds2))

        for ads in [ads1, ads2]:
            self.assertEqual(len(ads), size)
            for i in range(size):
                self.assertEqual(ads.getValueAbsolute(i), i)
                self.assertEqual(ads.getDateTimes()[i],
                                 now + datetime.timedelta(seconds=i))