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


Python bar.getDateTime函数代码示例

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


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

示例1: __getNextLine

	def __getNextLine(self, bar):
		ret = None

		if len(self.getValues()) > 0:
			lastLine = self.getValues()[-1]
			close = pyalgotrade.bar.get_close(bar, self.__useAdjustedValues)
			if lastLine.isWhite():
				if close > lastLine.getHigh():
					# Price extends in the same direction
					ret = Line(lastLine.getHigh(), close, bar.getDateTime(), True)
				elif self.__isReversal(close, False):
					# Price change is enough to warrant a reversal.
					ret = Line(close, lastLine.getLow(), bar.getDateTime(), False)
			else:
				if close < lastLine.getLow():
					# Price extends in the same direction
					ret = Line(close, lastLine.getLow(), bar.getDateTime(), False)
				elif self.__isReversal(close, True):
					# Price change is enough to warrant a reversal.
					ret = Line(lastLine.getHigh(), close, bar.getDateTime(), True)
		else:
			white = False
			if pyalgotrade.bar.get_close(bar, self.__useAdjustedValues) >= pyalgotrade.bar.get_open(bar, self.__useAdjustedValues):
				white = True
			ret = Line(pyalgotrade.bar.get_low(bar, self.__useAdjustedValues), pyalgotrade.bar.get_high(bar, self.__useAdjustedValues), bar.getDateTime(), white)
		return ret
开发者ID:charnugagoo,项目名称:pyalgotrade,代码行数:26,代码来源:linebreak.py

示例2: testWithPerFileTimezone

 def testWithPerFileTimezone(self):
     barFeed = yahoofeed.Feed()
     barFeed.addBarsFromCSV(FeedTestCase.TestInstrument, common.get_data_file_path("orcl-2000-yahoofinance.csv"), marketsession.USEquities.getTimezone())
     barFeed.addBarsFromCSV(FeedTestCase.TestInstrument, common.get_data_file_path("orcl-2001-yahoofinance.csv"), marketsession.USEquities.getTimezone())
     for dateTime, bars in barFeed:
         bar = bars.getBar(FeedTestCase.TestInstrument)
         self.assertFalse(dt.datetime_is_naive(bar.getDateTime()))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:7,代码来源:yahoofeed_test.py

示例3: testWithoutTimezone

 def testWithoutTimezone(self):
     barFeed = yahoofeed.Feed()
     barFeed.addBarsFromCSV(YahooTestCase.TestInstrument, common.get_data_file_path("orcl-2000-yahoofinance.csv"))
     barFeed.addBarsFromCSV(YahooTestCase.TestInstrument, common.get_data_file_path("orcl-2001-yahoofinance.csv"))
     for dateTime, bars in barFeed:
         bar = bars.getBar(YahooTestCase.TestInstrument)
         self.assertTrue(dt.datetime_is_naive(bar.getDateTime()))
开发者ID:arippbbc,项目名称:pyalgotrade,代码行数:7,代码来源:csvbarfeed_test.py

示例4: tryExecuteImpl

	def tryExecuteImpl(self, broker_, bar):
		justHitStopPrice = False

		# Check if we have to activate the limit order first.
		if not self.isLimitOrderActive() and self.__stopHit(broker_, bar):
			self.setLimitOrderActive(True)
			justHitStopPrice = True

		# Check if we have ever reached the limit price
		if self.isLimitOrderActive():
			fillInfo = broker_.getFillStrategy().fillStopLimitOrder(self, broker_, bar, justHitStopPrice)
			if fillInfo != None:
				broker_.commitOrderExecution(self, fillInfo.getPrice(), self.getQuantity(), bar.getDateTime())
开发者ID:iantuan,项目名称:pyalgotrade,代码行数:13,代码来源:backtesting.py

示例5: 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

示例6: onBars

    def onBars(self, bars):
        bar = bars[self.__instrument]
        # tmp_dtime = bar.getDateTime()
        self.__dtime = bar.getDateTime()
        if (None is self.lastDate):
            self.lastDate = self.__dtime.date()
        else:
            if (self.lastDate != self.__dtime.date()):
                self.lastDate = self.__dtime.date()
                self.__resetORHL()                
            else:
                self.barIntradayCount += 1

        ## intraday dynamics
        if (self.openrange > self.barIntradayCount):
            if bar.getHigh() > self.orh:
                self.orh = bar.getHigh()
            if bar.getLow() < self.orl:
                self.orl = bar.getLow()
        elif (self.openrange == self.barIntradayCount):
            self.__resetAC()
        elif (self.__dtime.time() > self.exitIntradayTradeTime):
            self.exitAllPositions()
        else:
            self.__clos = bar.getClose()
            self.__dynamics(self.__clos)
            if (0 == self.stateA):
                tmp_0 = self.processEvent1()
                if (1 <= tmp_0):
                    self.action_init2up()
                elif (-1 >= tmp_0):
                    self.action_init2down()
            else:
                if (1 == self.stateA):
                    if (6 == self.stateB):
                        tmp_6 = self.processEvent1()
                        if (1 <= tmp_6):
                            self.action_upempty2duo()
                        elif (-2 == tmp_6):
                            self.action_upempty2kong()
                    elif (2 == self.stateB):
                        tmp_2 = self.processEvent3()
                        if (1 == tmp_2):
                            self.action_upduo2exit_time()
                    elif (4 == self.stateB):
                        tmp_4 = self.processEvent3()
                        if (1 == tmp_4):
                            self.action_upkong2exit_time()
                else: # self.stateA == -1
                    if (6 == self.stateB):
                        tmp_6 = self.processEvent1()
                        if (2 == tmp_6):
                            self.action_downempty2duo()
                        elif (-1 >= tmp_6):
                            self.action_downempty2kong()
                    elif (2 == self.stateB):
                        tmp_2 = self.processEvent3()
                        if (1 == tmp_2):
                            self.action_downduo2exit_time()
                    elif (4 == self.stateB):
                        tmp_4 = self.processEvent3()
                        if (1 == tmp_4):
                            self.action_downkong2exit_time()
开发者ID:fuckfuckfuckfuck,项目名称:bin,代码行数:63,代码来源:orb.py

示例7: getCurrentDateTime

 def getCurrentDateTime(self):
     if self.__nextBar < len(self.__bars):
         bar = self.__bars[self.__nextBar]
     else:
         bar = self.__bars[-1]
     return bar.getDateTime()
开发者ID:frostyplanet,项目名称:pyalgotrade,代码行数:6,代码来源:__init__.py

示例8: tryExecuteImpl

 def tryExecuteImpl(self, broker_, bar):
     fillInfo = broker_.getFillStrategy().fillStopOrder(self, broker_, bar)
     if fillInfo is not None:
         broker_.commitOrderExecution(self, fillInfo.getPrice(), self.getQuantity(), bar.getDateTime())
开发者ID:akkineniramesh,项目名称:pyalgotrade,代码行数:4,代码来源:backtesting.py

示例9: 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

示例10: __addBar

 def __addBar(self, symbol, bar, cursor):
     string = ("INSERT INTO data (`symbol`, `date`,`milliseconds`, `open`, `close`, `high`, `low`, `volume`) " + 
               "VALUES ('{0:s}', '{1:%Y-%m-%d %H:%M:%S}', '{4:d}','{2:f}', '{2:f}', '{2:f}', '{2:f}', '{3:f}')")
     queryStr = string.format(symbol, bar.getDateTime(), bar.getClose(), bar.getVolume(), bar.getMilliSeconds())
     cursor.execute(queryStr)
开发者ID:TimonPeng,项目名称:pi314,代码行数:5,代码来源:client.py


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