Esempio n. 1
0
def follow_seller(stock,buy_signal,xstop=25,ret=50,**kwargs):
    '''
        如果价格小于最近5日高点5%,则卖出
        xstop为根据买入价的止损
        ret为从高点向下的回退值
    '''
    t = stock.transaction

    #从顶下落处理,前5天的收盘/开盘的高者和今天的开盘的高者 回落ret之后

    #hhret = gmax(rollx(tmax(gmax(t[OPEN],t[CLOSE]),5),1),t[OPEN])* (1000-ret)/1000
    hhret = gmax(rollx(tmax(t[HIGH],5),1),t[OPEN])* (1000-ret)/1000
    
    #hhret = rollx(tmax(t[HIGH],5),1) * (1000-ret)/1000
    sdl = t[LOW] < hhret
 
    #止损处理2.5%
    stop_price = extend2next(rollx(stock.buyprice,1) * (1000-xstop)/1000)
    stopl = t[LOW] < stop_price

    cut_price = gmin(gmax(hhret,stop_price),t[HIGH])    #首先,止损线和退回线高者先被触及,同时,穿越时可能跳低,所以找与t[HIGH]的低点
    cut_signal = gor(sdl,stopl)

    cut_signal = select([t[VOLUME]>0],[cut_signal]) #默认为0,即未交易的日子卖出信号不能发出,否则会合并到下一交易日

    bs = gand(buy_signal,cut_signal)
    rbs = rollx(bs)

    sell_signal = select([bs],[0],default=cut_signal) + rbs #如果当日冲销,则后推一日,但如果前一日也是当日,则信号被屏蔽

    stock.sellprice = select([cut_signal],[cut_price],default=t[OPEN])
    #止损和退回用cut_price, 当日卖出信号平移用开盘价,停牌平移用开盘价

    return cut_signal
Esempio n. 2
0
def prepare_up1(stock):
    linelog('prepare hour:%s' % stock.code)
    #up = stock.hour * 10000 / rollx(stock.hour,1) >= 10200
    down =stock.hour_high - stock.hour < (stock.hour-stock.hour_open)*2/3
    ol = stock.hour > stock.hour_open
    tk = stock.hour_low > rollx(stock.hour_high)
    up = stock.hour * 10000 / gmin(rollx(stock.hour,1),stock.hour_open) > 10200
    stock.up1 =  xfollow(hour2day1(gand(up,down,ol,tk)),stock.transaction[VOLUME])
    stock.open2 = hour2day2(stock.hour_open)
Esempio n. 3
0
def prepare_up1(stock):
    linelog('prepare hour:%s' % stock.code)
    #up = stock.hour * 10000 / rollx(stock.hour,1) >= 10200
    down = stock.hour_high - stock.hour < (stock.hour -
                                           stock.hour_open) * 2 / 3
    ol = stock.hour > stock.hour_open
    tk = stock.hour_low > rollx(stock.hour_high)
    up = stock.hour * 10000 / gmin(rollx(stock.hour, 1),
                                   stock.hour_open) > 10200
    stock.up1 = xfollow(hour2day1(gand(up, down, ol, tk)),
                        stock.transaction[VOLUME])
    stock.open2 = hour2day2(stock.hour_open)
Esempio n. 4
0
def follow_seller(stock, buy_signal, xstop=25, ret=50, **kwargs):
    '''
        如果价格小于最近5日高点5%,则卖出
        xstop为根据买入价的止损
        ret为从高点向下的回退值
    '''
    t = stock.transaction

    #从顶下落处理,前5天的收盘/开盘的高者和今天的开盘的高者 回落ret之后

    #hhret = gmax(rollx(tmax(gmax(t[OPEN],t[CLOSE]),5),1),t[OPEN])* (1000-ret)/1000
    hhret = gmax(rollx(tmax(t[HIGH], 5), 1), t[OPEN]) * (1000 - ret) / 1000

    #hhret = rollx(tmax(t[HIGH],5),1) * (1000-ret)/1000
    sdl = t[LOW] < hhret

    #止损处理2.5%
    stop_price = extend2next(rollx(stock.buyprice, 1) * (1000 - xstop) / 1000)
    stopl = t[LOW] < stop_price

    cut_price = gmin(gmax(hhret, stop_price),
                     t[HIGH])  #首先,止损线和退回线高者先被触及,同时,穿越时可能跳低,所以找与t[HIGH]的低点
    cut_signal = gor(sdl, stopl)

    cut_signal = select([t[VOLUME] > 0],
                        [cut_signal])  #默认为0,即未交易的日子卖出信号不能发出,否则会合并到下一交易日

    bs = gand(buy_signal, cut_signal)
    rbs = rollx(bs)

    sell_signal = select(
        [bs], [0], default=cut_signal) + rbs  #如果当日冲销,则后推一日,但如果前一日也是当日,则信号被屏蔽

    stock.sellprice = select([cut_signal], [cut_price], default=t[OPEN])
    #止损和退回用cut_price, 当日卖出信号平移用开盘价,停牌平移用开盘价

    return cut_signal
