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))
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)
def parseBar(self, csvRowDict): dateTime = self.__parseDateTime(csvRowDict["Date Time"]) close = float(csvRowDict["Close"]) open_ = float(csvRowDict["Open"]) high = float(csvRowDict["High"]) low = float(csvRowDict["Low"]) volume = float(csvRowDict["Volume"]) return bar.Bar(dateTime, open_, high, low, close, volume, None)
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)
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
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
def __buildBar(self, openPrice, highPrice, lowPrice, closePrice): dateTime = datetime.datetime.now() + datetime.timedelta( seconds=self.__currSeconds) self.__currSeconds += 1 return bar.Bar(dateTime, openPrice, highPrice, lowPrice, closePrice, closePrice * 10, closePrice)
def ds_bar_to_pyalgotrade_bar(dsBar): return bar.Bar(dsBar.dateTime, dsBar.open_, dsBar.high, dsBar.low, dsBar.close_, dsBar.volume, dsBar.adjClose)