Exemple #1
0
	def __init__(self, feed, smaPeriod):
		strategy.Strategy.__init__(self, feed)

		assert(smaPeriod > 3)
		self.__lead = "nikkei"
		self.__lag = "spy"
		# Exit signal is more sensitive than entry.
		adjClose = feed.getDataSeries(self.__lead).getAdjCloseDataSeries()
		self.__crossAbove = cross.CrossAbove(adjClose, ma.SMA(adjClose, smaPeriod))
		self.__crossBelow = cross.CrossAbove(adjClose, ma.SMA(adjClose, int(smaPeriod/2)))
		self.__pos = None
Exemple #2
0
 def __init__(self, feed, smaPeriod):
     strategy.Strategy.__init__(self, feed, 1000)
     closeDS = feed.getDataSeries("orcl").getCloseDataSeries()
     self.__sma = ma.SMA(closeDS, smaPeriod)
     self.__crossAbove = cross.CrossAbove(closeDS, self.__sma)
     self.__crossBelow = cross.CrossBelow(closeDS, self.__sma)
     self.__position = None
Exemple #3
0
    def __init__(self, feed, tickers, period=9, balance=15000, limit=10):
        basestrategies.BaseTrender.__init__(self, feed, period, tickers,
                                            balance, mongofeed.MongoRowParser)
        self.cross_aboves = {}
        self.cross_belows = {}
        self.current_positions = set()
        self.pos_limit = limit
        params = {
            'timeperiod': period,
            'nbdevup': 2,
            'nbdevdn': 2,
            'matype': du.tl.MA_SMA
        }

        for ticker in self.tickers:
            print 'Initializing: %s' % (ticker)
            data = du.get_data(ticker)
            d = [v['Adj Clos'] for v in data]
            a, b, c = du.run_command('BBANDS', np.array(d), **params)

            highs = dataseries.SequenceDataSeries([d for d in a.tolist()])
            lows = dataseries.SequenceDataSeries([d for d in c.tolist()])
            mids = dataseries.SequenceDataSeries([d for d in b.tolist()])

            self.cross_aboves[ticker] = cross.CrossAbove(
                feed.getDataSeries(ticker).getAdjCloseDataSeries(), highs)
            self.cross_belows[ticker] = cross.CrossBelow(
                feed.getDataSeries(ticker).getAdjCloseDataSeries(), lows)
Exemple #4
0
 def __init__(self, feed, instrument, smaPeriod, cash=1000):
     strategy.Strategy.__init__(self, feed, cash)
     closeDS = feed[instrument].getCloseDataSeries()
     self.__sma = ma.SMA(closeDS, smaPeriod)
     self.__instrument = instrument
     self.__crossAbove = cross.CrossAbove(closeDS, self.__sma)
     self.__crossBelow = cross.CrossBelow(closeDS, self.__sma)
     self.__position = None
 def __init__(self, feed, fastSMA, slowSMA):
     strategy.Strategy.__init__(self, feed, 1000)
     ds = feed.getDataSeries("orcl").getCloseDataSeries()
     fastSMADS = ma.SMA(ds, fastSMA)
     slowSMADS = ma.SMA(ds, slowSMA)
     self.__crossAbove = cross.CrossAbove(fastSMADS, slowSMADS)
     self.__crossBelow = cross.CrossBelow(fastSMADS, slowSMADS)
     self.__longPos = None
     self.__shortPos = None
     self.__finalValue = None
Exemple #6
0
    def __init__(self, feed, smaPeriod, f, tick1, tick2):
        strategy.Strategy.__init__(self, f, 2000)
        self.__position = {}
        self.__tick1 = tick1
        self.__tick2 = tick2
        self.pdata = feed.getDataSeries(tick1).getCloseDataSeries()
        self.result = None
        self.last_price = {}
        self.last_price.setdefault(tick1, None)
        self.last_price.setdefault(tick2, None)

        def get_ratio(bar):
            return bar.ratio

        self.ratios = f.getDataSeries('%s/%s' % (tick1, tick2))
        self.ratios = dataseries.BarValueDataSeries(
            f.getDataSeries('%s/%s' % (tick1, tick2)), get_ratio)
        self.ratio_series = du.RatioDataSeries(tick1, tick2, 'Adj Clos')
        a, b, c = du.run_command(
            'BBANDS', np.array(self.ratio_series.d), **{
                'timeperiod': smaPeriod,
                'nbdevup': 2,
                'nbdevdn': 2,
                'matype': du.tl.MA_SMA
            })
        self.highs = dataseries.SequenceDataSeries([d for d in a.tolist()])
        #print [d for d in a.tolist()]
        self.mids = dataseries.SequenceDataSeries([d for d in b.tolist()])
        self.lows = dataseries.SequenceDataSeries([d for d in c.tolist()])
        """
        self.highs = du.ArbitraryDataSeries('Upper BBand', a.tolist())
        self.mids = du.ArbitraryDataSeries('Mean', b.tolist())
        self.lows = du.ArbitraryDataSeries('Lower BBand', c.tolist()) 
        """
        self.cross_below = cross.CrossBelow(self.ratios, self.lows)
        self.cross_above = cross.CrossAbove(self.ratios, self.highs)
        self.cautious_cross_below = cross.CrossBelow(self.ratios, self.highs)
        self.cautious_cross_above = cross.CrossAbove(self.ratios, self.highs)
        self.price_slope = trend.Slope(self.ratios, 60)
        self.last_slope = 0
Exemple #7
0
 def testWithSMAs(self):
     ds1 = dataseries.SequenceDataSeries()
     ds2 = dataseries.SequenceDataSeries()
     crs = cross.CrossAbove(ma.SMA(ds1, 15), ma.SMA(ds2, 25), 2)
     for i in range(100):
         ds1.appendValue(i)
         ds2.appendValue(50)
         if i < 24:
             self.assertTrue(crs.getValue() == None)
         elif i == 58:
             self.assertTrue(crs.getValue() == 1)
         else:
             self.assertTrue(crs.getValue() == 0)