Beispiel #1
0
 def testOlderDateTime(self):
     """append should fail with candle input that has an older datetime than the most recently processed candle """
     s = Atr(4)
     testInput = inputValues[:8]
     for c in testInput:
         s.append(c)
     self.assertRaises(InvalidDateTimeError, s.append, inputValues[4])
Beispiel #2
0
 def testOlderDateTime(self):
     """append should fail with candle input that has an older datetime than the most recently processed candle """
     s = Atr(4)
     testInput = inputValues[:8]
     for c in testInput:
         s.append(c)
     self.assertRaises(InvalidDateTimeError, s.append, inputValues[4])
Beispiel #3
0
 def testOutputKnownValues(self):
     """Atr calculation should give known result with known input
        results are rounded by str representation of floats
     """
     s = Atr(4)
     knownvalues = [None, None, None, 12.24, 12.372, 12.3032, 12.26992, 12.225952]
     for c in inputValues[:8]:
         s.append(c)
     for i in range(len(s.output)):
         self.assertEqual(str(s.output[i]), str(knownvalues[i]))
Beispiel #4
0
 def testOutputKnownValues(self):
     """Atr calculation should give known result with known input
        results are rounded by str representation of floats
     """
     s = Atr(4)
     knownvalues = [
         None, None, None, 12.24, 12.372, 12.3032, 12.26992, 12.225952
     ]
     for c in inputValues[:8]:
         s.append(c)
     for i in range(len(s.output)):
         self.assertEqual(str(s.output[i]), str(knownvalues[i]))
Beispiel #5
0
 def testTupleTooLarge(self):
     """append should fail with tuple that has a length bigger than 6"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), None, 12.56, 12.11, 12.20, 2010912, 1425)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #6
0
 def testNoneOpen(self):
     """append should fail with None value for open"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), None, 12.56, 12.11, 12.20, 2010912)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #7
0
 def testFloatVolume(self):
     """append should fail with float value for volume"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), 12.34, 12.56, 12.11, 12.20, 2010912.25)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #8
0
 def testFloat(self):
     """append should fail with float input"""
     s = Atr(4)
     self.assertRaises(NotTupleError, s.append, 12.432)
Beispiel #9
0
 def testString(self):
     """append should fail with string input"""
     s = Atr(4)
     self.assertRaises(NotTupleError, s.append, "dummy")
Beispiel #10
0
 def testInteger(self):
     """append should fail with integer input"""
     s = Atr(4)
     self.assertRaises(NotTupleError, s.append, 4000)
Beispiel #11
0
 def testCloseLowerThanLow(self):
     """append should fail with close lower than low"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), 12.60, 12.56, 12.11, 12.09, 2010912)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #12
0
 def testOpenHigherThanHigh(self):
     """append should fail with open higher than high"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), 12.60, 12.56, 12.11, 12.20, 2010912)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #13
0
 def testHighLowMixUp(self):
     """append should fail with high lower than low"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), 12.34, 12.11, 12.56, 12.20, 2010912)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #14
0
 def testNegativeLow(self):
     """append should fail with negative low value"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5,
                            19), 12.34, 12.56, -12.11, 12.20, 2010912)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #15
0
 def testIntegerDateTime(self):
     """append should fail with candle input that does not have a datetime as first element """
     s = Atr(4)
     c = (1562516271, 12.34, 12.56, 12.11, 12.20, 2010912)
     self.assertRaises(InvalidDateTimeError, s.append, c)
Beispiel #16
0
 def testTupleTooSmall(self):
     """append should fail with tuple that has a length smaller than 6"""
     s = Atr(4)
     c = (datetime.datetime(2006, 5, 19), None, 12.56, 12.11, 12.20)
     self.assertRaises(InvalidCandleStickError, s.append, c)
Beispiel #17
0
from ta.Atr import *
import datetime
import random

ind = Atr(12)

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 Atr indicator took %s seconds. %s candles per second." % (nrofticks, dfsec, nrofticks / dfsec)
Beispiel #18
0
from ta.Atr import *
import datetime
import random

ind = Atr(12)

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 Atr indicator took %s seconds. %s candles per second."
    % (nrofticks, dfsec, nrofticks / dfsec))