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]))
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))