def testMin(self): mm = Min('close') for i, value in enumerate(self.samplesClose): mm.push(dict(close=value)) expected = min(self.samplesClose[:i + 1]) calculated = mm.result() self.assertAlmostEqual( expected, calculated, 10, "at index {0:d}\n" "expected min: {1:f}\n" "calculated min: {2:f}".format(i, expected, calculated))
def testDivOperator(self): mc5 = MovingCorrelation(5, ['open', 'close']) minum = Min('open') divRes = Min('open') / MovingCorrelation(5, ['open', 'close']) for i, (open, close) in enumerate(zip(self.sampleOpen, self.sampleClose)): data = {'close': close, 'open': open} mc5.push(data) minum.push(data) divRes.push(data) if i >= 1: expected = minum.result() / mc5.result() calculated = divRes.result() self.assertAlmostEqual(calculated, expected, 12, "at index {0:d}\n" "expected: {1:f}\n" "calculated: {2:f}".format(i, expected, calculated))
def testListedOperator(self): ma20 = MovingAverage(20, 'close') maxer = Max('open') minimumer = Min('close') listHolder = MovingAverage(20, 'close') ^ Max('open') ^ Min('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))