def testSignFunction(self):
        ma5 = MovingAverage(5, 'close')
        holder = Sign(ma5)
        holder2 = (ma5 ^ (-ma5)) >> Sign

        for i, close in enumerate(self.sampleClose):
            data = {'close': close}
            ma5.push(data)
            holder.push(data)
            holder2.push(data)

            expected = 1 if ma5.result() >= 0 else -1
            calculated = holder.result()

            self.assertEqual(calculated, expected, "at index {0:d}\n"
                                                   "expected:   {1:f}\n"
                                                   "calculated: {2:f}".format(i, expected, calculated))

            calculated = holder2.result()
            self.assertEqual(calculated[0], expected, "at index {0:d}\n"
                                                      "expected:   {1:f}\n"
                                                      "calculated: {2:f}".format(i, expected, calculated[0]))

            self.assertEqual(calculated[1], -expected, "at index {0:d}\n"
                                                       "expected:   {1:f}\n"
                                                       "calculated: {2:f}".format(i, expected, calculated[1]))
    def testSignFunction(self):
        ma5 = MovingAverage(5, 'close')
        holder = Sign(ma5)
        holder2 = (ma5 ^ (-ma5)) >> Sign

        for i, close in enumerate(self.sampleClose):
            data = {'close': close}
            ma5.push(data)
            holder.push(data)
            holder2.push(data)

            expected = 1 if ma5.result() >= 0 else -1
            calculated = holder.result()

            self.assertEqual(
                calculated, expected, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated))

            calculated = holder2.result()
            self.assertEqual(
                calculated[0], expected, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated[0]))

            self.assertEqual(
                calculated[1], -expected, "at index {0:d}\n"
                "expected:   {1:f}\n"
                "calculated: {2:f}".format(i, expected, calculated[1]))
Esempio n. 3
0
    def testSign(self):
        sign = Sign(dependency='close')

        for i, value in enumerate(self.samplesClose):
            sign.push(dict(close=value))
            expected = np.sign(self.samplesClose[i])

            calculated = sign.result()
            self.assertAlmostEqual(
                expected, calculated, 10, "at index {0:d}\n"
                "expected average:   {1:f}\n"
                "calculated average: {2:f}".format(i, expected, calculated))
Esempio n. 4
0
    def testArithmeticFunctionsDeepcopy(self):
        data = {'x': 1}

        test = Exp('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.exp(data['x']), copied.value)

        test = Log('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.log(data['x']), copied.value)

        test = Sqrt('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.sqrt(data['x']), copied.value)

        data['x'] = -1.

        test = Pow('x', 2)
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(data['x']**2, copied.value)

        test = Abs('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(abs(data['x']), copied.value)

        test = Sign('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(-1., copied.value)

        data['x'] = 1.

        test = Acos('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.acos(data['x']), copied.value)

        test = Asin('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.asin(data['x']), copied.value)

        test = Acosh('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.acosh(data['x']), copied.value)

        test = Asinh('x')
        test.push(data)
        copied = copy.deepcopy(test)
        self.assertAlmostEqual(math.asinh(data['x']), copied.value)
Esempio n. 5
0
    def testArithmeticFunctionsPickle(self):
        data = {'x': 1}

        test = Exp('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Log('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Sqrt('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        data['x'] = -1.

        test = Pow('x', 2)
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Abs('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Sign('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        data['x'] = 1.

        test = Acos('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Asin('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Acosh('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)

        test = Asinh('x')
        test.push(data)
        with tempfile.NamedTemporaryFile('w+b', delete=False) as f:
            pickle.dump(test, f)

        with open(f.name, 'rb') as f2:
            pickled = pickle.load(f2)
            self.assertAlmostEqual(test.value, pickled.value)
        os.unlink(f.name)
Esempio n. 6
0
 def testSignStr(self):
     s = Sign('roe')
     self.assertEqual("\mathrm{sign}(''\\text{roe}'')", str(s))