Ejemplo n.º 1
0
def fup60b(stock):
    '''
        60分钟从负数上来的有失败上叉先导的第一次成功上叉
    '''
    t = stock.transaction
    linelog('%s:%s' % (fup60.__name__, stock.code))

    hzero = cached_zeros(len(stock.hour))

    pdiff, pdea = cmacd(stock.hour)

    cross0 = cross(hzero, pdiff)

    udcross = cross(pdea, pdiff)

    #失败上叉:最近5个周期内被下叉信号抵消,或者最近5个周期内出现第二个上叉信号(导致msum仍然>0)
    fcross = gand(
        udcross > 0,
        gor(
            rollx(msum(udcross, 5), -5) == 0,
            rollx(msum(udcross > 0, 5), -5) > 1))

    ucross = gand(udcross > 0, pdiff > 0, bnot(fcross))

    xsum1 = rsum(ucross, cross0)  #此时,第一个cross>0和第二个之间的位置被填满1
    xsum = rsum(xsum1, cross0)  #此时,只有第一个发生位为1

    signal = gand(equals(xsum, 1), pdiff > 0)

    return hour2day(signal)
Ejemplo n.º 2
0
def fup60b(stock):
    '''
        60分钟从负数上来的有失败上叉先导的第一次成功上叉
    '''
    t = stock.transaction
    linelog('%s:%s' % (fup60.__name__,stock.code))

    hzero =  cached_zeros(len(stock.hour))
    
    pdiff,pdea = cmacd(stock.hour)
    
    cross0 = cross(hzero,pdiff)

    udcross = cross(pdea,pdiff)

    #失败上叉:最近5个周期内被下叉信号抵消,或者最近5个周期内出现第二个上叉信号(导致msum仍然>0)
    fcross = gand(udcross>0,gor(rollx(msum(udcross,5),-5)==0,rollx(msum(udcross>0,5),-5)>1))

    ucross = gand(udcross>0,pdiff>0,bnot(fcross))

    xsum1 = rsum(ucross,cross0)  #此时,第一个cross>0和第二个之间的位置被填满1
    xsum = rsum(xsum1,cross0)   #此时,只有第一个发生位为1

    signal = gand(equals(xsum,1),pdiff>0)

    return hour2day(signal)
Ejemplo n.º 3
0
def adx2(sclose,shigh,slow,n=14,m=6):
    ''' 
        调整的算法, abs在ma之后取值
        直接根据sclose,shigh,slow计算adx的快捷函数
        n: 计算di时的平滑天数
        m: 计算adx时的平滑天数
    '''
    pdm,ndm = dm(shigh,slow)
    xtr = msum(tr(sclose,shigh,slow),n)
    pdi = msum(pdm,n)*10000/xtr
    ndi = msum(ndm,n)*10000/xtr
    adx = np.abs(ma((pdi-ndi)*10000/(pdi+ndi),m))
    #adxr = (adx + rollx(adx,m)) /2 
    return pdi,ndi,adx#,adxr
Ejemplo n.º 4
0
def adx0(sclose,shigh,slow,n=14,m=6):
    ''' 
        原始的adx计算方法
        直接根据sclose,shigh,slow计算adx的快捷函数
        n: 计算di时的平滑天数
        m: 计算adx时的平滑天数
    '''
    pdm,ndm = dm(shigh,slow)
    xtr = msum(tr(sclose,shigh,slow),n)
    pdi = msum(pdm,n)*10000/xtr
    ndi = msum(ndm,n)*10000/xtr
    adx = ma(np.abs((pdi-ndi)*10000/(pdi+ndi)),m)
    #adxr = (adx + rollx(adx,m)) /2 
    return pdi,ndi,adx#,adxr
Ejemplo n.º 5
0
def adx2(sclose, shigh, slow, n=14, m=6):
    ''' 
        调整的算法, abs在ma之后取值
        直接根据sclose,shigh,slow计算adx的快捷函数
        n: 计算di时的平滑天数
        m: 计算adx时的平滑天数
    '''
    pdm, ndm = dm(shigh, slow)
    xtr = msum(tr(sclose, shigh, slow), n)
    pdi = msum(pdm, n) * 10000 / xtr
    ndi = msum(ndm, n) * 10000 / xtr
    adx = np.abs(ma((pdi - ndi) * 10000 / (pdi + ndi), m))
    #adxr = (adx + rollx(adx,m)) /2
    return pdi, ndi, adx  #,adxr
