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


Python bar.getOpen函数代码示例

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


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

示例1: addBar

    def addBar(self, instrument, bar, frequency):
        instrument = normalize_instrument(instrument)
        instrumentId = self.__getOrCreateInstrument(instrument)
        timeStamp = dt.datetime_to_timestamp(bar.getDateTime())

        try:
            sql = "insert into bar (instrument_id, frequency, timestamp, open, high, low, close, volume, adj_close) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
            params = [instrumentId, frequency, timeStamp, bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolume(), bar.getAdjClose()]
            self.__connection.execute(sql, params)
        except sqlite3.IntegrityError:
            sql = "update bar set open = ?, high = ?, low = ?, close = ?, volume = ?, adj_close = ?" \
                " where instrument_id = ? and frequency = ? and timestamp = ?"
            params = [bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolume(), bar.getAdjClose(), instrumentId, frequency, timeStamp]
            self.__connection.execute(sql, params)
开发者ID:363158858,项目名称:pyalgotrade-cn,代码行数:14,代码来源:sqlitefeed.py

示例2: get_stop_price_trigger

def get_stop_price_trigger(action, stopPrice, useAdjustedValues, bar):
    ret = None
    open_ = bar.getOpen(useAdjustedValues)
    high = bar.getHigh(useAdjustedValues)
    low = bar.getLow(useAdjustedValues)

    # If the bar is above the stop price, use the open price.
    # If the bar includes the stop price, use the open price or the stop price. Whichever is better.
    if action in [broker.Order.Action.BUY, broker.Order.Action.BUY_TO_COVER]:
        if low > stopPrice:
            ret = open_
        elif stopPrice <= high:
            if open_ > stopPrice:  # The stop price was penetrated on open.
                ret = open_
            else:
                ret = stopPrice
    # If the bar is below the stop price, use the open price.
    # If the bar includes the stop price, use the open price or the stop price. Whichever is better.
    elif action in [broker.Order.Action.SELL, broker.Order.Action.SELL_SHORT]:
        if high < stopPrice:
            ret = open_
        elif stopPrice >= low:
            if open_ < stopPrice:  # The stop price was penetrated on open.
                ret = open_
            else:
                ret = stopPrice
    else:  # Unknown action
        assert(False)

    return ret
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:30,代码来源:fillstrategy.py

示例3: fillMarketOrder

    def fillMarketOrder(self, broker_, order, bar):
        # Calculate the fill size for the order.
        fillSize = self.__calculateFillSize(broker_, order, bar)
        if fillSize == 0:
            broker_.getLogger().debug(
                "Not enough volume to fill %s market order [%s] for %s share/s" % (
                    order.getInstrument(),
                    order.getId(),
                    order.getRemaining()
                )
            )
            return None

        # Unless its a fill-on-close order, use the open price.
        if order.getFillOnClose():
            price = bar.getClose(broker_.getUseAdjustedValues())
        else:
            price = bar.getOpen(broker_.getUseAdjustedValues())
        assert price is not None

        # Don't slip prices when the bar represents the trading activity of a single trade.
        if bar.getFrequency() != pyalgotrade.bar.Frequency.TRADE:
            price = self.__slippageModel.calculatePrice(
                order, price, fillSize, bar, self.__volumeUsed[order.getInstrument()]
            )
        return FillInfo(price, fillSize)
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:26,代码来源:fillstrategy.py

示例4: fillStopOrder

    def fillStopOrder(self, order, broker_, bar):
        ret = None

        # First check if the stop price was hit so the market order becomes active.
        stopPriceTrigger = None
        if not order.getStopHit():
            stopPriceTrigger = get_stop_price_trigger(
                order.getAction(),
                order.getStopPrice(),
                broker_.getUseAdjustedValues(),
                bar
            )
            order.setStopHit(stopPriceTrigger is not None)

        # If the stop price was hit, check if we can fill the market order.
        if order.getStopHit():
            fillSize = self.__calculateFillSize(order, broker_, bar)
            if fillSize == 0:
                broker_.getLogger().debug("Not enough volume to fill %s stop order [%s] for %d share/s" % (
                    order.getInstrument(),
                    order.getId(),
                    order.getRemaining()
                ))
                return None

            # If we just hit the stop price we'll use it as the fill price.
            # For the remaining bars we'll use the open price.
            if stopPriceTrigger is not None:
                price = stopPriceTrigger
            else:
                price = bar.getOpen(broker_.getUseAdjustedValues())

            ret = FillInfo(price, fillSize)
        return ret
