示例#1
0
    def popOneDayData(self):
        if self.md_date is None or self.md_date.shape[0] < 1:
            return extracts.md_extracts(np.array([]), np.array([]),
                                        np.array([]), np.array([]),
                                        np.array([]), np.array([]),
                                        np.array([]))

        currentDay = self.md_date[0]
        nextDayIndex = 0
        for dayIndex in range(self.md_date.shape[0]):
            if currentDay != self.md_date[dayIndex]:
                nextDayIndex = dayIndex
                break
        if nextDayIndex == 0:
            nextDayIndex = self.md_date.shape[0]
        oneDayDate, self.md_date = np.split(self.md_date, [nextDayIndex])
        oneDayTime, self.md_time = np.split(self.md_time, [nextDayIndex])
        oneDayOpen, self.md_open = np.split(self.md_open, [nextDayIndex])
        oneDayClose, self.md_close = np.split(self.md_close, [nextDayIndex])
        oneDayHigh, self.md_high = np.split(self.md_high, [nextDayIndex])
        oneDayLow, self.md_low = np.split(self.md_low, [nextDayIndex])
        oneDayVolume, self.md_volume = np.split(self.md_volume, [nextDayIndex])
        extract_obj = extracts.md_extracts(oneDayDate, oneDayTime, oneDayOpen,
                                           oneDayClose, oneDayHigh, oneDayLow,
                                           oneDayVolume)
        return extract_obj
 def split(self):
     if self.extract_obj.md_date.shape[0] > self.threshold:
         input_date, output_date = np.split(self.extract_obj.md_date,
                                            [self.threshold])
         input_time, output_time = np.split(self.extract_obj.md_time,
                                            [self.threshold])
         input_open, output_open = np.split(self.extract_obj.md_open,
                                            [self.threshold])
         input_close, output_close = np.split(self.extract_obj.md_close,
                                              [self.threshold])
         input_high, output_high = np.split(self.extract_obj.md_high,
                                            [self.threshold])
         input_low, output_low = np.split(self.extract_obj.md_low,
                                          [self.threshold])
         input_volume, output_volume = np.split(self.extract_obj.md_volume,
                                                [self.threshold])
         input_extract_obj = extracts.md_extracts(input_date, input_time,
                                                  input_open, input_close,
                                                  input_high, input_low,
                                                  input_volume)
         output_extract_obj = extracts.md_extracts(output_date, output_time,
                                                   output_open,
                                                   output_close,
                                                   output_high, output_low,
                                                   output_volume)
         return True, input_extract_obj, output_extract_obj
     else:
         input_extract_obj = extracts.md_extracts(np.array([]), np.array(
             []), np.array([]), np.array([]), np.array([]), np.array([]),
                                                  np.array([]))
         output_extract_obj = extracts.md_extracts(np.array([]), np.array(
             []), np.array([]), np.array([]), np.array([]), np.array([]),
                                                   np.array([]))
         return False, input_extract_obj, output_extract_obj
示例#3
0
def extract_file(train_file):

    data_file = open(train_file)
    data_file_header = data_file.readline()

    file_data = []
    for line in data_file:
        if (len(line.strip()) > 0):
            file_data.append(line)

    data_file_header = [x for x in data_file_header.split(',') if len(x) >= 1]
    data_by_field = [[x for x in y.split(',') if len(x) >= 1]
                     for y in file_data if len(y) >= 1]

    md_date = np.array([x[0].strip() for x in data_by_field])
    md_time = np.array([x[1].strip() for x in data_by_field])
    md_open = np.array([x[5].strip() for x in data_by_field])
    md_close = np.array([x[6].strip() for x in data_by_field])
    md_high = np.array([x[7].strip() for x in data_by_field])
    md_low = np.array([x[8].strip() for x in data_by_field])
    md_volume = np.array([x[9].strip() for x in data_by_field])
    extracts_obj = extracts.md_extracts(md_date, md_time, md_open, md_close,
                                        md_high, md_low, md_volume)
    data_file.close()

    return extracts_obj
 def setUp(self):
     self.md_date = np.array([
         '03/06/2012', '03/06/2012', '03/06/2012', '03/06/2012',
         '03/06/2012', '03/06/2012'
     ])
     self.md_time = np.array([
         '09:15:00 AM', '09:16:00 AM', '09:17:00 AM', '09:18:00 AM',
         '09:19:00 AM', '09:20:00 AM'
     ])
     self.md_open = np.array(
         ['21119', '21119', '21126', '22119', '22119', '22126'])
     self.md_high = np.array(
         ['21130', '21127', '21126', '22130', '22127', '22126'])
     self.md_low = np.array(
         ['21101', '21111', '21105', '22101', '22111', '22105'])
     self.md_close = np.array(
         ['21115', '21125', '21108', '22115', '22125', '22108'])
     self.md_volume = np.array(
         ['662', '243', '392', '2662', '2243', '2392'])
     self.extract_obj = extracts.md_extracts(self.md_date, self.md_time,
                                             self.md_open, self.md_close,
                                             self.md_high, self.md_low,
                                             self.md_volume)