Пример #1
0
 def testAppendInvalidDatetime(self):
     ds = dataseries.BarDataSeries()
     for i in range(10):
         now = datetime.datetime.now() + datetime.timedelta(seconds=i)
         ds.append_value(bar.Bar(now, 0, 0, 0, 0, 0, 0))
         # Adding the same datetime twice should fail
         self.assertRaises(Exception, ds.append_value,
                           bar.Bar(now, 0, 0, 0, 0, 0, 0))
         # Adding a previous datetime should fail
         self.assertRaises(
             Exception, ds.append_value,
             bar.Bar(now - datetime.timedelta(seconds=i), 0, 0, 0, 0, 0, 0))
Пример #2
0
 def parse_bar(self, csv_row_dict):
     date_time = self.__parse_date_time(csv_row_dict["Date Time"])
     close = float(csv_row_dict["Close"])
     open_ = float(csv_row_dict["Open"])
     high = float(csv_row_dict["High"])
     low = float(csv_row_dict["Low"])
     volume = float(csv_row_dict["Volume"])
     return bar.Bar(date_time, open_, high, low, close, volume, None)
def build_bars_from_closing_prices(closingPrices):
    ret = []

    nextDateTime = datetime.datetime.now()
    for closePrice in closingPrices:
        bar_ = bar.Bar(nextDateTime, closePrice, closePrice, closePrice, closePrice, closePrice, closePrice)
        ret.append(bar_)
        nextDateTime = nextDateTime + datetime.timedelta(days=1)
    return ret
Пример #4
0
    def testNonEmpty(self):
        ds = dataseries.BarDataSeries()
        for i in range(10):
            ds.append_value(
                bar.Bar(
                    datetime.datetime.now() + datetime.timedelta(seconds=i), 0,
                    0, 0, 0, 0, 0))

        for i in range(0, 10):
            self.assertTrue(ds.get_value(i) != None)
Пример #5
0
    def __loadSarTestBarDs(self):
        seconds = 0

        ret = dataseries.BarDataSeries()
        for i in xrange(len(SAR_HIGH)):
            date_time = datetime.datetime.now() + datetime.timedelta(
                seconds=seconds)
            ret.append_value(
                bar.Bar(date_time, SAR_LOW[i], SAR_HIGH[i], SAR_LOW[i],
                        SAR_HIGH[i], 0, SAR_LOW[i]))
            seconds += 1
        return ret
Пример #6
0
    def __loadBarDS(self):
        seconds = 0

        ret = dataseries.BarDataSeries()
        for i in xrange(len(OPEN_VALUES)):
            date_time = datetime.datetime.now() + datetime.timedelta(
                seconds=seconds)
            ret.append_value(
                bar.Bar(date_time, OPEN_VALUES[i], HIGH_VALUES[i],
                        LOW_VALUES[i], CLOSE_VALUES[i], VOLUME_VALUES[i],
                        CLOSE_VALUES[i]))
            seconds += 1
        return ret
Пример #7
0
    def testSeqLikeOps(self):
        ds = dataseries.BarDataSeries()
        for i in range(10):
            ds.append_value(
                bar.Bar(
                    datetime.datetime.now() + datetime.timedelta(seconds=i), 2,
                    4, 1, 3, 10, 3))

        self.assertEqual(ds[-1], ds.get_value())
        self.assertEqual(ds[-2], ds.get_value(1))
        self.assertEqual(ds[0], ds[0])
        self.assertEqual(ds[1], ds[1])
        self.assertEqual(ds[-2:][-1], ds.get_value())
Пример #8
0
 def row_to_bar(self, row):
     row = row.split(',')
     dt = row[0]
     date = datetime.datetime(int(dt[:4]), int(dt[5:7]), int(dt[8:10]))
     open_ = float(row[1])
     high = float(row[2])
     low = float(row[3])
     close = float(row[4])
     volume = float(row[5])
     adj_close = float(row[6])
     try:
         return bar.Bar(date, open_, high, low, close, volume, adj_close)
     except AssertionError as e:
         return str(e)
Пример #9
0
    def testNestedDataSeries(self):
        ds = dataseries.BarDataSeries()
        for i in range(10):
            ds.append_value(
                bar.Bar(
                    datetime.datetime.now() + datetime.timedelta(seconds=i), 2,
                    4, 1, 3, 10, 3))

        self.__testGetValue(ds.get_open_data_series(), 10, 2)
        self.__testGetValue(ds.get_close_data_series(), 10, 3)
        self.__testGetValue(ds.get_high_data_series(), 10, 4)
        self.__testGetValue(ds.get_low_data_series(), 10, 1)
        self.__testGetValue(ds.get_volume_data_series(), 10, 10)
        self.__testGetValue(ds.get_adj_close_data_series(), 10, 3)
Пример #10
0
 def row_to_bar(self, row):
     row = row.split(',')
     try:
         date = datetime.datetime.fromtimestamp(int(row[0]))
     except ValueError:
         date = datetime.datetime.strptime(row[0], settings.DATE_FORMAT)
     close = float(row[1])
     high = float(row[2])
     low = float(row[3])
     open_ = float(row[4])
     volume = float(row[5])
     try:
         return bar.Bar(date, open_, high, low, close, volume, close)
     except AssertionError, e:
         return str(e)