开发者ID:Henry-Yan-Duke,项目名称:pyalgotrade,代码行数:34,代码来源:backtesting.py

示例5: get_range_price_trigger

def get_range_price_trigger(action, lowPrice, upPrice, useAdjustedValues, bar):
    ret = None
    open_ = bar.getOpen(useAdjustedValues)
    high = bar.getHigh(useAdjustedValues)
    low = bar.getLow(useAdjustedValues)

    # If the bar is below the limit price, use the open price.
    # If the bar includes the limit price, use the open price or the limit price.
    # if action in [broker.Order.Action.BUY, broker.Order.Action.BUY_TO_COVER]:
    #     if high < limitPrice:
    #         ret = open_
    #     elif limitPrice >= low:
    #         if open_ < limitPrice:  # The limit price was penetrated on open.
    #             ret = open_
    #         else:
    #             ret = limitPrice
    # If low of the bar is below lowPrice, use the open price when open is below lowPrice else use lowPrice.
    # If high of the bar is above upPrice, use the open price when open is above upPrice else use upPrice.
    if action in [broker.Order.Action.SELL, broker.Order.Action.SELL_SHORT]:
        if low < lowPrice:
            if open_ < lowPrice:
                ret = open_
            else:
                ret = lowPrice 
        elif upPrice <= high:
            if open_ > upPrice:  # The limit price was penetrated on open.
                ret = open_
            else:
                ret = upPrice
    else:  # Unknown action
        assert(False)
    return ret
开发者ID:runrunliuliu,项目名称:pyalgotrade,代码行数:32,代码来源:fillstrategy.py

示例6: get_limit_price_trigger

def get_limit_price_trigger(action, limitPrice, useAdjustedValues, bar):
    ret = None
    open_ = bar.getOpen(useAdjustedValues)
    high = bar.getHigh(useAdjustedValues)
    low = bar.getLow(useAdjustedValues)

    # If the bar is below the limit price, use the open price.
    # If the bar includes the limit price, use the open price or the limit price.
    if action in [broker.Order.Action.BUY, broker.Order.Action.BUY_TO_COVER]:
        if high < limitPrice:
            ret = open_
        elif limitPrice >= low:
            if open_ < limitPrice:  # The limit price was penetrated on open.
                ret = open_
            else:
                ret = limitPrice
    # If the bar is above the limit price, use the open price.
    # If the bar includes the limit price, use the open price or the limit price.
    elif action in [broker.Order.Action.SELL, broker.Order.Action.SELL_SHORT]:
        if low > limitPrice:
            ret = open_
        elif limitPrice <= high:
            if open_ > limitPrice:  # The limit price was penetrated on open.
                ret = open_
            else:
                ret = limitPrice
    else:  # Unknown action
        assert False
    return ret
开发者ID:tianhm,项目名称:pyalgotrade-cn,代码行数:29,代码来源:fillstrategy.py

示例7: onBars

 def onBars(self, bars):
     for instrument in bars.getInstruments():
         bar = bars[instrument]
         self.info("%s: %s %s %s %s %s %s" % (
             instrument,
             bar.getOpen(),
             bar.getHigh(),
             bar.getLow(),
             bar.getClose(),
             bar.getAdjClose(),
             bar.getVolume(),
         ))
开发者ID:jp1989326,项目名称:pyalgotrade,代码行数:12,代码来源:pandas_feed.py

