当前位置: 首页>>代码示例>>Python>>正文


Python cross.cross_below函数代码示例

本文整理汇总了Python中pyalgotrade.technical.cross.cross_below函数的典型用法代码示例。如果您正苦于以下问题:Python cross_below函数的具体用法?Python cross_below怎么用?Python cross_below使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cross_below函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onBars

 def onBars(self, bars):
     if self.__position != None and self.__position.getReturn() < -0.05:
         self.__position.exitMarket()
         
     # If a position was not opened, check if we should enter a long position.
     if self.__position is None:
         ds = self.getFeed().getDataSeries(self.__instrument).getCloseDataSeries()
         if self.touchBottom(): # and LINEARREG(ds, 20)[1] > 0:
             shares = int(self.getBroker().getCash() * 0.9 / bars[self.__instrument].getPrice())
             # Enter a buy market order. The order is good till canceled.
             self.__position = self.enterShort(self.__instrument, shares, True)
             self.__pos_kind = "Short"
             print str(bars[self.__instrument].getDateTime()) + " " + "buy Short"
         elif self.touchTop(): # and LINEARREG(ds, 20)[1] < 0:
             shares = int(self.getBroker().getCash() * 0.9 / bars[self.__instrument].getPrice())
             # Enter a buy market order. The order is good till canceled.
             self.__position = self.enterLong(self.__instrument, shares, True)
             self.__pos_kind = "Long"
             print str(bars[self.__instrument].getDateTime()) + " " + "buy Long"
         return
     # Check if we have to exit the position.
     elif (not self.__position.exitActive()):
         if self.__pos_kind == "Long" and (cross.cross_below(self.__prices, self.__sma, -2) > 0 or self.touchBottom()):
             self.__position.exitMarket() #Long exit
             print str(bars[self.__instrument].getDateTime()) + " " + "exit " + self.__pos_kind
         elif self.__pos_kind == "Short" and (cross.cross_above(self.__prices, self.__sma, -2) > 0 or self.touchTop()):
             self.__position.exitMarket() #Short exit
             print str(bars[self.__instrument].getDateTime()) + " " + "exit " + self.__pos_kind
开发者ID:dongdong2233,项目名称:fx_systrade,代码行数:28,代码来源:pyalgo_fx_orig.py

示例2: onBars

    def onBars(self, bars):
        for instrument, bar in bars.items():
            infoout = None
            if cross.cross_below(self.__shorttrix[instrument],
                                 self.__longtrix[instrument]) > 0:
                # If the derivative crosses above zero (deriv - -> +),
                # buy the instrument.
                now_cash, now_shares = self.inventory(instrument)
                buyqty = self.buyamount(
                    instrument, bar.getClose(), bar.getVolume(), now_cash, .2)
                self.marketOrder(instrument, buyqty)
                infoout = 'Order %d shares of %s @$%.2f. COH $%.2f' % (
                    buyqty, instrument, bar.getClose(), now_cash)

            elif cross.cross_above(self.__shorttrix[instrument],
                                   self.__longtrix[instrument]) > 0:
                # If the derivative crosses below zero (deriv + -> -),
                # sell the instrument.
                now_cash, now_shares = self.inventory(instrument)
                if now_shares > 0:
                    # Sell all shares
                    self.marketOrder(instrument, -now_shares)
                    infoout = 'Sell %d shares of %s @$%.2f. COH $%.2f' % (
                        now_shares, instrument, bar.getClose(), now_cash)
            if infoout and self.printinfo:
                self.info(infoout)
开发者ID:RyanEggert,项目名称:financial-signal-processing,代码行数:26,代码来源:strategies.py

示例3: onBars

	def onBars(self, bars):
		if bars.getBar(self.__lead):
			if cross.cross_above(self.__adjClose, self.__slowSMA) == 1 and self.__pos == None:
				shares = self.__calculatePosSize()
				if shares:
					self.__pos = self.enterLong(self.__lag, shares)
			elif cross.cross_below(self.__adjClose, self.__fastSMA) == 1 and self.__pos != None:
				self.exitPosition(self.__pos)
开发者ID:charnugagoo,项目名称:pyalgotrade,代码行数:8,代码来源:multi_instrument_strategy_test.py

