示例#1
0
	def testNonEmpty(self):
		ds = dataseries.BarDataSeries()
		for i in range(10):
			ds.appendValue( bar.Bar(datetime.datetime.now() + datetime.timedelta(seconds=i), 0, 0, 0, 0, 0, 0) )

		for i in range(0, 10):
			self.assertTrue(ds.getValue(i) != None)
示例#2
0
 def __buildBarDataSeries(self, closePrices, highPrices, lowPrices):
     assert (len(closePrices) == len(highPrices) == len(lowPrices))
     ret = dataseries.BarDataSeries()
     for i in range(len(highPrices)):
         ret.appendValue(
             self.__buildBar(closePrices[i], highPrices[i], lowPrices[i],
                             closePrices[i]))
     return ret
示例#3
0
	def testAppendInvalidDatetime(self):
		ds = dataseries.BarDataSeries()
		for i in range(10):
			now = datetime.datetime.now() + datetime.timedelta(seconds=i)
			ds.appendValue( bar.Bar(now, 0, 0, 0, 0, 0, 0) )
			# Adding the same datetime twice should fail
			self.assertRaises(Exception, ds.appendValue, bar.Bar(now, 0, 0, 0, 0, 0, 0))
			# Adding a previous datetime should fail
			self.assertRaises(Exception, ds.appendValue, bar.Bar(now - datetime.timedelta(seconds=i), 0, 0, 0, 0, 0, 0))
示例#4
0
	def testNestedDataSeries(self):
		ds = dataseries.BarDataSeries()
		for i in range(10):
			ds.appendValue( bar.Bar(datetime.datetime.now() + datetime.timedelta(seconds=i), 2, 4, 1, 3, 10, 3) )

		self.__testGetValue(ds.getOpenDataSeries(), 10, 2)
		self.__testGetValue(ds.getCloseDataSeries(), 10, 3)
		self.__testGetValue(ds.getHighDataSeries(), 10, 4)
		self.__testGetValue(ds.getLowDataSeries(), 10, 1)
		self.__testGetValue(ds.getVolumeDataSeries(), 10, 10)
		self.__testGetValue(ds.getAdjCloseDataSeries(), 10, 3)
示例#5
0
	def testEmpty(self):
		ds = dataseries.BarDataSeries()
		self.assertTrue(ds.getValue(-2) == None)
		self.assertTrue(ds.getValue(-1) == None)
		self.assertTrue(ds.getValue() == None)
		self.assertTrue(ds.getValue(1) == None)
		self.assertTrue(ds.getValue(2) == None)

		self.assertTrue(ds.getValueAbsolute(-1) == None)
		self.assertTrue(ds.getValueAbsolute(0) == None)
		self.assertTrue(ds.getValueAbsolute(1000) == None)
示例#6
0
    def __loadSarTestBarDs(self):
        seconds = 0

        ret = dataseries.BarDataSeries()
        for i in xrange(len(SAR_HIGH)):
            dateTime = datetime.datetime.now() + datetime.timedelta(
                seconds=seconds)
            ret.appendValue(
                bar.Bar(dateTime, SAR_LOW[i], SAR_HIGH[i], SAR_LOW[i],
                        SAR_HIGH[i], 0, SAR_LOW[i]))
            seconds += 1
        return ret
示例#7
0
    def __loadBarDS(self):
        seconds = 0

        ret = dataseries.BarDataSeries()
        for i in xrange(len(OPEN_VALUES)):
            dateTime = datetime.datetime.now() + datetime.timedelta(
                seconds=seconds)
            ret.appendValue(
                bar.Bar(dateTime, OPEN_VALUES[i], HIGH_VALUES[i],
                        LOW_VALUES[i], CLOSE_VALUES[i], VOLUME_VALUES[i],
                        CLOSE_VALUES[i]))
            seconds += 1
        return ret
示例#8
0
	def registerInstrument(self, instrument):
		self.__defaultInstrument = instrument
		if instrument not in self.__ds:
			self.__ds[instrument] = dataseries.BarDataSeries()