예제 #1
0
def stock_analyze(basic, kdata, policy_args):
    ### 基本条件选取
    get_index = include_analyze(basic, kdata, policy_args)
    if get_index is None:
        logger.debug("include_analyze() return None")
        return None
    else:
        [pick_index, take_index] = get_index

    ### 排它条件过滤
    if exclude_analyze(basic, kdata, pick_index, take_index, policy_args):
        logger.debug("exclude_analyze() return True")
        return None

    ### 构造结果
    result = {}
    result[dogen.RST_COL_CODE] = basic.name  # 股票代码
    result[dogen.RST_COL_NAME] = basic[dogen.NAME]  #  证券简写
    result[dogen.RST_COL_INDUSTRY] = basic[dogen.INDUSTRY]
    result[dogen.RST_COL_TAKE_TRADE] = kdata.index[take_index]  # 命中交易日
    result[dogen.RST_COL_LAST_CLOSE] = kdata.iloc[0][dogen.P_CLOSE]  # 最后一日收盘价
    result[dogen.RST_COL_OUTSTANDING] = round(
        kdata.iloc[0][dogen.P_CLOSE] * basic[dogen.OUTSTANDING], 2)  # 流通市值
    result[dogen.RST_COL_SCORE] = score_analyze(basic, kdata, pick_index,
                                                take_index, policy_args)  # 打分
    result[dogen.RST_COL_MATCH_TIME] = dogen.datetime_now()  # 选中时间
    result[dogen.RST_COL_INDEX] = '%s_%s' % (
        basic.name, kdata.index[take_index])  # 唯一标识,用于持久化去重

    return result
예제 #2
0
def stock_analyze(basic, kdata, policy_args):
    ### 基本条件选取
    get_index = include_analyze(basic, kdata, policy_args)
    if get_index is None:
        logger.debug("include_analyze() return None")
        return None
    else:
        [pick_index, take_index] = get_index

    ### 排它条件过滤
    if exclude_analyze(basic, kdata, pick_index, take_index, policy_args):
        logger.debug("exclude_analyze() return True")
        return None

    rise_range = dogen.get_last_rise_range(kdata, 0, sIdx=pick_index)
    if rise_range is not None:
        [pick_index, max_index, inc_close, get_lhigh, tmp_index] = rise_range

    ### 构造结果
    result = {}
    result[dogen.RST_COL_CODE] = basic.name  # 股票代码
    result[dogen.RST_COL_NAME] = basic[dogen.NAME]  #  证券简写
    result[dogen.RST_COL_INDUSTRY] = basic[dogen.INDUSTRY]
    result[dogen.RST_COL_START] = kdata.index[pick_index]
    result[dogen.RST_COL_TAKE_TRADE] = kdata.index[take_index]  # 命中交易日
    result[dogen.RST_COL_LAST_CLOSE] = kdata.iloc[0][dogen.P_CLOSE]  # 最后一日收盘价
    result[dogen.RST_COL_OUTSTANDING] = round(
        kdata.iloc[0][dogen.P_CLOSE] * basic[dogen.OUTSTANDING], 2)  # 流通市值
    result[dogen.RST_COL_INC_HL] = dogen.get_highlimit_trades(kdata,
                                                              eIdx=pick_index +
                                                              1).size
    result[dogen.RST_COL_SCORE] = score_analyze(basic, kdata, pick_index,
                                                take_index, policy_args)
    result[dogen.RST_COL_MATCH_TIME] = dogen.datetime_now()  # 选中时间
    result[dogen.RST_COL_INDEX] = '%s_%s' % (
        basic.name, kdata.index[take_index])  # 唯一标识,用于持久化去重

    return result