Esempio n. 5
0
def up_seller(stock, buy_signal, xstop=25, ret=50, **kwargs):
    '''
        如果买入日为阴线,则开盘卖出
        如果价格小于最近5日高点5%,则卖出
        xstop为根据买入价的止损
        ret为从高点向下的回退值
    '''
    t = stock.transaction

    #阴线处理
    sol = rollx(gand(buy_signal, t[CLOSE] < t[OPEN]), 1)

    #从顶下落处理,前5天的收盘/开盘的高者和今天的开盘的高者 回落ret之后

    #hhret = gmax(rollx(tmax(gmax(t[OPEN],t[CLOSE]),5),1),t[OPEN])* (1000-ret)/1000
    hhret = gmax(rollx(tmax(t[HIGH], 5), 1), t[OPEN]) * (1000 - ret) / 1000

    sdl = t[LOW] < hhret

    #止损处理2.5%
    stop_price = extend2next(rollx(stock.buyprice, 1) * (1000 - xstop) /
                             1000)  #要求buyprice只有在buyer日才有数据,否则extend2next无意义
    stopl = t[LOW] < stop_price

    cut_price = gmin(gmax(hhret, stop_price),
                     t[HIGH])  #首先,止损线和退回线高者先被触及,同时,穿越时可能跳低,所以找与t[HIGH]的低点
    cut_signal = gor(sdl, stopl)

    cut_signal = select([t[VOLUME] > 0],
                        [cut_signal])  #默认为0,即未交易的日子卖出信号不能发出,否则会合并到下一交易日

    ssignal = gor(sol, cut_signal)
    stock.sellprice = select([cut_signal], [cut_price], default=t[OPEN])
    #止损和退回用cut_price, 阴线出局和停牌平移都用开盘价

    return ssignal
Esempio n. 6
-1
def up_seller(stock,buy_signal,xstop=25,ret=50,**kwargs):
    '''
        如果买入日为阴线,则开盘卖出
        如果价格小于最近5日高点5%,则卖出
        xstop为根据买入价的止损
        ret为从高点向下的回退值
    '''
    t = stock.transaction

    #阴线处理
    sol = rollx(gand(buy_signal,t[CLOSE] < t[OPEN]),1)

    #从顶下落处理,前5天的收盘/开盘的高者和今天的开盘的高者 回落ret之后

    #hhret = gmax(rollx(tmax(gmax(t[OPEN],t[CLOSE]),5),1),t[OPEN])* (1000-ret)/1000
    hhret = gmax(rollx(tmax(t[HIGH],5),1),t[OPEN])* (1000-ret)/1000
   
    sdl = t[LOW] < hhret
 
    #止损处理2.5%
    stop_price = extend2next(rollx(stock.buyprice,1) * (1000-xstop)/1000)   #要求buyprice只有在buyer日才有数据,否则extend2next无意义
    stopl = t[LOW] < stop_price

    cut_price = gmin(gmax(hhret,stop_price),t[HIGH])    #首先,止损线和退回线高者先被触及,同时,穿越时可能跳低,所以找与t[HIGH]的低点
    cut_signal = gor(sdl,stopl)

    cut_signal = select([t[VOLUME]>0],[cut_signal]) #默认为0,即未交易的日子卖出信号不能发出,否则会合并到下一交易日


    ssignal = gor(sol,cut_signal)
    stock.sellprice = select([cut_signal],[cut_price],default=t[OPEN])
    #止损和退回用cut_price, 阴线出局和停牌平移都用开盘价

    return ssignal