示例8: fillMarketOrder

    def fillMarketOrder(self, order, broker_, bar):
        fillSize = self.__calculateFillSize(order, broker_, bar)
        if fillSize == 0:
            return None

        ret = None
        if order.getFillOnClose():
            price = bar.getClose(broker_.getUseAdjustedValues())
        else:
            price = bar.getOpen(broker_.getUseAdjustedValues())
        if price is not None:
            ret = FillInfo(price, fillSize)
        return ret
开发者ID:TimonPeng,项目名称:pi314,代码行数:13,代码来源:backtesting.py

示例9: fillMarketOrder

    def fillMarketOrder(self, order, broker_, bar):
        fillSize = self.__calculateFillSize(order, broker_, bar)
        if fillSize == 0:
            broker_.getLogger().debug("Not enough volume to fill %s market order [%s] for %d share/s" % (order.getInstrument(), order.getId(), order.getRemaining()))
            return None

        ret = None
        if order.getFillOnClose():
            price = bar.getClose(broker_.getUseAdjustedValues())
        else:
            price = bar.getOpen(broker_.getUseAdjustedValues())
        if price is not None:
            ret = FillInfo(price, fillSize)
        return ret
开发者ID:biznixcn,项目名称:pyalgotrade,代码行数:14,代码来源:backtesting.py

示例10: dayInfo

 def dayInfo(self, bar):
     try:
         self.__openD[-1]
     except AttributeError:
         self.__openD = []
         self.__highD = []
         self.__lowD = []
         self.__closeD = []
         self.__upper_limit = []
         self.__lower_limit = []
         
     if len(self.__datetime) < 2:
         self.__openD.append(bar.getOpen())
         self.__highD.append(self.__high[-1])
         self.__lowD.append(self.__low[-1])
         self.__closeD.append(self.__close[-1])                              
         return
         
     # if another day
     if self.__datetime[-1].date() != self.__datetime[-2].date():
         self.__openD.append(bar.getOpen())
         self.__highD.append(self.__high[-1])
         self.__lowD.append(self.__low[-1])
         self.__closeD.append(self.__close[-1]) 
         self.__upper_limit.append(round(round(self.__closeD[-2] * 1.1 * 1000) / 10) / 100)
         self.__lower_limit.append(round(round(self.__closeD[-2] * 0.9 * 1000) / 10) / 100) 
         print self.__datetime[-1].date(), self.__datetime[-2].date(), self.__openD[-1]
                          
     elif self.__datetime[-1].date() == self.__datetime[-2].date():
         if self.__high[-1] > self.__highD[-1]:
             self.__highD[-1] = self.__high[-1]
         
         if self.__low[-1] < self.__lowD[-1]:
             self.__lowD[-1] = self.__low[-1]
         
         self.__closeD[-1] = self.__close[-1]
开发者ID:UpSea,项目名称:midProjects,代码行数:36,代码来源:thrSMA_dayinfo.py

示例11: fillStopOrder

    def fillStopOrder(self, broker_, order, bar):
        ret = None

        # First check if the stop price was hit so the market order becomes active.
        stopPriceTrigger = None
        if not order.getStopHit():
            stopPriceTrigger = get_stop_price_trigger(
                order.getAction(),
                order.getStopPrice(),
                broker_.getUseAdjustedValues(),
                bar
            )
            order.setStopHit(stopPriceTrigger is not None)

        # If the stop price was hit, check if we can fill the market order.
        if order.getStopHit():
            # Calculate the fill size for the order.
            fillSize = self.__calculateFillSize(broker_, order, bar)
            if fillSize == 0:
                broker_.getLogger().debug("Not enough volume to fill %s stop order [%s] for %s share/s" % (
                    order.getInstrument(),
                    order.getId(),
                    order.getRemaining()
                ))
                return None

            # If we just hit the stop price we'll use it as the fill price.
            # For the remaining bars we'll use the open price.
            if stopPriceTrigger is not None:
                price = stopPriceTrigger
            else:
                price = bar.getOpen(broker_.getUseAdjustedValues())
            assert price is not None

            # Don't slip prices when the bar represents the trading activity of a single trade.
            if bar.getFrequency() != pyalgotrade.bar.Frequency.TRADE:
                price = self.__slippageModel.calculatePrice(
                    order, price, fillSize, bar, self.__volumeUsed[order.getInstrument()]
                )
            ret = FillInfo(price, fillSize)
        return ret
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:41,代码来源:fillstrategy.py

