Administrator
2024-01-15 40dc7735171fb0854cf0e03c9ea93c1234318a94
参考量距离计算
6个文件已修改
62 ■■■■ 已修改文件
code_attribute/code_volumn_manager.py 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/first_target_code_data_processor.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
output/code_info_output.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_code_attribute.py 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/init_data_util.py 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
code_attribute/code_volumn_manager.py
@@ -18,12 +18,13 @@
# 设置历史量
def set_histry_volumn(code, max60, yesterday, max60_day=''):
def set_histry_volumn(code, max60, yesterday, max60_day, max60_day_count):
    redis = __redis_manager.getRedis()
    global_util.max60_volumn[code] = (max60, max60_day)
    global_util.yesterday_volumn[code] = yesterday
    try:
        RedisUtils.setex_async(0, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)),
        RedisUtils.setex_async(0, "volumn_max60-{}".format(code), tool.get_expire(),
                               json.dumps((max60, max60_day, max60_day_count)),
                               auto_free=False)
        RedisUtils.setex_async(0, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False)
    finally:
@@ -98,14 +99,15 @@
# 获取量参考日期
# 返回(参考量日期,距今的交易日个数)
def get_volume_refer_date(code):
    max60, yesterday = get_histry_volumn(code)
    if max60 is None or yesterday is None:
        raise Exception("获取失败")
    if int(max60[0]) >= int(yesterday):
        return max60[1]
        return max60[1], max60[2]
    else:
        return "上个交易日"
        return "上个交易日", 0
# 获取量比索引
code_attribute/first_target_code_data_processor.py
@@ -123,7 +123,7 @@
                                                              limit_up_price,
                                                              volumes_data[:90]))
                logger_first_code_record.info("{} 获取到首板60天最大量:{}", code, volumes)
                code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2])
                code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2],volumes[3])
                # 保存K线形态
                k_format = code_nature_analyse.get_k_format(limit_up_price, volumes_data)
l2/l2_data_manager_new.py
@@ -989,6 +989,14 @@
        has_limit_down_in_5 = True if k_format and len(k_format) >= 13 and k_format[12] else False
        # 是否是强势10分钟
        is_in_strong_time = now_timestamp <= int("094000")
        # 量参考是否在最近30天
        # is_refer_volume_date_in_30_days = False
        # try:
        #     volume_refer_date, volume_refer_date_distance = code_volumn_manager.get_volume_refer_date(code)
        #     if volume_refer_date_distance < 30:
        #         is_refer_volume_date_in_30_days = True
        # except:
        #     pass
        if k_format and (k_format[1][0] or k_format[3][0]) and len(k_format) >= 12 and k_format[11]:
            # 破前高/接近前高且30天内有涨停
output/code_info_output.py
@@ -114,7 +114,7 @@
        # 获取量参考日期
        try:
            volume_refer_date = code_volumn_manager.get_volume_refer_date(code)
            volume_refer_date,volume_refer_date_distance = code_volumn_manager.get_volume_refer_date(code)
            params["trade_data"]["volume_refer_date"] = volume_refer_date
        except:
            pass
test/test_code_attribute.py
@@ -9,9 +9,22 @@
    return is_new_high
if __name__ == "__main__":
    code = "601022"
def __get_refer_volume_info():
    code = "001239"
    limit_up_price = 22.80
    volumes_data = init_data_util.get_volumns_by_code(code, 150)
    volumes_data = volumes_data[0:]
    print( code_nature_analyse.is_special(volumes_data))
    volumes = init_data_util.parse_max_volume(volumes_data[:90],
                                              code_nature_analyse.is_new_top(
                                                  limit_up_price,
                                                  volumes_data[:90]) or code_nature_analyse.is_near_top(
                                                  limit_up_price,
                                                  volumes_data[:90]))
    print(volumes)
if __name__ == "__main__":
    __get_refer_volume_info()
    # code = "601022"
    # volumes_data = init_data_util.get_volumns_by_code(code, 150)
    # volumes_data = volumes_data[0:]
    # print( code_nature_analyse.is_special(volumes_data))
utils/init_data_util.py
@@ -29,10 +29,11 @@
    return datas
# 解析最大量
# 返回:(60天最大量,昨日量,量参考日期,参考量据今交易日数)
def parse_max_volume(datas, is_new_or_near_top=False):
    max_volume = 0
    max_volume_date = None
    max_volume_index = None
    # 判断30天内是否有涨停
    if is_new_or_near_top:
        # 30天内是否有涨停
@@ -50,18 +51,20 @@
            if latest_limit_up_index > 0 and datas[latest_limit_up_index - 1]["volume"] > datas[latest_limit_up_index][
                "volume"]:
                return datas[latest_limit_up_index - 1]["volume"], datas[latest_limit_up_index - 1]["volume"], \
                       datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d")
                       datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index - 1
            else:
                return datas[latest_limit_up_index]["volume"], datas[latest_limit_up_index]["volume"], \
                       datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d")
                       datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index
    if is_new_or_near_top:
        # 如果是突破前高就取最大量
        for item in datas:
        for i in range(len(datas)):
            item = datas[i]
            if max_volume < item["volume"]:
                max_volume = item["volume"]
                max_volume_date = item["bob"]
        return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d")
                max_volume_index = i
        return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d"), max_volume_index
    else:
        date = None
        target_volume = None
@@ -84,7 +87,7 @@
                if volume < next_volume:
                    volume = next_volume
                    date = datas[i - 1]["bob"]
                target_volume = (volume, date)
                target_volume = (volume, date, i)
                break
        # 90个交易日无涨停,取最近30天内的最高量作为参考量
@@ -97,6 +100,6 @@
                item = datas[i]
                volume = item["volume"]
                if max_30_volume_info[0] < volume:
                    max_30_volume_info = [volume, item["bob"]]
                    max_30_volume_info = [volume, item["bob"], i]
            target_volume = max_30_volume_info
        return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d")
        return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d"), target_volume[2]