def testAsinhFunction(self): ma5 = MovingAverage(5, 'close') holder = Asinh(ma5) for i, close in enumerate(self.sampleClose): data = {'close': close} ma5.push(data) holder.push(data) expected = math.asinh(ma5.result()) calculated = holder.result() self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n" "expected: {1:f}\n" "calculated: {2:f}".format(i, expected, calculated))
def testAsinhFunction(self): ma5 = MovingAverage(5, 'close') holder = Asinh(ma5) sampleClose = np.sinh(self.sampleClose) for i, close in enumerate(sampleClose): data = {'close': close} ma5.push(data) holder.push(data) expected = math.asinh(ma5.result()) calculated = holder.result() self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n" "expected: {1:f}\n" "calculated: {2:f}".format(i, expected, calculated))
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)
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)
def testNegStr(self): s = -Asinh('roe') self.assertEqual("-\mathrm{ASinh}(''\\text{roe}'')", str(s))
def testAsinhStr(self): s = Asinh('roe') self.assertEqual("\mathrm{ASinh}(''\\text{roe}'')", str(s))