""" 首板代码评分管理 """ # bidding 是否满足竞价 # deal_big_money 成交大金额是否满足 # code_nature = (是否有涨停,是否有溢价) # hot_block(板块中涨停票个数(包含自己),板块炸板票个数,板块炸板回封个数, (板块名称,出现次数), 高位板信息) # zyltgb自由流通市值是否大于250亿 # limit_price 涨停价是否大于100块 # limit_up_time 是否10点之前涨停 # k_form(15个交易日是否涨幅24.9%,是否破前高,是否超跌,是否接近前高,是否N,是否V,是否有形态) from code_attribute import code_volumn_manager, code_nature_analyse, global_data_loader, gpcode_manager from utils import global_util, tool from third_data import block_info from trade import l2_trade_factor, deal_big_money_manager, bidding_money_manager # 获取几板 def __get_ban_count(str_): for i in range(len(str_)-1, -1, -1): if str_[i].isnumeric(): return int(str_[i]) return 0 def __get_score(zyltgb, limit_price, bidding, k_form, code_nature, hot_block, volume_rate, limit_up_time, deal_big_money_rate): score_list = [] if zyltgb: zyltgb_y = round(zyltgb / 100000000, 0) if zyltgb_y <= 80: score_list.append(max(int(round(0.5 * zyltgb_y - 10, 0)), -10)) else: score_list.append(max(int(round(30 - 5 * ((zyltgb_y - 80) // 20), 0)), -10)) else: score_list.append(0) score_list.append(max(int(round(-1 * limit_price + 31, 0)), -69)) # 开盘前竞价 if bidding: score_list.append(25) else: score_list.append(0) k_score = [] # 15个交易日是否涨幅24.9% if k_form[0]: k_score.append(-1000) else: k_score.append(0) # 是否破前高 if k_form[1]: k_score.append(55) else: k_score.append(0) # 是否超跌 if k_form[2]: k_score.append(35) else: k_score.append(0) # 是否接近前高 if k_form[3]: k_score.append(-10) else: k_score.append(0) # 是否N if k_form[4]: k_score.append(30) else: k_score.append(0) # 是否V if k_form[5]: k_score.append(25) else: k_score.append(0) # 是否有形态 if k_form[6]: k_score.append(0) else: k_score.append(20) # 是否天量大阳 if k_form[7] and not k_form[1]: # 天量大阳且不是突破前高 k_score.append(30) else: k_score.append(0) score_list.append(k_score) nature_score = [] # 首板涨停次数,首板溢价率,首板开板溢价率 if code_nature is None: code_nature = [0, 0, 0] if code_nature[0] <= 0: nature_score.append(20) else: nature_score.append(min(10 + code_nature[0], 20)) if code_nature[1]: nature_score.append(min(int(round(code_nature[1] * 20 - 10)), 10)) else: nature_score.append(0) if code_nature[2]: nature_score.append(min(int(round(code_nature[2] * 20 - 10)), 10)) else: nature_score.append(0) score_list.append(nature_score) hot_block_score = [] # --------------- 板块------------------ # 板块 - 代码平均涨幅 __average_rate = round(hot_block["block_codes_rates_info"][0] / hot_block["block_codes_rates_info"][1], 2) if hot_block["target_block_info"][0] == "无板块": # 无板块的板块得分只能是25 hot_block_score.append(25) # 补充多余数据 for i in range(10): hot_block_score.append(0) else: if hot_block["target_block_info"][0] == "无板块": hot_block_score.append(5) else: hot_block_score.append(min(int(round(__average_rate * 2 - 10)), 10)) # 板块 - 涨停只数 #--先注释设置为0 # if hot_block["limit_up_codes_count"] <= 1: # hot_block_score.append(1) # else: # hot_block_score.append(max(12 - hot_block["limit_up_codes_count"], 2)) hot_block_score.append(0) # 板块 - 板块涨幅 # hot_block_score.append(min(int(round(hot_block["target_block_info"][1] * 2)), 10)) #--先注释设置为0 hot_block_score.append(0) # 板块 - 第几只涨停 if hot_block["limit_up_index"] <= 0: hot_block_score.append(0) else: hot_block_score.append(max(120 - hot_block["limit_up_index"] * 10, 0)) # 板块 - 高位板 high_score = 0 for high_info in hot_block["high_block_infos"]: c_count = __get_ban_count(high_info[1]) high_score += min(2 * c_count - 2, 10) hot_block_score.append(high_score) # 板块 - 板块历史出现次数 if hot_block["target_block_info"][2] <= 1: hot_block_score.append(10) else: hot_block_score.append(max(-3 * hot_block["target_block_info"][2] + 20, -10)) score_list.append(hot_block_score) # --------------- 板块结束----------------- # 量 if volume_rate <= 0.5: score_list.append(int(round(100 * volume_rate))) elif volume_rate < 0.6: score_list.append(50) elif volume_rate < 0.7: score_list.append(55) elif volume_rate <= 1.0: score_list.append(60) else: score_list.append(max(int(round(-100 * volume_rate + 160, 0)), -20)) # 初始化为当前时间 limit_up_time_m = tool.trade_time_sub(tool.get_now_time_str(), "09:00:00") // 60 if limit_up_time: limit_up_time_m = tool.trade_time_sub(limit_up_time, "09:00:00") // 60 if limit_up_time_m < 240 or True: # 14:30之前适用 score_list.append(min(int(0 - round(limit_up_time_m / 15) + 12), 10)) # elif limit_up_time_m <= 270: # # 15:00之前加 # score_list.append(100) # else: # score_list.append(0) # 大单成交 # if deal_big_money_rate < 1: # score_list.append(0) # else: d_score = int(round(5 * deal_big_money_rate + 10, 0)) d_score = min(d_score, 40) score_list.append(d_score) score = 0 for s in score_list: if type(s) == list: for ss in s: score += ss else: score += s return score, score_list def get_score(code, volume_rate, limit_up_time, with_source_data=False, estimate_deal_big_money_num=0): source_datas = [] # 获取自由流通股本 zyltgb = global_util.zyltgb_map.get(code) if zyltgb is None: global_data_loader.load_zyltgb() zyltgb = global_util.zyltgb_map.get(code) if zyltgb is None: zyltgb = 100 * 100000000 source_datas.append(zyltgb) limit_price = float(gpcode_manager.get_limit_up_price(code)) source_datas.append(limit_price) # 竞价金额 bidding_money = bidding_money_manager.get_bidding_money_cache(code) source_datas.append(bidding_money) bidding = False if bidding_money and bidding_money >= 5000: bidding = True k_form = code_nature_analyse.CodeNatureRecordManager.get_k_format_cache(code) if k_form is None: k_form = [(True, ''), (False, ''), (False, ''), (False, ''), (False, ''), (False, ''), (True, ''), (1, 1)] today_volume = code_volumn_manager.get_today_volumn(code) if today_volume: today_volume = int(today_volume) if k_form[7][0] < today_volume * 0.7 and k_form[7][1] < today_volume * 0.3: # 最大量小于今日量的70%,平均量小于今日量的30% k_form[7] = (True, f"最大量:{k_form[7][0]} 均量:{k_form[7][1]}") else: k_form[7] = (False, f"最大量:{k_form[7][0]} 均量:{k_form[7][1]}") if not k_form[6][0] and k_form[7][0]: # 将天量大阳融合进去 k_form[6] = (True, '') source_datas.append(k_form) code_nature = code_nature_analyse.CodeNatureRecordManager.get_nature_cache(code) source_datas.append(code_nature) hot_block = block_info.get_info(code) if hot_block is None: hot_block = { # 目标板块信息(板块名称,板块涨幅,历史板块出现次数) "target_block_info": ("无板块", 0, 0), # 涨停顺序 "limit_up_index": 0, # 涨停代码数量 "limit_up_codes_count": 0, # 板块代码涨幅信息 "block_codes_rates_info": (0, 0), # 炸板代码数量 "break_size": 0, # 炸板回封数量 "re_limit_up_size": 0, # 高位版信息 "high_block_infos": [], } # 将代码本身的信息包含进去 hot_block["limit_up_codes_count"] = hot_block["limit_up_codes_count"] + 1 pre_close_price = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) hot_block["block_codes_rates_info"] = ( hot_block["block_codes_rates_info"][0] + round((limit_price - pre_close_price) * 100 / pre_close_price, 2), hot_block["block_codes_rates_info"][1] + 1) source_datas.append(hot_block) source_datas.append(volume_rate) source_datas.append(limit_up_time) # 获取成交大单 deal_big_num = deal_big_money_manager.get_deal_big_money_num(code) if estimate_deal_big_money_num > 0: deal_big_num = estimate_deal_big_money_num m = l2_trade_factor.L2TradeFactorUtil.get_base_safe_val(zyltgb) source_datas.append((deal_big_num * limit_price * 100, m)) deal_big_num_rate = (deal_big_num * limit_price * 100) / m k_form_1 = [] for i in range(0, len(k_form)): k_form_1.append(k_form[i][0]) result = __get_score(zyltgb, limit_price, bidding, k_form_1, code_nature, hot_block, volume_rate, limit_up_time, deal_big_num_rate) if with_source_data: return result, source_datas return result if __name__ == "__main__": limit_price = 35 prices = [0, 5, 10, 20, 30, 40, 50, 10000] price_scores = [20, 15, 10, 0, -10, -20, -1000] for i in range(1, len(prices)): if prices[i] > limit_price: print(price_scores[i - 1]) break