def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'dmt' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() mafile = MA(code, cycle) self.madata = mafile.getValues() pass
def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'Rng' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() kdjfile = KDJ(code, cycle) self.kdjdata = kdjfile.getValues() pass
class MA(Qualification): def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'Ma' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() def calcValue(self, index, d_data=None, q_data=None): if d_data == None: d_data = self.d_data if q_data == None: q_data = self.q_data level = [5, 18, 30, 60] value = [ d_data[index][0], ] for li in range(0, len(level)): if level[li] <= index: sum = 0.0 for i in range(index - level[li] + 1, index + 1): sum = sum + d_data[i][4] value.append(round((sum / level[li]), 2)) else: value.append(None) return tuple(value)
class DLT(Qualification): def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'Dlt' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() def calcValue(self, index, d_data=None, q_data=None): if d_data == None: d_data = self.d_data if q_data == None: q_data = self.q_data level = [5, 10, 30, 60] value = [ d_data[index][0], ] for li in range(0, len(level)): if 2 * level[li] <= index: v = 0.0 for ii in range(0, level[li]): v += (d_data[index - ii][4] - d_data[index - ii - level[li]][4]) / level[li] av = v / level[li] value.append(av) else: value.append(None) return tuple(value)
def __init__(self, code, cycle='D', cqcx=False): Qualification.__init__(self, code, 'KDJ' + '_' + cycle, cqcx) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx) self.d_data = self.dfile.getData() if cycle == 'H': self.dfile = HourFile(code) self.d_data = self.dfile.getData() if cycle == 'Q': self.dfile = QuarterFile(code) self.d_data = self.dfile.getData()
class MACD(Qualification): def __init__(self, code, cycle='D', cqcx=False): Qualification.__init__(self, code, 'MACD' + '_' + cycle, cqcx) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx) self.d_data = self.dfile.getData() def calcValue(self, index, d_data=None, q_data=None): #q_data = self.q_data + self.appends if d_data == None: d_data = self.d_data if q_data == None: q_data = self.q_data c = d_data[index][4] pre_ema12 = 0 pre_ema26 = 0 pre_dea = 0 if self.cycle == 'W': for i in range(len(q_data) - 1, -1, -1): if q_data[i][0].strftime('%W') != d_data[index][0].strftime( '%W'): pre_ema12 = q_data[i][1] pre_ema26 = q_data[i][2] pre_dif = q_data[i][3] break elif self.cycle == 'M': for i in range(len(q_data) - 1, -1, -1): if q_data[i][0].strftime('%M') != d_data[index][0].strftime( '%M'): pre_ema12 = q_data[i][1] pre_ema26 = q_data[i][2] pre_dea = q_data[i][4] break else: if len(q_data) > 1: pre_ema12 = q_data[-1][1] pre_ema26 = q_data[-1][2] pre_dif = q_data[-1][3] pre_dea = q_data[-1][4] ema12 = EMA(pre_ema12, c, 12) ema26 = EMA(pre_ema26, c, 26) dif = ema12 - ema26 #print(pre_dea) dea = EMA(pre_dea, dif, 9) macd = (dif - dea) * 2.0 #print((d_data[-1][0],rsv,k,d,j)) return (d_data[index][0], ema12, ema26, dif, dea, macd)
class BLC(Qualification): def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'Blc' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() def calcValue(self, index, d_data=None, q_data=None): if d_data == None: d_data = self.d_data if q_data == None: q_data = self.q_data value = [ d_data[index][0], ] v0 = VLV(d_data, index, 5, 3) if v0[0] == index: return (None, ) v1 = VLV(d_data, v0[0], 5, 3) if v1[0] == v0[0]: return (None, ) value.append(d_data[v1[0]][4]) mi = min([l for d, o, h, l, c, a, v in d_data[v1[0]:v0[0] + 1]]) ma = max([h for d, o, h, l, c, a, v in d_data[v1[0]:v0[0] + 1]]) value.append(ma) value.append(mi) value.append(d_data[v0[0]][4]) vol = 0 amount = 0.0 for dta in d_data[v1[0]:v0[0] + 1]: vol += dta[6] amount += dta[5] value.append(amount) value.append(vol) #print(value) value.append(v0[0]) return tuple(value)
class DTMA(Qualification): def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'dmt' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() mafile = MA(code, cycle) self.madata = mafile.getValues() pass def calcValue(self, index, d_data=None, q_data=None): if d_data == None: d_data = self.d_data if q_data == None: q_data = self.q_data d_date = d_data[index][0] d_close = d_data[index][4] value = [d_date, d_close] maindex = getIndexOfSerial(self.madata, d_date) if maindex == -1: return (None, ) ma = self.madata[maindex] r1 = 1 / (1 / 5) * ((1 / 5 * ma[1])) r2 = 1 / (1 / 5 + 1 / 10) * ((1 / 5 * ma[1]) + (1 / 10 * ma[2])) r3 = 1 / (1 / 5 + 1 / 10 + 1 / 30) * ((1 / 5 * ma[1]) + (1 / 10 * ma[2]) + (1 / 30 * ma[3])) r4 = 1 / (1 / 5 + 1 / 10 + 1 / 30 + 1 / 60) * ((1 / 5 * ma[1]) + (1 / 10 * ma[2]) + (1 / 30 * ma[3]) + (1 / 60 * ma[4])) value.append(r1) value.append(r2) value.append(r3) value.append(r4) return tuple(value)
def __init__(self, code, cycle='D', cqcx=False): Qualification.__init__(self, code, 'MACD' + '_' + cycle, cqcx) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx) self.d_data = self.dfile.getData()
class RNG(Qualification): def __init__(self, code, cycle='D'): Qualification.__init__(self, code, 'Rng' + '_' + cycle, cqcx=False) self.cycle = cycle if cycle == 'W': self.dfile = WeeklyFile(code, cqcx=False) self.d_data = self.dfile.getData() kdjfile = KDJ(code, cycle) self.kdjdata = kdjfile.getValues() pass def calcValue(self, index, d_data=None, q_data=None): if d_data == None: d_data = self.d_data if q_data == None: q_data = self.q_data d_date = d_data[index][0] d_close = d_data[index][4] value = [d_date, d_close] kdjindex = getIndexOfSerial(self.kdjdata, d_date) if kdjindex == -1: return (None, ) rl0 = None rh0 = None rl1 = None rh1 = None findl = True findkdjindex0 = kdjindex if self.kdjdata[kdjindex][2] < self.kdjdata[kdjindex][3]: findl = False for i in range(40): if findl: findkdjindex1 = VLV(self.kdjdata, findkdjindex0, 4, 3)[0] else: findkdjindex1 = VHV(self.kdjdata, findkdjindex0, 4, 3)[0] if findkdjindex0 == findkdjindex1: return (None, ) findkdjindex0 = findkdjindex1 findkdj = self.kdjdata[findkdjindex0] finddaily = self.d_data[getIndexOfSerial(self.d_data, findkdj[0])] #print(finddaily) if findl: if findkdj[2] > findkdj[3]: continue findl = False if (d_close > finddaily[4]): #(d_close / 1.05 < finddaily[4]) & if (rl0 == None): rl0 = finddaily[4] elif (rl1 == None): rl1 = finddaily[4] else: if findkdj[2] < findkdj[3]: continue findl = True if (d_close < finddaily[4]): # (d_close * 1.05 > finddaily[4]) & if (rh0 == None): rh0 = finddaily[4] elif (rh1 == None): rh1 = finddaily[4] if (not (rh1 == None)) & (not (rl1 == None)): break if (rh1 == None) | (rl1 == None): return (None, ) value.append(rl0) value.append(rh0) value.append(rl1) value.append(rh1) return tuple(value)