def prep_bar_feed(self): for sym in self._symbols: feed = self._barFeed.get_feed(sym) feed.insert( talibfunc.SMA('short_ma', feed, self._parms['shortPeriod'])) feed.insert( talibfunc.SMA('long_ma', feed, self._parms['longPeriod']))
def prep_bar_feed(self): period = self._parms['period'] for sym in self._symbols: feed = self._barFeed.get_feed(sym) feed.insert(talibfunc.SMA('short_ma', feed, period)) feed.insert(talibfunc.SMA('long_ma', feed, 2 * period)) feed.insert(talibfunc.MAX('max', feed, period)) feed.insert(talibfunc.MIN('min', feed, period))
def prep_bar_feed(self): for sym in self._symbols: feed = self._barFeed.get_feed(sym) feed.insert( talibfunc.SMA('filter_ma', feed, self._parms['filterPeriod'])) feed.insert( talibfunc.SMA('close_ma', feed, self._parms['close_ma_period'])) feed.insert(talibfunc.RSI('rsi', feed, self._parms['rsi_period']))
def setUp(self): manifest = '%s/data/manifest1.csv' % os.path.dirname(__file__) self._db = InstrumentDb.Instance() self._db.load(manifest) self._feed = Feed(self._db.get('AC')) self._feed.insert(talibfunc.SMA('SMA50', self._feed, 50)) self._feed.insert(talibfunc.SMA('SMA100', self._feed, 100)) self._feed.insert(talibfunc.MAX('MAX50', self._feed, 50)) self._feed.insert(talibfunc.MIN('MIN50', self._feed, 50)) self._feed.insert(talibfunc.ATR('ATR10', self._feed, 10))
def prep_bar_feed(self): for sym in self._symbols: feed = self._barFeed.get_feed(sym) feed.insert( talibfunc.SMA('filter_ma', feed, self._parms['filterPeriod'])) feed.insert(talibfunc.MAX('max', feed, self._parms['period'])) feed.insert(talibfunc.MIN('min', feed, self._parms['period']))
def prep_bar_feed(self): for sym in self._symbols: feed = self._barFeed.get_feed(sym) feed.insert( talibfunc.SMA('filter_ma', feed, self._parms['filterPeriod'])) feed.insert(talibfunc.RSI('rsi', feed, self._parms['rsi_period'])) feed.insert( CUM(name='cum_rsi', period=self._parms['rsi_cum_length'], baseIndicator='rsi'))
def testCum(self): w = Feed(self._inst) w.insert(talibfunc.SMA('SMA50', w, 50)) w.insert(CUM(name='cum2(SMA50)', period=2, baseIndicator='SMA50')) # just going to spot check a few values randomly (but hard-coded) # we know that the base indicator is NAN up through at least 50 cum = w.get_series('cum2(SMA50)') base = w.get_series('SMA50') self.assertAlmostEqual(cum[79], base[79] + base[78], places=4) self.assertAlmostEqual(cum[112], base[112] + base[111], places=4) self.assertAlmostEqual(cum[176], base[176] + base[175], places=4)
def testBasic(self): w = Feed(self._inst) w.insert(ATR()) w.insert(talibfunc.SMA('SMA10', w, 10)) self.assertEqual(len(w.values()), 8) self.assertEqual(len(w.values()[0]), 252) self.assertEqual(w.values()[0][251], datetime.datetime(2013, 1, 18, 0, 0)) self.assertTrue(math.isnan(w.get_series('ATR')[5])) self.assertTrue(math.isnan(w.get_series('ATR')[98])) self.assertAlmostEqual(w.get_series('ATR')[99], 0.03493, places=5) self.assertAlmostEqual(w.get_series('ATR')[251], 0.03307, places=5) self.assertAlmostEqual(w.get_series('SMA10')[251], 2.2921) self.assertAlmostEqual(w.get_series('SMA10')[188], 2.3989)
def testPriceVelocity(self): w = Feed(self._inst) w.insert(talibfunc.SMA('SMA50', w, 50)) w.insert(PriceVelocity('PVEL', period=10, baseIndicator='SMA50')) self.assertEqual(len(w.values()), 8) self.assertEqual(len(w.values()[0]), 252) self.assertAlmostEqual(w.get_series('PVEL')[251], -0.001576, places=4) feedout = '%s/writefeed.csv' % os.path.dirname(__file__) wf = open(feedout, 'w') w.write_csv(wf) wf.close() self.assertTrue( test_util.file_compare( '%s/writefeed.refcsv' % os.path.dirname(__file__), feedout)) os.remove(feedout)