def testCustomLoader(self): from dynts.conf import settings settings.default_loader = CustomLoader dynts.evaluate('BLT:google').unwind() data = CustomLoader.data self.assertTrue(data) self.assertTrue('BLT:GOOGLE' in data)
def get_analysis(code = None, start = None, end = None, format = None, **kwargs): '''Econometric analysis''' res = dynts.evaluate(code, start = start, end = end) if format: return res.dump(format = format) else: return res
def get_analysis(code=None, start=None, end=None, format=None, **kwargs): '''Econometric analysis''' res = dynts.evaluate(code, start=start, end=end) if format: return res.dump(format=format) else: return res
def testVbaJson(self): ts = dynts.evaluate('AMZN, AAPL').dump('jsonvba') self.assertTrue(isinstance(ts, list)) head = ts[0] self.assertEqual(['Date', 'AMZN', 'AAPL'], head) for row in ts[1:]: self.assertTrue(isinstance(row[0], int)) self.assertEqual(len(row), 3)
def testVbaJson(self): ts = dynts.evaluate("AMZN,AAPL").dump("jsonvba") self.assertTrue(isinstance(ts, list)) head = ts[0] self.assertEqual(["Date", "AMZN", "AAPL"], head) for row in ts[1:]: self.assertTrue(isinstance(row[0], int)) self.assertEqual(len(row), 3)
def testVbaJson(self): ts = dynts.evaluate('AMZN,AAPL').dump('jsonvba') self.assertTrue(isinstance(ts,list)) head = ts[0] self.assertEqual(['Date','AMZN','AAPL'],head) for row in ts[1:]: self.assertTrue(isinstance(row[0],int)) self.assertEqual(len(row),3)
def testNoParameters(self): '''Test mean function with zero parameters''' expression = '%s(GOOG)' % self.function result = dynts.evaluate(expression) self.assertEqual(str(result),expression) self.assertEqual(len(result.data),1) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(),1)
def testFlot1(self): ts = dynts.evaluate('YHOO,GOOG').dump('flot') dts = ts.todict() self.assertEqual(dts['type'],'multiplot') self.assertEqual(len(dts['plots']),1) plot = dts['plots'][0] self.assertEqual(plot['type'],'timeseries') self.assertEqual(len(plot['series']),2) data = json.dumps(dts)
def testScatter(self): ts = dynts.evaluate('scatter(YHOO, GOOG)').dump('flot') dts = ts.todict() self.assertEqual(dts['type'], 'multiplot') self.assertEqual(len(dts['plots']), 1) plot = dts['plots'][0] self.assertEqual(plot['type'], 'xy') self.assertEqual(len(plot['series']), 1) serie = plot['series'][0]
def testTwoSeries(self): e = '%s(GOOG,YHOO)' % self.function result = dynts.evaluate(e) symbols = result.expression.symbols() self.assertEqual(len(symbols), 2) self.assertEqual(len(result.data), 2) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(), 2)
def testNoParameters(self): '''Test mean function with zero parameters''' expression = '%s(GOOG)' % self.function result = dynts.evaluate(expression) self.assertEqual(str(result), expression) self.assertEqual(len(result.data), 1) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(), 1)
def testTwoSeries(self): e = '%s(GOOG, YHOO)' % self.function result = dynts.evaluate(e) symbols = result.expression.symbols() self.assertEqual(len(symbols), 2) self.assertEqual(len(result.data), 2) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(), 2)
def testFlot1(self): ts = dynts.evaluate("YHOO,GOOG").dump("flot") dts = ts.todict() self.assertEqual(dts["type"], "multiplot") self.assertEqual(len(dts["plots"]), 1) plot = dts["plots"][0] self.assertEqual(plot["type"], "timeseries") self.assertEqual(len(plot["series"]), 2) data = json.dumps(dts)
def testFlot1(self): ts = dynts.evaluate('YHOO, GOOG').dump('flot') dts = ts.todict() self.assertEqual(dts['type'], 'multiplot') self.assertEqual(len(dts['plots']), 1) plot = dts['plots'][0] self.assertEqual(plot['type'], 'timeseries') self.assertEqual(len(plot['series']), 2) data = json.dumps(dts)
def testScatter(self): ts = dynts.evaluate('scatter(YHOO,GOOG)').dump('flot') dts = ts.todict() self.assertEqual(dts['type'],'multiplot') self.assertEqual(len(dts['plots']),1) plot = dts['plots'][0] self.assertEqual(plot['type'],'scatter') self.assertEqual(len(plot['series']),1) serie = plot['series'][0]
def testScatter(self): ts = dynts.evaluate("scatter(YHOO,GOOG)").dump("flot") dts = ts.todict() self.assertEqual(dts["type"], "multiplot") self.assertEqual(len(dts["plots"]), 1) plot = dts["plots"][0] self.assertEqual(plot["type"], "xy") self.assertEqual(len(plot["series"]), 1) serie = plot["series"][0]
def testWindowParameter(self): '''Test mean function with one parameter''' e = '%(f)s(GOOG,window=30),%(f)s(GOOG,window=60)' % {'f':self.function} result = dynts.evaluate(e) symbols = result.expression.symbols() self.assertEqual(len(symbols),1) self.assertEqual(len(result.data),1) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(),2)
def testDataProvider(self): result = dynts.evaluate('2*GOOG,GOOG') self.assertEqual(len(result.data),1) self.assertEqual(result.expression,dynts.parse('2*GOOG,GOOG')) data = result.ts() self.assertTrue(dynts.istimeseries(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)
def testDataProvider(self): result = dynts.evaluate('2*GOOG, GOOG') self.assertEqual(len(result.data), 1) self.assertEqual(result.expression, dynts.parse('2*GOOG, GOOG')) data = result.ts() self.assertTrue(dynts.istimeseries(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)
def testBinOpSerieFunction(self): '''Get a timeseries and a function and check for consistency''' res = dynts.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 = dynts.evaluate(res) self.assertEqual(len(result.data),1) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(),1)
def testBinOpSerieFunction(self): '''Get a timeseries and a function and check for consistency''' res = dynts.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 = dynts.evaluate(res) self.assertEqual(len(result.data), 1) data = result.ts() self.assertTrue(dynts.istimeseries(data)) self.assertEqual(data.count(), 1)
def testWindowParameter(self): '''Test mean function with one parameter''' e = '%(f)s(GOOG,window=30),%(f)s(GOOG,window=60)' % {'f':self.function} result = dynts.evaluate(e) symbols = result.expression.symbols() self.assertEqual(len(symbols),1) self.assertEqual(len(result.data),1) ts = result.ts() self.assertTrue(dynts.istimeseries(ts)) self.assertEqual(ts.count(),2) back = ts[-1] self.assertEqual(len(back),2) self.assertEqual(back[0],back[0]) self.assertEqual(back[-1],back[-1])
def testWindowParameter(self): '''Test mean function with one parameter''' e = ('%(f)s(GOOG, window=30), %(f)s(GOOG, window=60)' % { 'f': self.function }) result = dynts.evaluate(e) symbols = result.expression.symbols() self.assertEqual(len(symbols), 1) self.assertEqual(len(result.data), 1) ts = result.ts() self.assertTrue(dynts.istimeseries(ts)) self.assertEqual(ts.count(), 2) back = ts[-1] self.assertEqual(len(back), 2) self.assertEqual(back[0], back[0]) self.assertEqual(back[-1], back[-1])
def testTSName(self): ''' The dslresult should include an attribute 'name' which is the equivalent to the expression passed. In situations where multiple timeseries are returned the name should be the concatenation of all the names joined by "__". ''' expressions = ['GOOG+YHOO', '2*GOOG', 'GOOG,YHOO', ] for expr in expressions: result = dynts.evaluate(expr) ts = result.ts() name = ts.name expected_name = '__'.join(expr.split(',')) self.assertEqual(name, expected_name)
def getdata(self, request, expression, start, end, **kwargs): res = dynts.evaluate(expression, start=start, end=end) return res.dump('flot')
def getdata(self, request, expression, start, end, **kwargs): res = dynts.evaluate(expression, start = start, end = end) return res.dump('flot')
def testyahoo(self): ts = dynts.evaluate('GOOG:yahoo') self.assertTrue(ts)