예제 #3
0
def __statistics_analyze(db, basic, kdata, save_result, args):
    """ 统计单只股票上涨区间

        参数说明:
            basic - 股票基本信息
            kdata - 股票交易数据
            mini_rise - 区间最小涨幅
            mini_hl - 区间最少涨停板数
    """
    ### 参数处理
    mini_rise = __parse_policy_args(args, MINI_RISE)
    mini_hl = __parse_policy_args(args, MINI_HL)

    ### 循环检查
    tmpId = 0
    match = []
    while True:
        rise_range = dogen.get_last_rise_range(kdata, mini_rise, max_fall=round(mini_rise/2, 2), sIdx=tmpId)
        if rise_range is None:
            break
        else:
            [min_index, max_index, inc_close, get_hl, tmpId] = rise_range

        ### 忽略不符合连板要求的区间
        outstanding   = None
        max_hl_serial = 0
        tmp_hl_serial = 0
        for temp_index in range(min_index, max_index-1, -1):
            if kdata.iloc[temp_index][dogen.P_CLOSE] < kdata.iloc[temp_index][dogen.L_HIGH]:
                tmp_hl_serial = 0
                continue
            tmp_hl_serial += 1
            if tmp_hl_serial > max_hl_serial:
                max_hl_serial = tmp_hl_serial
            if tmp_hl_serial > 2 and outstanding is None:
                outstanding = round(kdata.iloc[temp_index][dogen.P_CLOSE] * basic[dogen.OUTSTANDING], 2)
            pass
        if max_hl_serial < mini_hl:
            continue
            
        ### 保存区间结果
        result = {}
        result[dogen.RST_COL_CODE]        = basic.name
        result[dogen.RST_COL_NAME]        = basic[dogen.NAME] #  证券简写
        result[dogen.RST_COL_INDUSTRY]    = basic[dogen.INDUSTRY]
        result[dogen.RST_COL_START]       = kdata.index[min_index]
        result[dogen.RST_COL_END]         = kdata.index[max_index]
        result[dogen.RST_COL_START_CLOSE] = kdata.iloc[min_index][dogen.P_CLOSE] # 起始收盘价
        result[dogen.RST_COL_LAST_CLOSE]  = kdata.iloc[max_index][dogen.P_CLOSE] # 最高收盘价
        result[dogen.RST_COL_RISE_RATE]   = dogen.caculate_incr_percentage(result[dogen.RST_COL_LAST_CLOSE], result[dogen.RST_COL_START_CLOSE])
        result[dogen.RST_COL_INC_HL]      = get_hl
        result[dogen.RST_COL_OUTSTANDING] = outstanding # 流通市值
        result[dogen.RST_COL_MATCH_TIME]  = dogen.datetime_now() # 选中时间
        result[dogen.RST_COL_INDEX]       = '%s_%s' % (basic.name, kdata.index[min_index])

        match.append(result)

        ### 保存结果
        if save_result:
            rdata = db.lookup_statistics_largerise_range(cond={dogen.RST_COL_CODE:basic.name}, descending_by=dogen.RST_COL_START)
            if rdata is None or len(rdata)<=0:
                db.insert_statistics_largerise_range([result], key_name=dogen.RST_COL_INDEX)
                continue
            rlast = rdata[0]
            if rlast[dogen.RST_COL_END] < result[dogen.RST_COL_START]:
                db.insert_statistics_largerise_range([result], key_name=dogen.RST_COL_INDEX)
                continue
            ### 重叠合并
            tdata = kdata[(kdata.index > rlast[dogen.RST_COL_END])&(kdata.index <= result[dogen.RST_COL_END])]

            rlast[dogen.RST_COL_INC_HL] = rlast[dogen.RST_COL_INC_HL] + tdata[tdata[dogen.P_CLOSE]>=tdata[dogen.L_HIGH]].index.size
            rlast[dogen.RST_COL_END] = result[dogen.RST_COL_END]
            rlast[dogen.RST_COL_LAST_CLOSE] = result[dogen.RST_COL_LAST_CLOSE]
            rlast[dogen.RST_COL_RISE_RATE] = dogen.caculate_incr_percentage(rlast[dogen.RST_COL_LAST_CLOSE], rlast[dogen.RST_COL_START_CLOSE])
            rlast[dogen.RST_COL_MATCH_TIME] = result[dogen.RST_COL_MATCH_TIME]
            db.insert_statistics_largerise_range([rlast], key_name=dogen.RST_COL_INDEX)

    return match