• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python cross.cross_below函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: onBars

    def onBars(self, bars):
        # If a position was not opened, check if we should enter a long position.

        if self.__ma3[-1] is None:
            return

        if self.__position is not None:
            if not self.__position.exitActive() and cross.cross_below(self.__ma1, self.__ma2) > 0:
                self.__position.exitMarket()
                # self.info("sell %s" % (bars.getDateTime()))

        if self.__position is None:
            if self.buyCon1() and self.buyCon2():
                shares = int(self.getBroker().getCash() * 0.2 / bars[self.__instrument].getPrice())
                self.__position = self.enterLong(self.__instrument, shares)
开发者ID:chopchopjames,项目名称:pyalgotrade-cn,代码行数:15,代码来源:thrSMA.py


示例17: exitLongSignal

 def exitLongSignal(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
     elif self.__macd[-1]>=self.__UpperBand[-1] and self.__macdMax==self.__macd[-1]:
         return True
     elif self.__macd[-1]*1.001>=self.__UpperBand[-1] and self.__macd[-1]>-0.1:
         return True
     else:
         return False
开发者ID:llmofang,项目名称:backtest,代码行数:15,代码来源:bollingerband_macd.py


示例18: onBars

    def onBars(self, bars):
        bar = bars[self.__instrument]
        self.info("Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))

        # Wait until we get the current bid/ask prices.
        if self.__ask is None:
            return

        # 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:
                self.info("Entry signal. Buy at %s" % (self.__ask))
                self.__position = self.enterLongLimit(self.__instrument, self.__ask, self.__posSize, True)
        # Check if we have to close the position.
        elif not self.__position.exitActive() and cross.cross_below(self.__prices, self.__sma) > 0:
            self.info("Exit signal. Sell at %s" % (self.__bid))
            self.__position.exitLimit(self.__bid)
开发者ID:iminrhythm,项目名称:iirmerl,代码行数:17,代码来源:p2btstmp.py


示例19: onBars

    def onBars(self, bars):
        # If a position was not opened, check if we should enter a long position.
        closeDs = self.getFeed().getDataSeries(instrument).getCloseDataSeries()
        self.__ma1 = indicator.MA(closeDs, 40, self.__malength1)
        self.__ma2 = indicator.MA(closeDs, 40, self.__malength2)

        if self.__ma2[-1]is None:
            return 
            
        if self.__position is not None:
            if not self.__position.exitActive() and cross.cross_below(self.__ma1, self.__ma2) > 0:
                self.__position.exitMarket()
                #self.info("sell %s" % (bars.getDateTime()))
        
        if self.__position is None:
            if cross.cross_above(self.__ma1, self.__ma2) > 0:
                shares = int(self.getBroker().getEquity() * 0.2 / bars[self.__instrument].getPrice())
                self.__position = self.enterLong(self.__instrument, shares)
                print bars[self.__instrument].getDateTime(), bars[self.__instrument].getPrice()
开发者ID:grayfox7744,项目名称:quantLibrary,代码行数:19,代码来源:doubleMA.py


示例20: onBars

 def onBars(self, bars):
     inst0_cond = cross.cross_above(self.__prices[self.__instrumentList[0]], self.__sma[self.__instrumentList[0]])
     inst2_cond = cross.cross_above(self.__prices[self.__instrumentList[2]], self.__sma[self.__instrumentList[2]])
     # If a position was not opened, check if we should enter a long position.
     if not self.__positions:
         if inst0_cond > 0 or inst2_cond > 0:
             if inst0_cond > 0:
                 shares_0 = int(self.getBroker().getCash() * 0.6 / bars[self.__instrumentList[0]].getPrice())
                 shares_2 = int(self.getBroker().getCash() * 0.3 / bars[self.__instrumentList[2]].getPrice())
             else:
                 shares_0 = int(self.getBroker().getCash() * 0.3 / bars[self.__instrumentList[0]].getPrice())
                 shares_2 = int(self.getBroker().getCash() * 0.6 / bars[self.__instrumentList[2]].getPrice())
             # Enter a buy market order. The order is good till canceled.
             print "%%%%%$$$$: ", shares_0, shares_2
             self.__positions[self.__instrumentList[0]] = self.enterLong(self.__instrumentList[0], int(shares_0), True)
             self.__positions[self.__instrumentList[2]] =self.enterLong(self.__instrumentList[2], int(shares_2), True)
             self.__activePosition = self.__instrumentList[0]
     # Check if we have to exit the position.
     elif cross.cross_below(self.__prices[self.__activePosition], self.__sma[self.__activePosition]) > 0:
         self.__position[self.__instrumentList[0]].exitMarket()
         self.__position[self.__instrumentList[2]].exitMarket()
开发者ID:lagisettyk,项目名称:roboquant,代码行数:21,代码来源:simple_strategy.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python yahoofinance.build_feed函数代码示例发布时间:2022-05-25
下一篇:
Python cross.cross_above函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap