| | |
| | | yi = 1 |
| | | return 5000000 + (yi - 1) * 500000 |
| | | |
| | | # 自由流通市值影响比例 |
| | | @classmethod |
| | | def get_zylt_rate(cls, zyltgb): |
| | | yi = round(zyltgb / 100000000) |
| | | if yi < 1: |
| | | yi = 1 |
| | | if yi <= 30: |
| | | rate = -0.04 + 0.01 * (yi - 1) |
| | | if rate > 0.1: |
| | | rate = 0.1 |
| | | else: |
| | | rate = 0.09 - (yi - 31) * 0.002 |
| | | if rate < -0.1: |
| | | rate = -0.1 |
| | | return round(rate, 4) |
| | | |
| | | # 获取行业影响比例 |
| | | # total_limit_percent为统计的比例之和乘以100 |
| | | @classmethod |
| | | def get_industry_rate(cls, total_limit_percent): |
| | | t = total_limit_percent / 10 |
| | | rate = t / 0.5 * 0.02 + 0.26 |
| | | if rate > 0.52: |
| | | rate = 0.52 |
| | | return round(rate, 2) |
| | | if t < 0.9: |
| | | return 0 |
| | | elif t <= 1.1: |
| | | return 0.2 |
| | | elif t <= 1.6: |
| | | return 0 |
| | | elif t <= 2.1: |
| | | return 0.03 |
| | | elif t <= 2.6: |
| | | return 0.06 |
| | | elif t <= 3.1: |
| | | return 0.09 |
| | | elif t <= 3.6: |
| | | return 0.12 |
| | | elif t <= 4.1: |
| | | return 0.15 |
| | | elif t <= 4.6: |
| | | return 0.18 |
| | | elif t <= 5.1: |
| | | return 0.21 |
| | | elif t <= 5.6: |
| | | return 0.24 |
| | | elif t <= 6.1: |
| | | return 0.27 |
| | | else: |
| | | return 0.30 |
| | | |
| | | # 获取量影响比例 |
| | | @classmethod |
| | | def get_volumn_rate(cls, day60_max, yest, today): |
| | | old_volumn = yest |
| | | base_rate = 0.49 |
| | | if day60_max > yest: |
| | | old_volumn = day60_max |
| | | base_rate = 0.50 |
| | | r = round(today / old_volumn, 2) |
| | | if r < 0.01: |
| | | r = 0.01 |
| | | print("比例:", r) |
| | | rate = 0 |
| | | if r <= 0.25: |
| | | rate = base_rate - (r - 0.01) * 2 |
| | | elif r <= 0.5: |
| | | rate = 0.25 - r + (0.01 if day60_max > yest else 0) |
| | | elif r < 0.75: |
| | | rate = r - 0.75 + (0.01 if day60_max > yest else 0) |
| | | elif r < 1.74: |
| | | rate = base_rate - (r - 0.75) |
| | | if r < 0.5: |
| | | rate = 0.3 - (r - 0.01) |
| | | elif r <= 0.75: |
| | | rate = -0.2 + (r - 0.5) * 2 |
| | | elif r <= 1.35: |
| | | rate = 0.3 - (r - 0.75) |
| | | else: |
| | | rate = base_rate - 0.99 |
| | | rate = -0.3 |
| | | return round(rate, 4) |
| | | |
| | | # 当前股票首次涨停时间的影响比例 |
| | |
| | | start_m = 9 * 60 + 30 |
| | | m = int(times[0]) * 60 + int(times[1]) |
| | | dif = m - start_m |
| | | base_rate = 0.5 |
| | | base_rate = 0.3 |
| | | rate = 0 |
| | | if dif < 1: |
| | | rate = base_rate |
| | | elif dif <= 5: |
| | | rate = base_rate - dif * 0.02 |
| | | elif dif <= 120: |
| | | # 11:30之前 |
| | | rate = 0.39 - (dif - 6) * 0.004 |
| | | rate = base_rate - dif * 0.0035 |
| | | else: |
| | | rate = 0.39 - (120 - 6) * 0.004 - (dif - 210 + 1) * 0.004 |
| | | if rate < -0.5: |
| | | rate = -0.5 |
| | | rate = base_rate - (dif - 89) * 0.0035 |
| | | if rate < -0.3020: |
| | | rate = -0.3020 |
| | | return round(rate, 4) |
| | | |
| | | # 纯万手哥影响值(手数》=9000 OR 金额》=500w) |
| | | @classmethod |
| | | def get_big_money_rate(cls, num): |
| | | if num < 0: |
| | | num = 0 |
| | | if num >= 10: |
| | | return 0.5 |
| | | else: |
| | | return round(num * 0.05, 2) |
| | | if num < 4: |
| | | return 0 |
| | | rate = (num - 4) * 0.035 / 4 + 0.06 |
| | | if rate > 0.9: |
| | | rate = 0.9 |
| | | return round(rate, 4) |
| | | |
| | | @classmethod |
| | | def compute_rate(cls, zyltgb, total_industry_limit_percent, volumn_day60_max, volumn_yest, volumn_today, |
| | | limit_up_time, big_money_num): |
| | | # 自由流通股本影响比例 |
| | | zyltgb_rate = cls.get_zylt_rate(zyltgb) |
| | | |
| | | # 行业涨停影响比例 |
| | | industry_rate = 0 |
| | | if total_industry_limit_percent is not None: |
| | |
| | | if big_money_num is not None: |
| | | big_money_rate = cls.get_big_money_rate(big_money_num) |
| | | print( |
| | | "zyltgb_rate:{} industry_rate:{} volumn_rate:{} limit_up_time_rate:{} big_money_rate:{}".format(zyltgb_rate, |
| | | industry_rate, |
| | | volumn_rate, |
| | | limit_up_time_rate, |
| | | big_money_rate)) |
| | | "industry_rate:{} volumn_rate:{} limit_up_time_rate:{} big_money_rate:{}".format(industry_rate, |
| | | volumn_rate, |
| | | limit_up_time_rate, |
| | | big_money_rate)) |
| | | |
| | | return round(1 - (zyltgb_rate + industry_rate + volumn_rate + limit_up_time_rate + big_money_rate), 4) |
| | | final_rate = round(1 - (industry_rate + volumn_rate + limit_up_time_rate + big_money_rate), 4) |
| | | if final_rate < 0.1: |
| | | final_rate = 0.1 |
| | | return final_rate |
| | | |
| | | @classmethod |
| | | def compute_rate_by_code(cls, code): |
| | | factors = cls.__get_rate_factors(code) |
| | | return cls.compute_rate(factors[0], factors[1], factors[2], factors[3], factors[4], factors[5], factors[6]) |
| | | |
| | | @classmethod |
| | | def __get_rate_factors(cls, code): |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | # 获取行业热度 |
| | | industry = global_util.code_industry_map.get(code) |
| | |
| | | industry = global_util.code_industry_map.get(code) |
| | | |
| | | total_industry_limit_percent = global_util.industry_hot_num.get(industry) if industry is not None else None |
| | | # 当前票是否涨停 |
| | | if total_industry_limit_percent is not None: |
| | | if code in global_util.limit_up_codes_percent: |
| | | total_industry_limit_percent -= global_util.limit_up_codes_percent[code] |
| | | |
| | | # 获取量 |
| | | volumn_day60_max, volumn_yest, volumn_today = global_util.max60_volumn.get( |
| | | code), global_util.yesterday_volumn.get(code), global_util.today_volumn.get(code) |
| | |
| | | big_money_num = global_util.big_money_num.get(code) |
| | | if big_money_num is None: |
| | | big_money_num = big_money_num_manager.get_num(code) |
| | | return cls.compute_rate(zyltgb, total_industry_limit_percent, volumn_day60_max, volumn_yest, volumn_today, |
| | | limit_up_time, big_money_num) |
| | | return ( |
| | | zyltgb, total_industry_limit_percent, volumn_day60_max, volumn_yest, volumn_today, limit_up_time, |
| | | big_money_num) |
| | | |
| | | @classmethod |
| | | def factors_to_string(cls, code): |
| | | vals = cls.__get_rate_factors(code) |
| | | return "zyltgb:%s, total_industry_limit_percent:%s, volumn_day60_max:%s, volumn_yest:%s, volumn_today:%s,limit_up_time:%s, big_money_num:%s" % vals |
| | | |
| | | @classmethod |
| | | def __get_zyltgb(cls, code): |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | if zyltgb is None: |
| | | global_util.load_zyltgb() |
| | | zyltgb = global_util.zyltgb_map.get(code) |
| | | return zyltgb |
| | | |
| | | @classmethod |
| | | def compute_m_value(cls, code): |
| | |
| | | if zyltgb is None: |
| | | print("没有获取到自由流通市值") |
| | | return 10000000 |
| | | if code == '002476': |
| | | print("") |
| | | zyltgb = cls.get_base_safe_val(zyltgb) |
| | | rate = cls.compute_rate_by_code(code) |
| | | # print("m值获取:", code, round(zyltgb * rate)) |
| | | return round(zyltgb * rate) |
| | | |
| | | # 获取安全笔数 |
| | | @classmethod |
| | | def get_safe_buy_count(cls, code): |
| | | gb = cls.__get_zyltgb(code) |
| | | if not gb: |
| | | # 默认10笔 |
| | | return 8 |
| | | count = gb // 100000000 |
| | | if count > 30: |
| | | return 30 |
| | | if count < 5: |
| | | return 5 |
| | | return count |
| | | |
| | | |
| | | # l2因子归因数据 |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | L2TradeFactorUtil.compute_m_value("000036") |
| | | # print(L2TradeFactorUtil.get_big_money_rate(1)) |
| | | # print(L2TradeFactorUtil.get_rate_factors("003004")) |
| | | # print(L2TradeFactorUtil.factors_to_string("003004")) |
| | | print(L2TradeFactorUtil.get_limit_up_time_rate("09:30:30")) |
| | | print(L2TradeFactorUtil.get_limit_up_time_rate("11:30:00")) |
| | | print(L2TradeFactorUtil.get_limit_up_time_rate("13:00:00")) |
| | | print(L2TradeFactorUtil.get_limit_up_time_rate("13:48:00")) |
| | | print(L2TradeFactorUtil.get_limit_up_time_rate("13:53:23")) |
| | | print(L2TradeFactorUtil.get_limit_up_time_rate("14:23:23")) |
| | | |
| | | # print(L2TradeFactorUtil.get_big_money_rate(2)) |
| | | # print(L2TradeFactorUtil.get_big_money_rate(3)) |