Ejemplo n.º 6
0
def adx0(sclose, shigh, slow, n=14, m=6):
    ''' 
        原始的adx计算方法
        直接根据sclose,shigh,slow计算adx的快捷函数
        n: 计算di时的平滑天数
        m: 计算adx时的平滑天数
    '''
    pdm, ndm = dm(shigh, slow)
    xtr = msum(tr(sclose, shigh, slow), n)
    pdi = msum(pdm, n) * 10000 / xtr
    ndi = msum(ndm, n) * 10000 / xtr
    adx = ma(np.abs((pdi - ndi) * 10000 / (pdi + ndi)), m)
    #adxr = (adx + rollx(adx,m)) /2
    return pdi, ndi, adx  #,adxr
Ejemplo n.º 7
0
def hmxru(stock):
    ''' 成交量分配后的macd,采用supdown
        vfilter = svma < vma * 2/3    
        评估:总盈亏值=4813,交易次数=14  期望值=5444
                总盈亏率(1/1000)=4813,平均盈亏率(1/1000)=343,盈利交易率(1/1000)=928
                平均持仓时间=50,持仓效率(1/1000000)=6860
                赢利次数=13,赢利总值=4876
                亏损次数=1,亏损总值=63
                平盘次数=0
        vfilter = gand(svma<vma*2/3,t[VOLUME]<=vma*2/3)
        评估:总盈亏值=3810,交易次数=8   期望值=1000
                总盈亏率(1/1000)=3810,平均盈亏率(1/1000)=476,盈利交易率(1/1000)=1000
                平均持仓时间=65,持仓效率(1/1000000)=7323
                赢利次数=8,赢利总值=3810
                亏损次数=0,亏损总值=0
                平盘次数=0

    '''
    t = stock.transaction
    mxc = stock.xru
    vma = ma(t[VOLUME],30)
    svma = ma(t[VOLUME],3)
    vfilter = gand(svma<vma*2/3,t[VOLUME]<=vma*2/3)
    #vfilter = gand(svma<vma*2/3)
    xatr = stock.atr * BASE / t[CLOSE]     
    ma0 = ma(t[CLOSE],3)
    ndown = bnot(gand(t[CLOSE]<ma0,ma0<stock.ma1,stock.ma1<stock.ma2))
    s = stock
    sv = greater(msum(t[VOLUME] > 0,120),100)   #确保新股上市前100天无信号    
    signal = gand(mxc,stock.above,vfilter,strend(stock.ma4)>0,stock.t5,xatr>=60,stock.magic,stock.ma1<stock.ma2,stock.ma1>stock.ma3,ndown)


    linelog(stock.code)
    return signal
Ejemplo n.º 8
0
def hmacd2(stock):
    ''' 无大用
    '''
    t = stock.transaction    
    linelog(stock.code)
    vma = ma(t[VOLUME],30)
    svma = ma(t[VOLUME],3)
    vfilter = gand(svma<vma*2/3)
    #vfilter = gand(svma<vma*3/4,t[VOLUME]<vma)
    #vfilter = gand(svma<vma*3/5,t[VOLUME]>0,t[VOLUME]>vma*1/2)#,t[VOLUME]<vma*3/2)   #2/3        

    xatr = stock.atr * BASE / t[CLOSE]
    cf = (t[OPEN]-t[LOW] + t[HIGH]-t[CLOSE])*1000 / (t[HIGH]-t[LOW])   #向下的动力  
    mcf = ma(cf,7)
    
    #ma3 = ma(t[CLOSE],3)
    #ma7 = ma(t[CLOSE],7)
    #c37 = gand(cross(ma7,ma3)>0,strend(ma3)>0)
    #sc = sfollow(stock.hdev,c37,3)
    
    ss = gand(msum(stock.hup,5)>1,stock.hup)    #5日内的第二次上叉

    s=stock
    #signal = gand(stock.hdev,stock.t5,vfilter,mcf>1000,stock.g5<stock.g60,s.g20 >= s.g60,s.g60 >= s.g120,s.g120 >= s.g250,s.g20<=8000)
    #magic = gand(s.g20 >= s.g60,s.g60 <= s.g120,s.g120 <= s.g250)#,s.g20<=8000)
    magic = gand(s.g5>s.g60,s.g20 >= s.g60,s.g60 <= s.g120,s.g20<=8000)
    signal = gand(ss,stock.t5,stock.t4,vfilter,mcf<900,xatr>60,magic)
    return signal
Ejemplo n.º 9
0
def mfi(source,vol,length=13):
    '''
        mfi指标
        source = (close+high+low)/3

        TYP := (HIGH + LOW + CLOSE)/3;
        V1=SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)/SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
        MFI:100-(100/(1+V1))
        设定 PV = SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)
             NV = SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
        则MFI = 100PV/(PV+NV)
        
    '''
    pvol = np.select([source>rollx(source)],[vol])
    nvol = np.select([source<rollx(source)],[vol])
    spv = msum(pvol,length)
    snv = msum(nvol,length)
    result = (BASE*spv+(spv+snv)/2)/(spv+snv)   #四舍五入
    return result
Ejemplo n.º 10
0
def mfi(source, vol, length=13):
    '''
        mfi指标
        source = (close+high+low)/3

        TYP := (HIGH + LOW + CLOSE)/3;
        V1=SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)/SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
        MFI:100-(100/(1+V1))
        设定 PV = SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)
             NV = SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
        则MFI = 100PV/(PV+NV)
        
    '''
    pvol = np.select([source > rollx(source)], [vol])
    nvol = np.select([source < rollx(source)], [vol])
    spv = msum(pvol, length)
    snv = msum(nvol, length)
    result = (BASE * spv + (spv + snv) / 2) / (spv + snv)  #四舍五入
    return result
Ejemplo n.º 11
0
def efficient_rate(source,covered=10):
    ''' 效率函数. 来源: smarter trading (略有不同,书中效率值为abs值,而此函数以负表示下降效率)
        根据单一source计算(存在其他方式的效率计算方法,但在此如此计算)
        先计算n日内每日波动幅度amplitude = abs(source[i]-source[i-1]),然后根据n求和为s_amplitude
        然后计算n日总波幅t_amplitude = source[i]-source[i-n]
        当日效率系数 = t_amplitude / s_amplitude
        第covered+1个数据(下标为covered)开始有效,之前的全部置0
        效率值有正有负,为负表明是下降效率
    '''
    assert covered > 0
    if(len(source) <= covered):
        return np.zeros_like(source)
    sdiff = np.abs(subd(source))
    ssum = msum(sdiff,covered)
    sdiffc = subd(source,covered)
    rev = sdiffc * BASE / ssum
    rev[:covered] = 0
    return rev
Ejemplo n.º 12
0
def efficient_rate(source, covered=10):
    ''' 效率函数. 来源: smarter trading (略有不同,书中效率值为abs值,而此函数以负表示下降效率)
        根据单一source计算(存在其他方式的效率计算方法,但在此如此计算)
        先计算n日内每日波动幅度amplitude = abs(source[i]-source[i-1]),然后根据n求和为s_amplitude
        然后计算n日总波幅t_amplitude = source[i]-source[i-n]
        当日效率系数 = t_amplitude / s_amplitude
        第covered+1个数据(下标为covered)开始有效,之前的全部置0
        效率值有正有负,为负表明是下降效率
    '''
    assert covered > 0
    if (len(source) <= covered):
        return np.zeros_like(source)
    sdiff = np.abs(subd(source))
    ssum = msum(sdiff, covered)
    sdiffc = subd(source, covered)
    rev = sdiffc * BASE / ssum
    rev[:covered] = 0
    return rev
Ejemplo n.º 13
0
def psy(source,length=12):
    ''' 心理线PSY:COUNT(CLOSE>REF(CLOSE,1),N)/N*100
    '''
    s = greater(source,rollx(source))
    rev = (msum(s,length) * BASE + length/2)/ length
    return rev
Ejemplo n.º 14
0
def psy(source, length=12):
    ''' 心理线PSY:COUNT(CLOSE>REF(CLOSE,1),N)/N*100
    '''
    s = greater(source, rollx(source))
    rev = (msum(s, length) * BASE + length / 2) / length
    return rev