示例12: adjustBars

	def adjustBars(self):

		for key, value in self.__barsDict.iteritems():

			basicbars = []
			bars = value
			bars_in_dtrange = [bar for bar in bars if self.__startdate.replace(tzinfo=None) <= bar.getDateTime() <= self.__enddate.replace(tzinfo=None)]
			bars_in_dtrange.sort(key=lambda bar: bar.getDateTime(), reverse=True)

			k = 0
			splitdataList = []
			dividendList = []

			for bar in bars_in_dtrange:
				splitdata = float(bar.getSplit())
				dividend = float(bar.getDividend())
				if splitdata != 1.0:
					splitdataList.append(bar.getSplit())
				if dividend != 0.0:
					adjFactor = (bar.getClose() + bar.getDividend()) / bar.getClose()
					dividendList.append(adjFactor)
				#### Special case.... end date / analysis date nothing to do..
				if (k==0):
					bar = BasicBar(bar.getDateTime(), 
						bar.getOpen() , bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolume(), bar.getClose(), Frequency.DAY)
					basicbars.append(bar)
				else:
					#### Adjust OHLC & Volume data for split adjustments and dividend adjustments
					Open = bar.getOpen()
					High = bar.getHigh()
					Low  = bar.getLow()
					Close = bar.getClose()
					Volume = bar.getVolume()
					### adjust data for splits
					for split in splitdataList:
						Open = Open / split
						High = High / split
						Low  = Low / split
						Close = Close /split
						Volume = Volume * split

					### adjust data for dividends
					for adjFactor in dividendList:
						Open = Open / adjFactor
						High = High / adjFactor
						Low  = Low / adjFactor
						Close = Close / adjFactor
						Volume = Volume * adjFactor
					bar = BasicBar(bar.getDateTime(), 
						Open , High, Low, Close, Volume, Close, Frequency.DAY)
					basicbars.append(bar)
				k +=1


			DateTimes = []
			OpenSeries = SequenceDataSeries(4000)
			HighSeries = SequenceDataSeries(4000)
			LowSeries =  SequenceDataSeries(4000)
			CloseSeries = SequenceDataSeries(4000)
			VolumeSeries = SequenceDataSeries(4000)
			TypicalSeries = SequenceDataSeries(4000)
			barSeries = BarDataSeries(4000)
			basicbars.sort(key=lambda bar: bar.getDateTime(), reverse=False)
			

			for bar in basicbars:
				DateTimes.append(bar.getDateTime())
				OpenSeries.appendWithDateTime(bar.getDateTime(), bar.getOpen())
				HighSeries.appendWithDateTime(bar.getDateTime(), bar.getHigh())
				LowSeries.appendWithDateTime(bar.getDateTime(), bar.getLow())
				CloseSeries.appendWithDateTime(bar.getDateTime(), bar.getClose())
				VolumeSeries.appendWithDateTime(bar.getDateTime(), bar.getVolume())
				TypicalSeries.appendWithDateTime(bar.getDateTime(), (bar.getClose()+bar.getHigh()+bar.getLow())/3.0)
				barSeries.appendWithDateTime(bar.getDateTime(), bar)


			self.__DateTimes[key+"_adjusted"] = DateTimes
			self.__OpenDataSeries[key+"_adjusted"] = OpenSeries
			self.__HighDataSeries[key+"_adjusted"] = HighSeries
			self.__LowDataSeries[key+"_adjusted"] =  LowSeries
			self.__CloseDataSeries[key+"_adjusted"] = CloseSeries
			self.__VolumeDataSeries[key+"_adjusted"] = VolumeSeries
			self.__TypicalDataSeries[key+"_adjusted"] = TypicalSeries
			self.__barSeries[key+"_adjusted"] = barSeries
开发者ID:lagisettyk,项目名称:roboquant,代码行数:84,代码来源:xiquantPlatform.py


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