Beispiel #1
0
 def testAdditionOperation(self):
     res = api.parse('YHOO+GOOG')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 2)
     self.assertEqual(names[0], str(res.left))
     self.assertEqual(names[1], str(res.right))
Beispiel #2
0
 def testTwoTimeSeries(self):
     '''Get a timeseries and a function and check for consistency'''
     res = api.parse('gs:yahoo, min(gs:yahoo, window=30)')
     self.assertEqual(res.symbols(), ['GS:YAHOO'])
     self.assertEqual(len(res), 2)
     self.assertEqual(str(res[0]), 'GS:YAHOO')
     self.assertEqual(str(res[1]), 'min(GS:YAHOO, window=30)')
Beispiel #3
0
 def testAdditionOperation(self):
     res = api.parse('YHOO+GOOG')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 2)
     self.assertEqual(names[0], str(res.left))
     self.assertEqual(names[1], str(res.right))
Beispiel #4
0
 def testSpecialSymbol2(self):
     '''Symbol can be included by character'''
     res = api.parse('`EURSW6M2YR_2.2`')
     names = res.symbols()
     self.assertEqual(len(names), 1)
     self.assertEqual(str(res), '`EURSW6M2YR_2.2`')
     self.assertEqual(names[0], 'EURSW6M2YR_2.2')
Beispiel #5
0
 def testSpecialSymbol2(self):
     '''Symbol can be included by character'''
     res = api.parse('`EURSW6M2YR_2.2`')
     names = res.symbols()
     self.assertEqual(len(names), 1)
     self.assertEqual(str(res), '`EURSW6M2YR_2.2`')
     self.assertEqual(names[0], 'EURSW6M2YR_2.2')
Beispiel #6
0
 def testTwoTimeSeries(self):
     '''Get a timeseries and a function and check for consistency'''
     res = api.parse('gs:yahoo, min(gs:yahoo, window=30)')
     self.assertEqual(res.symbols(), ['GS:YAHOO'])
     self.assertEqual(len(res), 2)
     self.assertEqual(str(res[0]), 'GS:YAHOO')
     self.assertEqual(str(res[1]), 'min(GS:YAHOO, window=30)')
Beispiel #7
0
 def testSpecialSymbol(self):
     '''Symbol can be included by character'''
     res = api.parse('`FX-15`+amzn')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 2)
     self.assertEqual(names[0], 'FX-15')
     self.assertEqual(names[1], 'AMZN')
Beispiel #8
0
 def testSpecialSymbol(self):
     '''Symbol can be included by character'''
     res = api.parse('`FX-15`+amzn')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 2)
     self.assertEqual(names[0], 'FX-15')
     self.assertEqual(names[1], 'AMZN')
Beispiel #9
0
 def testOperationOrder(self):
     res = api.parse('2*GOOG+4*YHOO')
     self.assertEqual(len(res.children), 2)
     self.assertTrue(isinstance(res, ast.PlusOp))
     res1 = res.children[0]
     self.assertTrue(isinstance(res1, ast.MultiplyOp))
     res2 = res.children[1]
     self.assertTrue(isinstance(res2, ast.MultiplyOp))
Beispiel #10
0
 def testOperationOrder(self):
     res = api.parse('2*GOOG+4*YHOO')
     self.assertEqual(len(res.children), 2)
     self.assertTrue(isinstance(res, ast.PlusOp))
     res1 = res.children[0]
     self.assertTrue(isinstance(res1, ast.MultiplyOp))
     res2 = res.children[1]
     self.assertTrue(isinstance(res2, ast.MultiplyOp))
Beispiel #11
0
 def testDataProvider(self):
     result = api.evaluate('2*GOOG, GOOG')
     self.assertEqual(len(result.data), 1)
     self.assertEqual(result.expression, api.parse('2*GOOG, GOOG'))
     data = result.ts()
     self.assertTrue(api.is_timeseries(data))
     self.assertEqual(data.count(), 2)
     ts1 = data.serie(0)
     ts2 = data.serie(1)
     for v1, v2 in zip(ts1, ts2):
         self.assertAlmostEqual(v1, 2. * v2)
