Administrator
2023-03-27 8535f56dbf6e410b4a09f02f95d4d49bcc8753f2
code_nature_analyse.py
@@ -47,15 +47,17 @@
# 设置历史K线
def set_record_datas(code, limit_up_price, record_datas):
    k_format = get_k_format(limit_up_price, record_datas)
    k_format = get_k_format(float(limit_up_price), record_datas)
    CodeNatureRecordManager.save_k_format(code, k_format)
    natures = get_nature(record_datas)
    CodeNatureRecordManager.save_nature(code, natures)
# 获取K线形态
# 返回 (15个交易日涨幅是否大于24.9%,是否破前高,是否超跌,是否接近前高,是否N,是否V)
def get_k_format(limit_up_price, record_datas):
    p1 = get_lowest_price_rate(record_datas) >= 0.249
    p1_data = get_lowest_price_rate(record_datas)
    p1 = p1_data[0] >= 0.249, p1_data[1]
    p2 = __is_new_top(limit_up_price, record_datas)
    p3 = __is_lowest(record_datas)
    p4 = __is_near_new_top(limit_up_price, record_datas)
@@ -63,13 +65,13 @@
    p6 = __is_v_model(record_datas)
    # N字型包含了N字型
    if p5:
        p6 = False
        p6 = False, ''
    return (p1, p2, p3, p4, p5, p6)
# 是否具有K线形态
def is_has_k_format(limit_up_price, record_datas):
    is_too_high, is_new_top, is_lowest, is_near_new_top, is_n, is_v = get_k_format(limit_up_price, record_datas)
    is_too_high, is_new_top, is_lowest, is_near_new_top, is_n, is_v = get_k_format(float(limit_up_price), record_datas)
    # if is_too_high:
    #     return False, "15个交易日涨幅大于24.9%"
@@ -91,7 +93,7 @@
def get_nature(record_datas):
    limit_up = is_have_limit_up(record_datas)
    premium_rate = get_limit_up_premium_rate(record_datas)
    result = (limit_up, premium_rate >= 0.6)
    result = (limit_up, premium_rate >= 0.6,premium_rate)
    return result
@@ -101,10 +103,12 @@
    datas.sort(key=lambda x: x["bob"])
    datas = datas[-15:]
    low_price = datas[0]["close"]
    date = None
    for data in datas:
        if low_price > data["close"]:
            low_price = data["close"]
    return (datas[-1]["close"] - low_price) / low_price
            date = data['bob'].strftime("%Y-%m-%d")
    return (datas[-1]["close"] - low_price) / low_price, date
# 是否有涨停
@@ -114,12 +118,8 @@
        item = datas[i]
        limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"]))
        if abs(limit_up_price - item["close"]) < 0.01:
            return True
    return False
def is_have_limit_up_by_code(code):
    return False
            return True, item['bob'].strftime("%Y-%m-%d")
    return False, ''
# 是否破前高
@@ -131,9 +131,13 @@
    for data in datas:
        if max_price < data["high"]:
            max_price = data["high"]
    if limit_up_price > max_price:
        return True
    return False
    if limit_up_price >= max_price:
        return True, ''
    return False, ''
def is_new_top(limit_up_price, datas):
    return __is_new_top(float(limit_up_price), datas)[0]
# 接近新高
@@ -142,15 +146,33 @@
    datas.sort(key=lambda x: x["bob"])
    datas = datas[-80:]
    max_volume = 0
    price = 0
    for data in datas:
    max_volume_index = 0
    for index in range(0, len(datas)):
        data = datas[index]
        if max_volume < data["volume"]:
            max_volume = data["volume"]
            max_volume_index = index
    price = 0
    price_index = 0
    for index in range(max_volume_index, len(datas)):
        data = datas[index]
        if data["high"] > price:
            price = data["high"]
            price_index = index
    index = price_index
    # 最大量当日最高价比当日之后的最高价涨幅在15%以内
    if (price - datas[max_volume_index]["high"]) / datas[max_volume_index]["high"] < 0.15:
        price = datas[max_volume_index]["high"]
        index = max_volume_index
    print(max_volume)
    if limit_up_price < price and (price - limit_up_price) / limit_up_price < 0.03:
        return True
    return False
    rate = (price - limit_up_price) / limit_up_price
    if 0 < rate < 0.03:
        return True, datas[index]['bob'].strftime("%Y-%m-%d")
    return False, ''
# 是否跌破箱体
@@ -163,13 +185,15 @@
        if min_price > data["low"]:
            min_price = data["low"]
    # 近5天内的最低价
    date = ''
    min_price_5 = 10000
    for data in datas[-5:]:
        if min_price_5 > data["low"]:
            min_price_5 = data["low"]
            date = data['bob']
    if abs(min_price_5 - min_price) / min_price < 0.015:
        return True
    return False
        return True, date.strftime("%Y-%m-%d")
    return False, ''
# N字形
@@ -192,8 +216,8 @@
                if min_price > item["low"]:
                    min_price = item["low"]
        if max_price > min_price:
            return True
    return False
            return True, ''
    return False, ''
# V字形
@@ -215,9 +239,9 @@
            min_price_index = i
    if (max_price - min_price) / max_price > 0.249:
        return True
        return True, ''
    return False
    return False, ''
# 首板涨停溢价率
@@ -234,9 +258,13 @@
            rate = (datas[i + 1]["high"] - datas[i + 1]["pre_close"]) / datas[i + 1]["pre_close"]
            first_rate_list.append(rate)
    if not first_rate_list:
        return 1
        return 0
    count = 0
    for rate in first_rate_list:
        if rate >= 0.01:
            count += 1
    return count / len(first_rate_list)
if __name__ == "__main__":
    print(CodeNatureRecordManager.get_k_format("603717"))