| | |
| | | |
| | | |
| | | # 获取股性 |
| | | # 返回(是否涨停,首板溢价率是否大于0.6) |
| | | # 返回(是否涨停,首板溢价率,首板炸板溢价率) |
| | | def get_nature(record_datas): |
| | | limit_up = is_have_limit_up(record_datas) |
| | | limit_up_count = get_first_limit_up_count(record_datas) |
| | | premium_rate = get_limit_up_premium_rate(record_datas) |
| | | result = (limit_up, premium_rate >= 0.6, premium_rate) |
| | | |
| | | open_premium_rate = get_open_limit_up_premium_rate(record_datas) |
| | | result = (limit_up_count, premium_rate, open_premium_rate) |
| | | return result |
| | | |
| | | |
| | | # 获取涨幅 |
| | | def get_lowest_price_rate(record_datas): |
| | | datas = copy.deepcopy(record_datas) |
| | | datas.sort(key=lambda x: x["bob"]) |
| | | datas = datas[-15:] |
| | | low_price = datas[0]["close"] |
| | | date = None |
| | | datas = datas[-10:] |
| | | for data in datas: |
| | | if low_price > data["close"]: |
| | | low_price = data["close"] |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(data["pre_close"])) |
| | | if abs(limit_up_price - data["high"]) < 0.01: |
| | | date = data['bob'].strftime("%Y-%m-%d") |
| | | return (datas[-1]["close"] - low_price) / low_price, date |
| | | return round((datas[-1]["close"] - data["close"]) / data["close"], 4), date |
| | | return 0, '' |
| | | |
| | | |
| | | # 是否有涨停 |
| | | def is_have_limit_up(datas): |
| | | def get_first_limit_up_count(datas): |
| | | datas = copy.deepcopy(datas) |
| | | count = 0 |
| | | for i in range(len(datas)): |
| | | item = datas[i] |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) |
| | | if abs(limit_up_price - item["close"]) < 0.01: |
| | | return True, item['bob'].strftime("%Y-%m-%d") |
| | | return False, '' |
| | | # 获取首板涨停次数 |
| | | if __is_limit_up(item) and i>0 and not __is_limit_up(datas[i-1]): |
| | | # 首板涨停 |
| | | count+=1 |
| | | |
| | | return count |
| | | |
| | | |
| | | # 是否破前高 |
| | |
| | | return max_volume, average_volume |
| | | |
| | | |
| | | # 是否涨停 |
| | | def __is_limit_up(data): |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(data["pre_close"])) |
| | | return abs(limit_up_price - data["close"]) < 0.001 |
| | | |
| | | |
| | | # 首板涨停溢价率 |
| | | def get_limit_up_premium_rate(datas): |
| | | datas = copy.deepcopy(datas) |
| | |
| | | for i in range(0, len(datas)): |
| | | item = datas[i] |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) |
| | | if abs(limit_up_price - item["close"]) < 0.001 and abs( |
| | | limit_up_price - datas[i - 1]["close"]) >= 0.001 and 0 < i < len(datas) - 1: |
| | | # 首板涨停 |
| | | rate = (datas[i + 1]["high"] - datas[i + 1]["pre_close"]) / datas[i + 1]["pre_close"] |
| | | first_rate_list.append(rate) |
| | | if abs(limit_up_price - item["close"]) < 0.001: |
| | | if 0 < i < len(datas) - 1 and not __is_limit_up(datas[i - 1]): |
| | | # 首板涨停 |
| | | rate = (datas[i + 1]["high"] - datas[i + 1]["pre_close"]) / datas[i + 1]["pre_close"] |
| | | first_rate_list.append(rate) |
| | | if not first_rate_list: |
| | | return 0 |
| | | return None |
| | | count = 0 |
| | | for rate in first_rate_list: |
| | | if rate >= 0.01: |
| | | count += 1 |
| | | return count / len(first_rate_list) |
| | | |
| | | |
| | | # 首板炸板溢价率 |
| | | def get_open_limit_up_premium_rate(datas): |
| | | datas = copy.deepcopy(datas) |
| | | datas.sort(key=lambda x: x["bob"]) |
| | | first_rate_list = [] |
| | | for i in range(0, len(datas)): |
| | | item = datas[i] |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) |
| | | |
| | | if abs(limit_up_price - item["high"]) < 0.001 and abs(limit_up_price - item["close"]) > 0.001: |
| | | # |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(datas[i - 1]["pre_close"])) |
| | | if 0 < i < len(datas) - 1 and not __is_limit_up(datas[i - 1]): |
| | | # 前一天未涨停 |
| | | rate = (datas[i + 1]["high"] - item["high"]) / item["high"] |
| | | first_rate_list.append(rate) |
| | | if not first_rate_list: |
| | | return None |
| | | count = 0 |
| | | for rate in first_rate_list: |
| | | if rate >= 0.01: |