Beispiel #12
0
 def testDataProvider(self):
     result = api.evaluate('2*GOOG, GOOG')
     self.assertEqual(len(result.data), 1)
     self.assertEqual(result.expression, api.parse('2*GOOG, GOOG'))
     data = result.ts()
     self.assertTrue(api.is_timeseries(data))
     self.assertEqual(data.count(), 2)
     ts1 = data.serie(0)
     ts2 = data.serie(1)
     for v1, v2 in zip(ts1, ts2):
         self.assertAlmostEqual(v1, 2.*v2)
Beispiel #13
0
 def testBinOpSerieFunction(self):
     '''Get a timeseries and a function and check for consistency'''
     res = api.parse('goog:yahoo-ma(goog:yahoo, window=30)')
     self.assertEqual(res.symbols(), ['GOOG:YAHOO'])
     self.assertEqual(len(res), 2)
     self.assertEqual(str(res[0]), 'GOOG:YAHOO')
     self.assertEqual(str(res[1]), 'ma(GOOG:YAHOO, window=30)')
     result = api.evaluate(res)
     self.assertEqual(len(result.data), 1)
     data = result.ts()
     self.assertTrue(api.is_timeseries(data))
     self.assertEqual(data.count(), 1)
Beispiel #14
0
 def testBinOpSerieFunction(self):
     '''Get a timeseries and a function and check for consistency'''
     res = api.parse('goog:yahoo-ma(goog:yahoo, window=30)')
     self.assertEqual(res.symbols(), ['GOOG:YAHOO'])
     self.assertEqual(len(res), 2)
     self.assertEqual(str(res[0]), 'GOOG:YAHOO')
     self.assertEqual(str(res[1]), 'ma(GOOG:YAHOO, window=30)')
     result = api.evaluate(res)
     self.assertEqual(len(result.data), 1)
     data = result.ts()
     self.assertTrue(api.is_timeseries(data))
     self.assertEqual(data.count(), 1)
Beispiel #15
0
 def testName(self):
     for name in self.names:
         res = api.parse(name)
         self.assertTrue(isinstance(res, ast.Symbol))
         self.assertEqual(name.upper(), str(res))
Beispiel #16
0
 def testTimesMinus(self):
     result = api.parse('EUR*-3')
     self.assertEqual(result.symbols(), ['EUR'])
     self.assertEqual(len(result), 2)
     self.assertEqual(str(result[0]), 'EUR')
     self.assertEqual(str(result[1]), '-3')
Beispiel #17
0
 def testSyntaxError2(self):
     '''Symbol can be included by character'''
     res = api.parse('yahoo, delta(goog')
     self.assertTrue(res.malformed())
Beispiel #18
0
 def testBinaryOperation(self):
     res = api.parse('2*GOOG')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 1)
     self.assertEqual(names[0], str(res.right))
Beispiel #19
0
 def testQuote(self):
     res = api.parse('"FX-15"+amzn')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 1)
     self.assertEqual(names[0], str(res.right))
Beispiel #20
0
 def testQuote(self):
     res = api.parse('"FX-15"+amzn')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 1)
     self.assertEqual(names[0], str(res.right))
Beispiel #21
0
 def testSyntaxError2(self):
     '''Symbol can be included by character'''
     res = api.parse('yahoo, delta(goog')
     self.assertTrue(res.malformed())
Beispiel #22
0
 def testName(self):
     for name in self.names:
         res = api.parse(name)
         self.assertTrue(isinstance(res, ast.Symbol))
         self.assertEqual(name.upper(), str(res))
Beispiel #23
0
 def testBinaryOperation(self):
     res = api.parse('2*GOOG')
     self.assertEqual(len(res.children), 2)
     names = res.symbols()
     self.assertEqual(len(names), 1)
     self.assertEqual(names[0], str(res.right))
Beispiel #24
0
 def testTimesMinus(self):
     result = api.parse('EUR*-3')
     self.assertEqual(result.symbols(), ['EUR'])
     self.assertEqual(len(result), 2)
     self.assertEqual(str(result[0]), 'EUR')
     self.assertEqual(str(result[1]), '-3')
Beispiel #25
0
 def testQuotedLinearSuperimposition(self):
     res = api.parse("4*`eur:rm@bla`-8*`abc:56`+4*`a-b-c:-20`")
     self.assertEqual(len(res), 2)
Beispiel #26
0
 def testQuotedLinearSuperimposition(self):
     res = api.parse("4*`eur:rm@bla`-8*`abc:56`+4*`a-b-c:-20`")
     self.assertEqual(len(res), 2)