| | |
| | | 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): |
| | | """ |
| | | 获取近几个交易日的最高价 |
| | |
| | | """ |
| | | return sum( |
| | | 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): |
| | |
| | | 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() |