예제 #1
0
 def __init__(self, code, startd="", endd=""):
     '''
     Constructor
     '''
     self.code = code
     self.startd = startd
     self.endd = endd
     self.normal_lines = {}
     self.base_lines = {}
     self.trend_lines = {}
     data = kf.get_kabuka([code], startd, endd, True)
     if data.has_key(code):
         self.data = kf.get_kabuka([code], startd, endd, True)[code]
     else:
         return None
     if len(self.data) == 0:
         return None
     self._make_lines()
예제 #2
0
 def __init__(self, meigaras, startd="", endd=""):
     '''
     Constructor
     '''
     self.startd = startd
     self.endd = endd
     self.normal_lines = {}
     self.base_lines = {}
     self.trend_lines = {}
     self.data = kf.get_kabuka(meigaras, startd, endd)
     self._make_lines()
     f.log("finished preparation")
예제 #3
0
 def set_params(self, startd, endd, save_folder, meigaras=[]):
     if len(meigaras) > 0:
         self.meigaras = meigaras
     if save_folder == "":
         savedir = "%s" % (PNFCKPT_DIR)
     else:
         savedir = "%s/%s" % (PNFCKPT_DIR, save_folder)
     if os.path.exists(savedir) == False:
         os.makedirs(savedir)
     self.ckptfile = "%s/pnf.ckpt" % (savedir)
     
     self.startd = startd
     self.endd = endd
     self.data = kf.get_kabuka(self.meigaras, self.startd, self.endd, True)
예제 #4
0
 def __init__(self, code, startd="", endd="", buffer_days=60):
     '''
     Constructor
     '''
     code = str(code)
     self.code = code
     self.startd = dtf.datestrsub(startd, buffer_days)
     self.endd = endd
     self.buffer_days = buffer_days
     self.normal_lines = {}
     self.trend_lines = {}
     data = kf.get_kabuka([code], startd, endd, True)
     if data.has_key(code):
         self.data = data[code]
     else:
         return None
     if len(self.data) == 0:
         return None
     self._make_lines()
예제 #5
0
    def get_line_data(self, meigaras=[]):
        data = kf.get_kabuka(meigaras, self.startd, self.endd, True)
        xbatch = []
        ybatch = []
        for code in data.keys():
            (indexes, dates, open, high, low, close, volume) = data[code]
            (pnf_joints, pnf_indexes, pnf_pmmask) = lines.get_pnf(high, low, close)
            (avg, bollp2, bollm2) = lines.get_bollinger(close)
            (pnf_indexes, pnf_pmmask) = self.add_mid_joints(pnf_indexes, pnf_pmmask)

            for i in range(1, len(pnf_indexes)):
                jointi = pnf_indexes[i]
                if jointi >= MA_DAYS + WATCH_DAYS:
                    ylist = [0, 0, 1, 0, 0]
                    if pnf_pmmask[i] == -2:
                        ylist = [1, 0, 0, 0, 0]
                    if pnf_pmmask[i] == -1:
                        ylist = [0, 1, 0, 0, 0]
                    if pnf_pmmask[i] == 1:
                        ylist = [0, 0, 0, 1, 0]
                    if pnf_pmmask[i] == 2:
                        ylist = [0, 0, 0, 0, 1]
                    xlist = self.lines2image(
                        open[jointi - WATCH_DAYS + 1 : jointi + 1],
                        high[jointi - WATCH_DAYS + 1 : jointi + 1],
                        low[jointi - WATCH_DAYS + 1 : jointi + 1],
                        close[jointi - WATCH_DAYS + 1 : jointi + 1],
                        olines=[
                            avg[jointi - WATCH_DAYS + 1 : jointi + 1],
                            bollp2[jointi - WATCH_DAYS + 1 : jointi + 1],
                            bollm2[jointi - WATCH_DAYS + 1 : jointi + 1],
                        ],
                    )

                    ylist = np.array(ylist)
                    if len(xbatch) == 0:
                        xbatch = np.array([xlist])
                        ybatch = np.array([ylist])
                    else:
                        xbatch = np.append(xbatch, [xlist], axis=0)
                        ybatch = np.append(ybatch, [ylist], axis=0)
        return [xbatch, ybatch]
예제 #6
0
 def get_line_data(self, meigaras=[]):
     data = kf.get_kabuka(meigaras, self.startd, self.endd, True)
     xbatch = []
     ybatch = []
     for code in data.keys():
         (indexes, dates, open, high, low, close, volume) = data[code]
         (pnf_joints, pnf_indexes, pnf_pmmask) = lines.get_pnf(high, low, close)
         avg = lines.get_ma(close)
         (pnf_indexes, pnf_pmmask) = self.add_mid_joints(pnf_indexes, pnf_pmmask)
         
         for i in range(1, len(pnf_indexes)):
             jointi = pnf_indexes[i]
             if jointi >= MA_DAYS+WATCH_DAYS:
                 #xlist = open[jointi-5+1:jointi+1]
                 #xlist += high[jointi-5+1:jointi+1]
                 #xlist += low[jointi-5+1:jointi+1]
                 #xlist += close[jointi-5+1:jointi+1]
                 ylist = [0, 1, 0]
                 if pnf_pmmask[i] == -1:
                     ylist = [1, 0, 0]
                 if pnf_pmmask[i] == 1:
                     ylist = [0, 0, 1]
                 #xlist = self.normalize(np.array(xlist))
                 #xlist = np.append(xlist, self.normalize_volume(volume[jointi-5+1:jointi+1]))
                 #xlist = np.append(xlist, np.zeros(XSIZE-len(xlist)))
                 xlist = self.lines2image( 
                         open[jointi-WATCH_DAYS+1:jointi+1], 
                         high[jointi-WATCH_DAYS+1:jointi+1], 
                         low[jointi-WATCH_DAYS+1:jointi+1], 
                         close[jointi-WATCH_DAYS+1:jointi+1], 
                         olines=[avg[jointi-WATCH_DAYS+1:jointi+1]])
                 
                 ylist = np.array(ylist)
                 if len(xbatch) == 0:
                     xbatch = np.array([xlist])
                     ybatch = np.array([ylist])
                 else:
                     xbatch = np.append(xbatch, [xlist], axis=0)
                     ybatch = np.append(ybatch, [ylist], axis=0)
     return [xbatch, ybatch]
예제 #7
0
 def set_date(self, startd, endd):
     self.startd = startd
     self.endd = endd
     self.data = kf.get_kabuka(self.meigaras, self.startd, self.endd, True)