| | |
| | | return k_data[0]['amount'] |
| | | |
| | | @classmethod |
| | | def get_yesterday_low_price(cls, k_data): |
| | | """ |
| | | 获取昨日最低价 |
| | | @param k_data: K线数据列表 |
| | | @return: 昨日最高价 |
| | | """ |
| | | return k_data[0]['low'] |
| | | |
| | | @classmethod |
| | | def get_yesterday_open_price(cls, k_data): |
| | | """ |
| | | 获取昨日开盘价 |
| | | @param k_data: K线数据列表 |
| | | @return: 昨日最高价 |
| | | """ |
| | | return k_data[0]['open'] |
| | | |
| | | @classmethod |
| | | def get_recent_days_high(cls, k_data, days): |
| | | """ |
| | | 获取近几个交易日的最高价 |
| | |
| | | 1 for d in k_data[:days] if d['close'] <= cls.calculate_lower_limit_price(d["sec_id"], d["pre_close"])) |
| | | |
| | | @classmethod |
| | | def get_recent_days_double_volume_date(cls, k_data, days): |
| | | """ |
| | | 获取最近几个交易日的倍量日期 |
| | | @param k_data: K线数据列表 |
| | | @param days: 交易日数量 |
| | | @return: 倍量的日期 |
| | | """ |
| | | k_datas: list = k_data[:days] |
| | | k_datas.reverse() |
| | | for i in range(1, len(k_datas)): |
| | | latest_volume = k_datas[i - 1]["volume"] |
| | | if k_datas[i]["volume"] > 2 * latest_volume: |
| | | return k_datas[i]["bob"] |
| | | return None |
| | | |
| | | @classmethod |
| | | def get_first_limit_up_avg_premium(cls, k_data, days): |
| | | """ |
| | | 获取近几个交易日的首板涨停平均溢价率 |
| | |
| | | return count |
| | | |
| | | @classmethod |
| | | def __is_limit_up(cls, code, close, pre_close): |
| | | """ |
| | | 是否涨停 |
| | | @param code: |
| | | @param close: |
| | | @param pre_close: |
| | | @return: |
| | | """ |
| | | return abs(close - cls.calculate_upper_limit_price(code, |
| | | pre_close)) < 0.01 |
| | | |
| | | @classmethod |
| | | def get_third_limit_up_days(cls, k_data, days): |
| | | """ |
| | | 获取近几个交易日的三板天数 |
| | |
| | | @return: 三板天数 |
| | | """ |
| | | count = 0 |
| | | k_data = k_data[:days] |
| | | k_data = k_data[::-1] |
| | | for i in range(days): |
| | | if i + 3 >= len(k_data): |
| | | continue |
| | | # 判断连续三日涨停且第四日非涨停 |
| | | if (k_data[i]['close'] >= cls.calculate_upper_limit_price(k_data[i]["sec_id"], k_data[i]["pre_close"])) and \ |
| | | (k_data[i + 1]['close'] >= cls.calculate_upper_limit_price(k_data[i + 1]["sec_id"], |
| | | k_data[i + 1]["pre_close"])) and \ |
| | | (k_data[i + 2]['close'] >= cls.calculate_upper_limit_price(k_data[i + 2]["sec_id"], |
| | | k_data[i + 2]["pre_close"])) and \ |
| | | (k_data[i + 3]['close'] < cls.calculate_upper_limit_price(k_data[i + 3]["sec_id"], |
| | | k_data[i + 3]["pre_close"])): |
| | | count += 1 |
| | | if cls.__is_limit_up(k_data[i]["sec_id"], k_data[i]['close'], k_data[i]["pre_close"]): |
| | | if cls.__is_limit_up(k_data[i+1]["sec_id"], k_data[i+1]['close'], k_data[i+1]["pre_close"]): |
| | | if cls.__is_limit_up(k_data[i+2]["sec_id"], k_data[i+2]['close'], k_data[i+2]["pre_close"]): |
| | | if not cls.__is_limit_up(k_data[i+3]["sec_id"], k_data[i+3]['close'], k_data[i+3]["pre_close"]): |
| | | count += 1 |
| | | return count |
| | | |
| | | @classmethod |
| | |
| | | reason_counts = {} |
| | | special_reasons = constant.KPL_INVALID_BLOCKS |
| | | if limit_up_data: |
| | | for _, date, reason in limit_up_data: |
| | | for _, date, reason, is_open, _blocks in limit_up_data: |
| | | if is_open: |
| | | continue |
| | | if min_day <= date <= max_day and reason not in special_reasons: |
| | | reason_counts[reason] = reason_counts.get(reason, 0) + 1 |
| | | if not reason_counts: |
| | | return [] |
| | | max_count = max(reason_counts.values()) |
| | | return [(reason, count) for reason, count in reason_counts.items() if count == max_count] |
| | | |
| | | @classmethod |
| | | def get_limit_up_reasons(cls, limit_up_data_list, min_day, max_day, include_recommend_reason=False): |
| | | """ |
| | | 获取最近一段时间的涨停原因 |
| | | @param include_recommend_reason: 是否包含推荐原因 |
| | | @param max_day: |
| | | @param limit_up_data_list: |
| | | @param min_day: |
| | | @return: |
| | | """ |
| | | special_reasons = constant.KPL_INVALID_BLOCKS |
| | | day_block_codes = {} |
| | | if limit_up_data_list: |
| | | for _, date, reason, is_open, _blocks in limit_up_data_list: |
| | | if reason in special_reasons: |
| | | continue |
| | | if date > max_day or date < min_day: |
| | | continue |
| | | # 每天的板块涨停数量 |
| | | if date not in day_block_codes: |
| | | day_block_codes[date] = {} |
| | | reasons = {reason} |
| | | if include_recommend_reason and _blocks: |
| | | reasons |= set(_blocks.split("、")) |
| | | for r in reasons: |
| | | if r not in day_block_codes[date]: |
| | | # {日期:{板块:[{真正涨停集合}, {炸板集合}]}} |
| | | day_block_codes[date][r] = [set(), set()] |
| | | if not is_open: |
| | | # 真正涨停 |
| | | day_block_codes[date][r][0].add(_) |
| | | else: |
| | | # 炸板 |
| | | day_block_codes[date][r][1].add(_) |
| | | blocks = set() |
| | | for date in day_block_codes: |
| | | for reason in day_block_codes[date]: |
| | | if len(day_block_codes[date][reason][0]) >= 2 or len(day_block_codes[date][reason][0]) >= 4: |
| | | # 最后涨停数>=2 炸板数>=4 |
| | | blocks.add(reason) |
| | | return blocks |
| | | return set() |
| | | |
| | | @classmethod |
| | | def get_continuous_limit_up_reasons(cls, limit_up_data_list, days_list): |
| | | """ |
| | | 连续老题材:days_list交易日都在走的题材 |
| | | @param limit_up_data_list: |
| | | @param days_list: ["2025-01-01"] |
| | | @return: |
| | | """ |
| | | special_reasons = constant.KPL_INVALID_BLOCKS |
| | | day_block_codes = {} |
| | | if limit_up_data_list: |
| | | for _, date, reason, is_open, _blocks in limit_up_data_list: |
| | | if reason in special_reasons: |
| | | continue |
| | | if date not in days_list: |
| | | continue |
| | | # 每天的板块涨停数量 |
| | | if date not in day_block_codes: |
| | | day_block_codes[date] = {} |
| | | reasons = {reason} |
| | | for r in reasons: |
| | | if r not in day_block_codes[date]: |
| | | # {日期:{板块:[{真正涨停集合}, {炸板集合}]}} |
| | | day_block_codes[date][r] = [set(), set()] |
| | | if not is_open: |
| | | # 真正涨停 |
| | | day_block_codes[date][r][0].add(_) |
| | | else: |
| | | # 炸板 |
| | | day_block_codes[date][r][1].add(_) |
| | | block_days = {} |
| | | for date in day_block_codes: |
| | | for reason in day_block_codes[date]: |
| | | if len(day_block_codes[date][reason][0]) >= 2 or len(day_block_codes[date][reason][0]) >= 4: |
| | | # 最后涨停数>=2 炸板数>=4 |
| | | if reason not in block_days: |
| | | block_days[reason] = set() |
| | | block_days[reason].add(date) |
| | | return set([b for b in block_days if len(block_days[b]) == len(days_list)]) |
| | | return set() |