def testAccumulatorBasic(self):

        # check parameter list should not be empty
        with self.assertRaises(ValueError):
            Max(dependency=[])

        m = Max(dependency='x')
        m.push({'x': 10.0})
        self.assertAlmostEqual(m.result(), m.value)
    def testMax(self):
        mm = Max(dependency='close')

        for i, value in enumerate(self.samplesClose):
            mm.push(dict(close=value))
            expected = max(self.samplesClose[:i + 1])
            calculated = mm.result()

            self.assertAlmostEqual(expected, calculated, 10, "at index {0:d}\n"
                                                             "expected max:   {1:f}\n"
                                                             "calculated max: {2:f}".format(i, expected, calculated))
    def testMax(self):
        mm = Max(dependency='close')

        for i, value in enumerate(self.samplesClose):
            mm.push(dict(close=value))
            expected = max(self.samplesClose[:i + 1])
            calculated = mm.result()

            self.assertAlmostEqual(
                expected, calculated, 10, "at index {0:d}\n"
                "expected max:   {1:f}\n"
                "calculated max: {2:f}".format(i, expected, calculated))
Esempio n. 4
0
    def testGreaterOperator(self):
        m1 = Max('x')
        m2 = Min('x')
        cmp = m1 > m2

        cmp.push(dict(x=1.0))
        self.assertEqual(False, cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual(True, cmp.result())
Esempio n. 5
0
    def testLessOrEqualOperators(self):
        m1 = Max('x')
        m2 = Min('x')
        cmp = m1 <= m2

        cmp.push(dict(x=1.0))
        self.assertEqual(True, cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual(False, cmp.result())
Esempio n. 6
0
    def testGetItemOperator(self):
        listHolder = MovingAverage(20, 'close') ^ Max('open') ^ Min('close')
        listHolder1 = listHolder[1]
        listHolder2 = listHolder[1:3]
        maxer = Max('open')

        for i, (open,
                close) in enumerate(zip(self.sampleOpen, self.sampleClose)):
            data = {'close': close, 'open': open}
            listHolder1.push(data)
            listHolder2.push(data)
            maxer.push(data)

            expected = maxer.result()
            calculated = listHolder1.result()
            self.assertAlmostEqual(
                expected, calculated, 12, "at index {0:d}\n"
                "expected beta:   {1:f}\n"
                "calculated beta: {2:f}".format(i, expected, calculated))

            calculated = listHolder2.result()[0]
            self.assertAlmostEqual(
                expected, calculated, 12, "at index {0:d}\n"
                "expected beta:   {1:f}\n"
                "calculated beta: {2:f}".format(i, expected, calculated))
    def testGetItemOperator(self):
        listHolder = MovingAverage(20, 'close') ^ Max('open') ^ Minimum('close')
        listHolder1 = listHolder[1]
        listHolder2 = listHolder[1:3]
        maxer = Max('open')

        for i, (open, close) in enumerate(zip(self.sampleOpen, self.sampleClose)):
            data = {'close': close, 'open': open}
            listHolder1.push(data)
            listHolder2.push(data)
            maxer.push(data)

            expected = maxer.result()
            calculated = listHolder1.result()
            self.assertAlmostEqual(expected, calculated, 12, "at index {0:d}\n"
                                                             "expected beta:   {1:f}\n"
                                                             "calculated beta: {2:f}".format(i, expected, calculated))

            calculated = listHolder2.result()[0]
            self.assertAlmostEqual(expected, calculated, 12, "at index {0:d}\n"
                                                             "expected beta:   {1:f}\n"
                                                             "calculated beta: {2:f}".format(i, expected, calculated))
    def testCompoundedOperator(self):
        ma5 = MovingAverage(5, 'x')
        maxer = Max('close')
        max5ma = Max('close') >> MovingAverage(5)
        max5ma2 = MovingAverage(5, Max('close'))
        average = Average('close')
        sumM = Sum('close')
        mvTest = Correlation(dependency=('x', 'y'))
        mvCorr = (Average('close') ^ Sum('close')) >> Correlation(dependency=('x', 'y'))

        for i, close in enumerate(self.sampleClose):
            data = {'close': close, 'open': open}
            maxer.push(data)
            data2 = {'x': maxer.result()}
            ma5.push(data2)
            max5ma.push(data)
            max5ma2.push(data)
            average.push(data)
            sumM.push(data)
            data3 = {'x': average.result(), 'y': sumM.result()}
            mvTest.push(data3)
            mvCorr.push(data)

            expected = ma5.result()
            calculated = max5ma.result()
            self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n"
                                                             "expected:   {1:f}\n"
                                                             "calculated: {2:f}".format(i, expected, calculated))

            calculated = max5ma2.result()
            self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n"
                                                             "expected:   {1:f}\n"
                                                             "calculated: {2:f}".format(i, expected, calculated))

            if i >= 1:
                expected = mvTest.result()
                calculated = mvCorr.result()
                self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n"
                                                                 "expected:   {1:f}\n"
                                                                 "calculated: {2:f}".format(i, expected, calculated))

        with self.assertRaises(ValueError):
            _ = Max('close') >> math.sqrt

        with self.assertRaises(ValueError):
            _ = (Max('close') ^ Minimum('close')) >> MovingCorrelation(20, dependency=('x', 'y', 'z'))

        (Max('close') ^ Minimum('close')) >> MovingCorrelation(20, dependency=('x', 'y'))
    def testAccumulatorBasic(self):

        # check parameter list should not be empty
        with self.assertRaises(ValueError):
            Max(dependency=[])

        m = Max(dependency='x')
        m.push({'x': 10.0})
        self.assertAlmostEqual(m.result(), m.value)
    def testListedOperator(self):
        ma20 = MovingAverage(20, 'close')
        maxer = Max('open')
        minimumer = Minimum('close')
        listHolder = MovingAverage(20, 'close') ^ Max('open') ^ Minimum('close')
        listHolder2 = 2.0 ^ MovingAverage(20, 'close')
        listHolder3 = MovingAverage(20, 'close') ^ 2.0

        for i, (open, close) in enumerate(zip(self.sampleOpen, self.sampleClose)):
            data = {'close': close, 'open': open}
            ma20.push(data)
            maxer.push(data)
            minimumer.push(data)
            listHolder.push(data)
            listHolder2.push(data)
            listHolder3.push(data)

            expected = (ma20.result(), maxer.result(), minimumer.result())
            calculated = listHolder.result()
            for ev, cv in zip(expected, calculated):
                self.assertAlmostEqual(ev, cv, 12, "at index {0:d}\n"
                                                   "expected:   {1}\n"
                                                   "calculated: {2}".format(i, expected, calculated))

            expected = (2.0, ma20.result())
            calculated = listHolder2.result()
            for ev, cv in zip(expected, calculated):
                self.assertAlmostEqual(ev, cv, 12, "at index {0:d}\n"
                                                   "expected:   {1}\n"
                                                   "calculated: {2}".format(i, expected, calculated))

            expected = (ma20.result(), 2.0)
            calculated = listHolder3.result()
            for ev, cv in zip(expected, calculated):
                self.assertAlmostEqual(ev, cv, 12, "at index {0:d}\n"
                                                   "expected:   {1}\n"
                                                   "calculated: {2}".format(i, expected, calculated))
    def testGreaterOperator(self):
        m1 = Max('x')
        m2 = Minimum('x')
        cmp = m1 > m2

        cmp.push(dict(x=1.0))
        self.assertEqual(False, cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual(True, cmp.result())

        cmp = (m1 ^ m2) > m2
        cmp.push(dict(x=1.0))
        self.assertEqual((False, False), cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual((True, False), cmp.result())

        cmp = m1 > (m1 ^ m2)
        cmp.push(dict(x=1.0))
        self.assertEqual((False, False), cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual((False, True), cmp.result())
    def testLessOrEqualOperators(self):
        m1 = Max('x')
        m2 = Minimum('x')
        cmp = m1 <= m2

        cmp.push(dict(x=1.0))
        self.assertEqual(True, cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual(False, cmp.result())

        cmp = (m1 ^ m2) <= m2
        cmp.push(dict(x=1.0))
        self.assertEqual((True, True), cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual((False, True), cmp.result())

        cmp = m1 <= (m1 ^ m2)
        cmp.push(dict(x=1.0))
        self.assertEqual((True, True), cmp.result())
        cmp.push(dict(x=2.0))
        self.assertEqual((True, False), cmp.result())
    def testListedOperator(self):
        ma20 = MovingAverage(20, 'close')
        maxer = Max('open')
        minimumer = Minimum('close')
        listHolder = MovingAverage(20,
                                   'close') ^ Max('open') ^ Minimum('close')
        listHolder2 = 2.0 ^ MovingAverage(20, 'close')
        listHolder3 = MovingAverage(20, 'close') ^ 2.0

        for i, (open,
                close) in enumerate(zip(self.sampleOpen, self.sampleClose)):
            data = {'close': close, 'open': open}
            ma20.push(data)
            maxer.push(data)
            minimumer.push(data)
            listHolder.push(data)
            listHolder2.push(data)
            listHolder3.push(data)

            expected = (ma20.result(), maxer.result(), minimumer.result())
            calculated = listHolder.result()
            for ev, cv in zip(expected, calculated):
                self.assertAlmostEqual(
                    ev, cv, 12, "at index {0:d}\n"
                    "expected:   {1}\n"
                    "calculated: {2}".format(i, expected, calculated))

            expected = (2.0, ma20.result())
            calculated = listHolder2.result()
            for ev, cv in zip(expected, calculated):
                self.assertAlmostEqual(
                    ev, cv, 12, "at index {0:d}\n"
                    "expected:   {1}\n"
                    "calculated: {2}".format(i, expected, calculated))

            expected = (ma20.result(), 2.0)
            calculated = listHolder3.result()
            for ev, cv in zip(expected, calculated):
                self.assertAlmostEqual(
                    ev, cv, 12, "at index {0:d}\n"
                    "expected:   {1}\n"
                    "calculated: {2}".format(i, expected, calculated))
Esempio n. 14
0
    def testCompoundedOperator(self):
        ma5 = MovingAverage(5, 'x')
        maxer = Max('close')
        max5ma = Max('close') >> MovingAverage(5)
        max5ma2 = MovingAverage(5, Max('close'))
        average = Average('close')
        sumM = Sum('close')
        mvTest = Correlation(dependency=('x', 'y'))
        mvCorr = (Average('close')
                  ^ Sum('close')) >> Correlation(dependency=('x', 'y'))

        for i, close in enumerate(self.sampleClose):
            data = {'close': close, 'open': 1.}
            maxer.push(data)
            data2 = {'x': maxer.result()}
            ma5.push(data2)
            max5ma.push(data)
            max5ma2.push(data)
            average.push(data)
            sumM.push(data)
            data3 = {'x': average.result(), 'y': sumM.result()}
            mvTest.push(data3)
            mvCorr.push(data)

            expected = ma5.result()
            calculated = max5ma.result()
            self.assertAlmostEqual(
                calculated, expected, 12, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated))

            calculated = max5ma2.result()
            self.assertAlmostEqual(
                calculated, expected, 12, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated))

            if i >= 1:
                expected = mvTest.result()
                calculated = mvCorr.result()
                self.assertAlmostEqual(
                    calculated, expected, 12, "at index {0:d}\n"
                    "expected:   {1:f}\n"
                    "calculated: {2:f}".format(i, expected, calculated))

        with self.assertRaises(ValueError):
            _ = Max('close') >> math.sqrt

        with self.assertRaises(ValueError):
            _ = (Max('close') ^ Min('close')) >> MovingCorrelation(
                20, dependency=('x', 'y', 'z'))

        (Max('close') ^ Min('close')) >> MovingCorrelation(
            20, dependency=('x', 'y'))
Esempio n. 15
0
 def testAddedNanValue(self):
     m = Max(dependency='x')
     m.push({'x': 10.0})
     m.push({'x': np.nan})
     self.assertAlmostEqual(10., m.value)
Esempio n. 16
0
 def testAccumulatorBasic(self):
     m = Max(dependency='x')
     m.push({'x': 10.0})
     self.assertAlmostEqual(m.result(), m.value)
Esempio n. 17
0
    def testCompoundedOperator(self):
        ma5 = MovingAverage(5, 'x')
        maxer = Max('close')
        max5ma = Max('close') >> MovingAverage(5, 'max')
        max5ma2 = MovingAverage(5, Max('close'))

        for i, close in enumerate(self.sampleClose):
            data = {'close': close, 'open': 1.}
            maxer.push(data)
            data2 = {'x': maxer.result()}
            ma5.push(data2)
            max5ma.push(data)
            max5ma2.push(data)

            expected = ma5.result()
            calculated = max5ma.result()
            self.assertAlmostEqual(
                calculated, expected, 12, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated))

            calculated = max5ma2.result()
            self.assertAlmostEqual(
                calculated, expected, 12, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated))

        with self.assertRaises(ValueError):
            _ = Max('close') >> math.sqrt