示例4: onBars

	def onBars(self, bars):
		if self.__position is None:
			if cross.cross_above(self.__prices, self.__sma) >0:
				shares = int(self.getBroker().getCash() * 0.9 / bars[self.__instrument].getPrice())
				self.__position = self.enterLong(self.__instrument, shares, True)
		
		elif not self.__position.exitActive() and cross.cross_below(self.__prices,self.__sma) >0:
			self.__position.exitMarket()
开发者ID:sv112,项目名称:pyAlgoTrade,代码行数:8,代码来源:sma_crossover.py

示例5: onBars

 def onBars(self, bars):
     # If a position was not opened, check if we should enter a long position.
     if self.__position == None:
         if cross.cross_above(self.__adjClose, self.__sma) > 0:
             # Enter a buy market order for 10 shares. The order is good till canceled.
             self.__position = self.enterLong(self.__instrument, 10, True)
     # Check if we have to exit the position.
     elif cross.cross_below(self.__adjClose, self.__sma) > 0:
         self.__position.exit()
开发者ID:greatGregLiu,项目名称:pytrade,代码行数:9,代码来源:smacross_strategy.py

示例6: onBars

 def onBars(self, bars):
     # If a position was not opened, check if we should enter a long position.
     if self.__position is None:
         if cross.cross_above(self.__prices, self.__sma) > 0:
             shares = int(self.getBroker().getCash() * 0.9 / bars[self.__instrument].getPrice())
             # Enter a buy market order. The order is good till canceled.
             self.__position = self.enterLong(self.__instrument, shares, True)
     # Check if we have to exit the position.
     elif not self.__position.exitActive() and cross.cross_below(self.__prices, self.__exit_sma) > 0:
         self.__position.exitMarket()
开发者ID:luosz,项目名称:quant,代码行数:10,代码来源:my_sma_crossover.py

示例7: enterShortSignal

 def enterShortSignal(self) :
     if self.__UpperBand[-1-self.__circ] is None:
         return False
     m1 = 0
     for i in range(self.__circ):
         if self.__macd[-i-1] >= self.__UpperBand[-i-2]:
             m1 += 1
     if m1 >= self.__circ-1 and cross.cross_below(self.__macd,self.__UpperBand)>0:
         return True
     else:
         return False
开发者ID:llmofang,项目名称:backtest,代码行数:11,代码来源:bitcoinbacktest.py

示例8: handle_data

 def handle_data(self,bars):
     for instrument in bars.getInstruments():
         # If a position was not opened, check if we should enter a long position.
         if self.__position[instrument] is None:
             if cross.cross_above(self.__prices[instrument], self.__sma[instrument]) > 0:
                 shares = int(self.getBroker().getCash() * 0.9 / bars[instrument].getPrice())
                 # Enter a buy market order. The order is good till canceled.
                 self.__position[instrument] = self.enterLong(instrument, shares, True)
         # Check if we have to exit the position.
         elif not self.__position[instrument].exitActive() and cross.cross_below(self.__prices[instrument], self.__sma[instrument]) > 0:
             self.__position[instrument].exitMarket()
开发者ID:hezhenke,项目名称:AshareBackTest,代码行数:11,代码来源:testPosition.py

示例9: exitLongSignal

 def exitLongSignal(self) :
     if self.__UpperBand[-1-self.__circ] is None:
         return False
     m1 = 0
     for i in range(self.__circ):
         if self.__close[-i-1] >= self.__UpperBand[-i-2]:
             m1 += 1
     if m1 >= self.__circ-1 and cross.cross_below(self.__close,self.__UpperBand)>0:
         return True
     else:
         return False
开发者ID:llmofang,项目名称:backtest,代码行数:11,代码来源:bollinger_band.py

示例10: testCrossBelowMany

    def testCrossBelowMany(self):
        count = 100
        values1 = [0 for i in range(count)]
        values2 = [-1 if i % 2 == 0 else 1 for i in range(count)]

        # Check first value
        self.assertEqual(cross.cross_below(values1, values2, 0, 0), 0)

        # Check every 2 values.
        period = 2
        for i in range(1, count):
            if i % 2 == 0:
                self.assertEqual(cross.cross_below(values1, values2, i - period + 1, i + 1), 0)
            else:
                self.assertEqual(cross.cross_below(values1, values2, i - period + 1, i + 1), 1)

        # Check every 4 values.
        period = 4
        for i in range(3, count):
            if i % 2 == 0:
                self.assertEqual(cross.cross_below(values1, values2, i - period + 1, i + 1), 1)
            else:
                self.assertEqual(cross.cross_below(values1, values2, i - period + 1, i + 1), 2)

        # Check for all values.
        self.assertEqual(cross.cross_below(values1, values2, 0, count), count / 2)
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:26,代码来源:technical_cross_test.py

