Example #1
0
def lwr(shigh,slow,sclose,n=9,m=3):
    lowv = tmin(slow,n)
    highv = tmax(shigh,n)
    rsv = (highv-sclose)*100 / (highv-lowv)
    lwr1 = sma(rsv,m,1)
    lwr2 = sma(lwr1,m,1)
    return lwr1,lwr2
Example #2
0
def skdj(shigh,slow,sclose,n=9,m=3):
    lowv = tmin(slow,n)
    highv = tmax(shigh,n)
    rsv = cexpma((sclose-lowv)*100/(highv-lowv),m)
    k = cexpma(rsv,m)
    d = ma(k,m)
    return k,d
Example #3
0
def lwr(shigh, slow, sclose, n=9, m=3):
    lowv = tmin(slow, n)
    highv = tmax(shigh, n)
    rsv = (highv - sclose) * 100 / (highv - lowv)
    lwr1 = sma(rsv, m, 1)
    lwr2 = sma(lwr1, m, 1)
    return lwr1, lwr2
Example #4
0
def skdj(shigh, slow, sclose, n=9, m=3):
    lowv = tmin(slow, n)
    highv = tmax(shigh, n)
    rsv = cexpma((sclose - lowv) * 100 / (highv - lowv), m)
    k = cexpma(rsv, m)
    d = ma(k, m)
    return k, d
Example #5
0
def wms(tclose,thigh,tlow,length):
    ''' 威廉指标
        可单独使用,同时也被kdj用到
    '''
    assert len(tclose) == len(thigh) and len(tclose) == len(tlow)
    lmax = tmax(thigh,length)
    lmin = tmin(tlow,length)
    rev = np.zeros_like(tclose)
    for i in xrange(len(tclose)):
        cmax,cmin = lmax[i],lmin[i]
        rev[i] = BASE if cmax==cmin else (tclose[i]-cmin) * BASE/(cmax-cmin)
    return rev   
Example #6
0
def wms(tclose, thigh, tlow, length):
    ''' 威廉指标
        可单独使用,同时也被kdj用到
    '''
    assert len(tclose) == len(thigh) and len(tclose) == len(tlow)
    lmax = tmax(thigh, length)
    lmin = tmin(tlow, length)
    rev = np.zeros_like(tclose)
    for i in xrange(len(tclose)):
        cmax, cmin = lmax[i], lmin[i]
        rev[i] = BASE if cmax == cmin else (tclose[i] - cmin) * BASE / (cmax -
                                                                        cmin)
    return rev
Example #7
0
def mm_ratio(sclose,shigh,slow,satr,covered=1):
    ''' 计算标准化的最大有利变动(MFE)/最大不利变动(MAE)
        即以当日为基准,计算covered内AMFE=(最大值-当日值)/atr和(当日值-最小值)/atr
        用于优势率e_ratio的计算:
            所有信号的CMFE之和/所有信号的CMAE之和 (信号次数被约掉)
            应当用这种方式,而不是单独计算CMFE/CMAE然后求平均
            比如一次是2/1,另一次是1/2,如果单独求比例然后平均,则e_ratio=(2+0.5)/2=1.25
                而先求平均再除,则是 (2+1)/(1+2) = 1
                显然后者是正常情形
        这是一个future函数, 正因为有左移的原因,所以最后covered的数据是失准的,需要处理掉,失灭为准
    '''
    m_max = rollx(tmax(sclose,covered),-covered)  #未来数据左移
    m_min = rollx(tmin(sclose,covered),-covered)  #未来数据左移
    #print m_min,tmin(sclose,covered)
    amfe = (m_max - sclose) * BASE / satr      #可能出现m_max[i] < sclose[i]的情况,如当日之后的covered内sclose一直下行
    amae = (sclose - m_min) * BASE / satr      #可能出现m_min[i] > sclose[i]的情况,如当日之后的covered内sclose一直上行
    amfe[-covered:] = amae[-covered:] = 0
    #print amfe.tolist(),amae.tolist()
    return amfe,amae
Example #8
0
def mm_ratio(sclose, shigh, slow, satr, covered=1):
    ''' 计算标准化的最大有利变动(MFE)/最大不利变动(MAE)
        即以当日为基准,计算covered内AMFE=(最大值-当日值)/atr和(当日值-最小值)/atr
        用于优势率e_ratio的计算:
            所有信号的CMFE之和/所有信号的CMAE之和 (信号次数被约掉)
            应当用这种方式,而不是单独计算CMFE/CMAE然后求平均
            比如一次是2/1,另一次是1/2,如果单独求比例然后平均,则e_ratio=(2+0.5)/2=1.25
                而先求平均再除,则是 (2+1)/(1+2) = 1
                显然后者是正常情形
        这是一个future函数, 正因为有左移的原因,所以最后covered的数据是失准的,需要处理掉,失灭为准
    '''
    m_max = rollx(tmax(sclose, covered), -covered)  #未来数据左移
    m_min = rollx(tmin(sclose, covered), -covered)  #未来数据左移
    #print m_min,tmin(sclose,covered)
    amfe = (
        m_max - sclose
    ) * BASE / satr  #可能出现m_max[i] < sclose[i]的情况,如当日之后的covered内sclose一直下行
    amae = (
        sclose - m_min
    ) * BASE / satr  #可能出现m_min[i] > sclose[i]的情况,如当日之后的covered内sclose一直上行
    amfe[-covered:] = amae[-covered:] = 0
    #print amfe.tolist(),amae.tolist()
    return amfe, amae