def testOlderDateTime(self): """append should fail with candle input that has an older datetime than the most recently processed candle """ s = Macd((3, 6, 3)) testInput = inputValues[:8] for c in testInput: s.append(c) self.assertRaises(InvalidDateTimeError, s.append, inputValues[4])
def testOutputKnownMacdValues(self): """Macd calculation should give known result with known input results are rounded by str representation of floats """ parameter = (3, 6, 3) s = Macd(parameter) ema1 = Ema(parameter[0]) ema2 = Ema(parameter[1]) emamacd = EmaMacd(parameter[2]) for c in inputValues: s.append(c) ema1.append(c) ema2.append(c) knownvalues = [] for e in range(len(ema1.output)): if ema2.output[e] == None: knownvalues.append(None) continue else: knownvalues.append(ema1.output[e] - ema2.output[e]) for i in range(len(s.output)): self.assertEqual(str(s.output[i]), str(knownvalues[i]))
def testOlderDateTime(self): """append should fail with candle input that has an older datetime than the most recently processed candle """ s = Macd((3,6,3)) testInput = inputValues[:8] for c in testInput: s.append(c) self.assertRaises(InvalidDateTimeError, s.append, inputValues[4])
def testOutputKnownMacdValues(self): """Macd calculation should give known result with known input results are rounded by str representation of floats """ parameter = (3,6,3) s = Macd(parameter) ema1 = Ema(parameter[0]) ema2 = Ema(parameter[1]) emamacd = EmaMacd(parameter[2]) for c in inputValues: s.append(c) ema1.append(c) ema2.append(c) knownvalues = [] for e in range(len(ema1.output)): if ema2.output[e] == None: knownvalues.append(None) continue else: knownvalues.append(ema1.output[e] - ema2.output[e]) for i in range(len(s.output)): self.assertEqual(str(s.output[i]), str(knownvalues[i]))
from ta.Macd import * import datetime import random ind = Macd((12, 26, 9)) d = datetime.datetime(2005, 1, 1, 9, 30) td = datetime.timedelta(0, 1) close = 12.20 nrofticks = int(60 * 60 * 6.5) # one market day with one tick every second start = datetime.datetime.now() for x in range(nrofticks): c = (d, close + 0.01, close + 0.04, close - 0.10, close, 20192812) ind.append(c) d = d + td if (random.random() > 0.4): close = close + random.random() / 2 else: close = close - random.random() / 2 end = datetime.datetime.now() diff = end - start dfsec = float("" + str(diff.seconds) + "." + str(diff.microseconds)) print( "Inserting %s candles in Macd indicator took %s seconds. %s candles per second." % (nrofticks, dfsec, nrofticks / dfsec))
from ta.Macd import * import datetime import random ind = Macd((12,26,9)) d = datetime.datetime(2005, 1, 1, 9, 30) td = datetime.timedelta(0, 1) close = 12.20 nrofticks = int(60 * 60 * 6.5) # one market day with one tick every second start = datetime.datetime.now() for x in xrange(nrofticks): c = (d, close+0.01, close+0.04, close-0.10, close, 20192812) ind.append(c) d = d + td if (random.random() > 0.4): close = close + random.random()/2 else: close = close - random.random()/2 end = datetime.datetime.now() diff = end - start dfsec = float("" + str(diff.seconds) + "." + str(diff.microseconds)) print "Inserting %s candles in Macd indicator took %s seconds. %s candles per second." % (nrofticks, dfsec, nrofticks / dfsec)
def testTupleTooLarge(self): """append should fail with tuple that has a length bigger than 6""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), None, 12.56, 12.11, 12.20, 2010912, 1425) self.assertRaises(InvalidCandleStickError, s.append, c)
def testNoneOpen(self): """append should fail with None value for open""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), None, 12.56, 12.11, 12.20, 2010912) self.assertRaises(InvalidCandleStickError, s.append, c)
def testFloatVolume(self): """append should fail with float value for volume""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), 12.34, 12.56, 12.11, 12.20, 2010912.25) self.assertRaises(InvalidCandleStickError, s.append, c)
def testFloat(self): """append should fail with float input""" s = Macd((3, 6, 3)) self.assertRaises(NotTupleError, s.append, 12.432)
def testInteger(self): """append should fail with integer input""" s = Macd((3, 6, 3)) self.assertRaises(NotTupleError, s.append, 4000)
def testCloseLowerThanLow(self): """append should fail with close lower than low""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), 12.60, 12.56, 12.11, 12.09, 2010912) self.assertRaises(InvalidCandleStickError, s.append, c)
def testOpenHigherThanHigh(self): """append should fail with open higher than high""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), 12.60, 12.56, 12.11, 12.20, 2010912) self.assertRaises(InvalidCandleStickError, s.append, c)
def testHighLowMixUp(self): """append should fail with high lower than low""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), 12.34, 12.11, 12.56, 12.20, 2010912) self.assertRaises(InvalidCandleStickError, s.append, c)
def testNegativeLow(self): """append should fail with negative low value""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), 12.34, 12.56, -12.11, 12.20, 2010912) self.assertRaises(InvalidCandleStickError, s.append, c)
def testIntegerDateTime(self): """append should fail with candle input that does not have a datetime as first element """ s = Macd((3, 6, 3)) c = (1562516271, 12.34, 12.56, 12.11, 12.20, 2010912) self.assertRaises(InvalidDateTimeError, s.append, c)
def testString(self): """append should fail with string input""" s = Macd((3, 6, 3)) self.assertRaises(NotTupleError, s.append, "dummy")
def testTupleTooSmall(self): """append should fail with tuple that has a length smaller than 6""" s = Macd((3, 6, 3)) c = (datetime.datetime(2006, 5, 19), None, 12.56, 12.11, 12.20) self.assertRaises(InvalidCandleStickError, s.append, c)