Administrator
2023-04-26 d1bf04791ad095b17660a1f383b7a12f0a59b1d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
"""
首板代码评分管理
"""
 
# bidding 是否满足竞价
# deal_big_money 成交大金额是否满足
# code_nature = (是否有涨停,是否有溢价)
# hot_block(板块中涨停票个数(包含自己),板块炸板票个数,板块炸板回封个数, (板块名称,出现次数), 高位板信息)
# zyltgb自由流通市值是否大于250亿
# limit_price 涨停价是否大于100块
# limit_up_time 是否10点之前涨停
# k_form(15个交易日是否涨幅24.9%,是否破前高,是否超跌,是否接近前高,是否N,是否V,是否有形态)
import code_nature_analyse
import code_volumn_manager
import global_data_loader
import global_util
import gpcode_manager
import 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(90 - 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:
        # 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(10 * deal_big_money_rate, 0))
        d_score = min(d_score, 60)
        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(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(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(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.get_price_pre(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