def __init__(self, feed, brk, instrument, vwapWindowSize, buyThreshold, sellThreshold): super(VWAPMomentum, self).__init__(feed, brk) self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize) self.__buyThreshold = buyThreshold self.__sellThreshold = sellThreshold
def testPeriod1_TypicalPrice(self): barFeed = self.__getFeed() bars = barFeed[INSTRUMENT] vwap_ = vwap.VWAP(bars, 1, True) barFeed.loadAll() for i in xrange(len(bars)): self.assertEqual(round(bars[i].getTypicalPrice(), 5), round(vwap_[i], 5))
def testPeriod1_ClosingPrice(self): barFeed = self.__getFeed() bars = barFeed[VWAPTestCase.Instrument] vwap_ = vwap.VWAP(bars, 1) barFeed.loadAll() for i in range(len(bars)): self.assertEqual(round(bars[i].getClose(), 5), round(vwap_[i], 5))
def __init__(self, feed, brk, instrument, vwapWindowSize, buyThreshold, sellThreshold): strategy.BacktestingStrategy.__init__(self, feed, brk) self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize) self.__buyThreshold = buyThreshold self.__sellThreshold = sellThreshold
def __init__(self, feed, brk, instrument, vwapWindowSize, buyThreshold, sellThreshold): super(VWAPMomentum, self).__init__(feed, brk=brk) self.__vwap = vwap.VWAP(feed.getDataSeries(instrument), vwapWindowSize) self.__buyThreshold = buyThreshold self.__sellThreshold = sellThreshold self.__instrument = instrument self.__symbol, self.__priceCurrency = instrument.split("/")
def testPeriod2_TypicalPrice(self): barFeed = self.__getFeed() bars = barFeed[INSTRUMENT] vwap_ = vwap.VWAP(bars, 2, True) barFeed.loadAll() self.assertEqual(vwap_[0], None) for i in xrange(1, len(vwap_)): self.assertNotEqual(vwap_[i], None)
def testPeriod2_TypicalPrice(self): barFeed = self.__getFeed() bars = barFeed[VWAPTestCase.Instrument] vwap_ = vwap.VWAP(bars, 2, True) barFeed.loadAll() self.assertEqual(vwap_[0], None) for i in range(1, len(vwap_)): self.assertNotEqual(vwap_[i], None)
def testPeriod50_ClosingPrice(self): barFeed = self.__getFeed() bars = barFeed[INSTRUMENT] vwap_ = vwap.VWAP(bars, 50) barFeed.loadAll() for i in xrange(49): self.assertEqual(vwap_[i], None) for i in xrange(49, len(vwap_)): self.assertNotEqual(vwap_[i], None)
def testPeriod50_ClosingPrice(self): barFeed = self.__getFeed() bars = barFeed[VWAPTestCase.Instrument] vwap_ = vwap.VWAP(bars, 50) barFeed.loadAll() for i in range(49): self.assertEqual(vwap_[i], None) for i in range(49, len(vwap_)): self.assertNotEqual(vwap_[i], None)
def testBounded(self): barFeed = self.__getFeed() bars = barFeed[VWAPTestCase.Instrument] vwap_ = vwap.VWAP(bars, 50, True, 2) barFeed.loadAll() outputValues = [14.605005665747331, 14.605416923506045] for i in range(2): self.assertEqual(round(vwap_[i], 4), round(outputValues[i], 4))
def __init__(self, feed, instrument, vwapWindowSize, threshold): super(PivotPointMomentum, self).__init__(feed) self._instrument = instrument self._vwap = vwap.VWAP(feed[instrument], vwapWindowSize) self._pp = pivotpoints.PivotPointsSequenceBased( feed[instrument], vwapWindowSize, 1, pivotpoints.PivotPointsPeriod.daily) self._pp_e = pivotpoints.PivotPointsEventBased( feed[instrument], vwapWindowSize, 1, pivotpoints.PivotPointsPeriod.daily) self._threshold = threshold self.getBroker().getFillStrategy().setVolumeLimit(None)
def __init__(self, feed, instrument, vwapWindowSize, threshold): strategy.BacktestingStrategy.__init__(self, feed) self.__instrument = instrument self.__feed = feed self.__threshold = threshold self.__vwap ={} for element in instrument: self.__vwap[element] = vwap.VWAP(feed[element], vwapWindowSize) self.__notional = 0 self.__count = 0 self.__info = DataFrame(columns={'date','id','action','instrument','quantity','price'}) #交易记录信息 self.__info_matrix = []
def __init__(self, feed, instrument, parametres, cash=10, comission=0.002): broker = backtesting.Broker(cash, feed, backtesting.TradePercentage(comission)) strategy.BaseStrategy.__init__(self, feed, broker) self.numOrder = 0 self.okOrder = 0 self.exitOrder = 0 self.s1 = self.s2 = self.s3 = 1 self.p1 = self.p2 = self.p3 = 1 self.windowTrust = parametres[3] # SMA self.__instrument = instrument self.__position = None self.__Close = feed[instrument].getCloseDataSeries() self.__sma = ma.SMA(self.__Close, parametres[0]) # Bbands self.__instrument = instrument self.__bbands = bollinger.BollingerBands(feed[instrument].getCloseDataSeries(), parametres[1], 2) # Vwap self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], parametres[2])
def __init__(self, feed, instrument, vwapWindowSize, threshold): strategy.BacktestingStrategy.__init__(self, feed) self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize) self.__threshold = threshold
def __init__(self, feed, instrument, vwapWindowSize, threshold): super().__init__(feed) self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize) self.__threshold = threshold self.__position = None
def __init__(self, feed, instrument, initialBalance, vwapWindowSize, threshold): super(VWAPMomentum, self).__init__(feed, balances=initialBalance) self.__instrument = instrument self.__vwap = vwap.VWAP(feed.getDataSeries(instrument), vwapWindowSize) self.__threshold = threshold
def __init__(self, feed, instrument, vwapWindowSize, threshold): super(VWAPMomentum, self).__init__(feed) self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize) self.__threshold = threshold
def __init__(self, feed, instrument, vwapWindowSize, cash=10, comission=0.002): broker = backtesting.Broker(cash, feed, backtesting.TradePercentage(comission)) strategy.BaseStrategy.__init__(self, feed, broker) self.__instrument = instrument self.__vwap = vwap.VWAP(feed[instrument], vwapWindowSize)