示例11: sellSignal

 def sellSignal(self, bars):
     #         a> 价格下穿20日均线 并且 价格<SMA价格的97%
     #         b> 亏损超10%
     #         c> RSI>80
     #         c> 价格小于买入后最高价的90%
     if self.__buy_pos is None or self.__sell_pos is None:
         high_period = 0
     else:
         high_period = self.__buy_pos - self.__sell_pos
     return (cross.cross_below(self.__prices, self.__sma20) and self.__prices[-1] < self.__sma[-1] * 0.97) \
            or (self.__last_buy * 0.9 > self.getResult()) \
            or (self.__rsi > 80) \
            or (self.__prices < highlow.High(self.__prices, high_period) * 0.9)
开发者ID:leowll,项目名称:pyaltradeSample,代码行数:13,代码来源:sma_rsi.py

示例12: onBars

 def onBars(self, bars):        
     if self.__position is None:            
         if cross.cross_above(self.__Close, self.__sma) > 0:
             self.buyPrice = bars.getBar("btc").getClose()
             
             quantity = self.getBroker().getCash() / bars.getBar("btc").getClose() * 0.99
             self.__position = self.enterLong(self.__instrument, quantity)
             
             self.numOrder += 1
     elif cross.cross_below(self.__Close, self.__sma) > 0:
         # if (abs(self.buyPrice - bars.getBar("btc").getClose()) > 0.002 * (bars.getBar("btc").getClose())):
         if (abs(self.buyPrice - bars.getBar("btc").getClose()) > 10):            
             self.__position.exitMarket()
开发者ID:deamoon,项目名称:meteopt,代码行数:13,代码来源:smacross_strategy.py

示例13: calcSignal

 def calcSignal(self):
     self.buySignal,self.sellSignal = {},{}
     for instrument in self.instruments:
         self.buySignal[instrument],self.sellSignal[instrument] = False,False
         #if(self.longAllowed):
         if self.longPosition[instrument] is None:
             #mid 无多仓,检查是否需要开多仓
             if cross.cross_above(self.__sma[instrument], self.__lma[instrument]) > 0:
                 self.buySignal[instrument] = True   
         #if(self.shortAllowed ):
         if self.shortPosition[instrument] is None:
             if cross.cross_below(self.__sma[instrument], self.__lma[instrument]) > 0:
                 self.sellSignal[instrument] = True 
开发者ID:UpSea,项目名称:PyAlgoTradeMid,代码行数:13,代码来源:Signal.py

示例14: onBars

    def onBars(self, bars):
        bar = bars.getBar("orcl")
        self.printDebug("%s: O=%s H=%s L=%s C=%s" % (bar.getDateTime(), bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose()))

        if cross.cross_above(self.__fastSMADS, self.__slowSMADS) == 1:
            if self.__shortPos:
                self.exitShortPosition(bars, self.__shortPos)
            assert(self.__longPos is None)
            self.__longPos = self.enterLongPosition(bars)
        elif cross.cross_below(self.__fastSMADS, self.__slowSMADS) == 1:
            if self.__longPos:
                self.exitLongPosition(bars, self.__longPos)
            assert(self.__shortPos is None)
            self.__shortPos = self.enterShortPosition(bars)
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:14,代码来源:smacrossover_strategy_test.py

示例15: enterShortSignal

 def enterShortSignal(self) :
     if self.__lastShortPos is not None:
         if self.__barNum-self.__lastShortPos<60:
             return 0
     if self.__UpperBand[-1-self.__circ] is None:
         return 0
     m1 = 0
     for i in range(self.__circ):
         if self.__close[-i-1] >= self.__UpperBand[-i-2]:
             m1 += 1
     if m1 >= self.__circ-1 and cross.cross_below(self.__close,self.__UpperBand)>0:
         return 1
     else:
         return 0
开发者ID:llmofang,项目名称:backtest,代码行数:14,代码来源:bollinger_band.py


注:本文中的pyalgotrade.technical.cross.cross_below函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。