| | |
| | | |
| | | # 计算市场分布形态因子 函数 |
| | | # ====================== 输入数据 ====================== |
| | | data = {'-1': '2676', '-10': '4', '-2': '769', '-3': '181', '-4': '59', '-5': '43', '-6': '18', '-7': '11', '-8': '5', '-9': '4', '0': '219', '1': '714', '10': '6', '2': '214', '3': '69', '4': '45', '5': '23', '6': '9', '7': '9', '8': '7', '9': '6', 'DT': 17, 'SJDT': '8', 'SJZT': '17', 'STDT': '9', 'STZT': '4', 'SZJS': 1123, 'XDJS': 3787, 'ZSZDFB': '480,1639,112,123,351,26,76,202,15,17,32,1,15,30,5,78,204,18,', 'ZT': 21, 'sign': '市场人气一般', 'szln': 2591290, 'qscln': 6629612, 's_zrcs': 2604433, 'q_zrcs': 6660830, 's_zrtj': 38031347, 'q_zrtj': 91465597} |
| | | data = {'-1': '2676', '-10': '4', '-2': '769', '-3': '181', '-4': '59', '-5': '43', '-6': '18', '-7': '11', '-8': '5', |
| | | '-9': '4', '0': '219', '1': '714', '10': '6', '2': '214', '3': '69', '4': '45', '5': '23', '6': '9', '7': '9', |
| | | '8': '7', '9': '6', 'DT': 17, 'SJDT': '8', 'SJZT': '17', 'STDT': '9', 'STZT': '4', 'SZJS': 1123, 'XDJS': 3787, |
| | | 'ZSZDFB': '480,1639,112,123,351,26,76,202,15,17,32,1,15,30,5,78,204,18,', 'ZT': 21, 'sign': '市场人气一般', |
| | | 'szln': 2591290, 'qscln': 6629612, 's_zrcs': 2604433, 'q_zrcs': 6660830, 's_zrtj': 38031347, 'q_zrtj': 91465597} |
| | | |
| | | |
| | | # ====================== 总手涨跌分布数据预处理 ====================== |
| | |
| | | |
| | | # 2. 定义区间划分(假设从-9%到+9%,1%间隔) |
| | | bins = [ |
| | | "[+9%, +8%)", "[+8%, +7%)", "[+7%, +6%)", "[+6%, +5%)", "[+5%, +4%)", "[+4%, +3%)", "[+3%, +2%)", "[+2%, +1%)", "[+1%, 0%)", "[0%, -1%)", "[-1%, -2%)", "[-2%, -3%)", "[-3%, -4%)", "[-4%, -5%)", "[-5%, -6%)", "[-6%, -7%)", "[-7%, -8%)", "[ -8%, -9%)" |
| | | ] |
| | | "[+9%, +8%)", "[+8%, +7%)", "[+7%, +6%)", "[+6%, +5%)", "[+5%, +4%)", "[+4%, +3%)", "[+3%, +2%)", "[+2%, +1%)", |
| | | "[+1%, 0%)", "[0%, -1%)", "[-1%, -2%)", "[-2%, -3%)", "[-3%, -4%)", "[-4%, -5%)", "[-5%, -6%)", "[-6%, -7%)", |
| | | "[-7%, -8%)", "[ -8%, -9%)" |
| | | ] |
| | | |
| | | # 3. 验证数据长度 |
| | | if len(counts) != len(bins): |
| | |
| | | } |
| | | |
| | | return result |
| | | |
| | | |
| | | # ====================== 核心因子计算 ====================== |
| | | def calculate_factors(data): |
| | |
| | | signals.append("高情绪热度:涨停股多且人气向好") |
| | | |
| | | # 信号5:涨跌分布综合 |
| | | if factors['top_three']['top1']['value']+factors['top_three']['top2']['value']+factors['top_three']['top3']['value'] > 50: |
| | | value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + factors['top_three']['top3']['value'] |
| | | if factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + factors['top_three']['top3'][ |
| | | 'value'] > 50: |
| | | value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + \ |
| | | factors['top_three']['top3']['value'] |
| | | signals.append(f"涨跌分布:长尾分布{value}") |
| | | if factors['top_three']['top1']['value']/factors['top_three']['top2']['value'] > 1.25: |
| | | signals.append(f"涨跌分布:强势聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%") |
| | | if factors['top_three']['top1']['value'] / factors['top_three']['top2']['value'] > 1.25: |
| | | signals.append( |
| | | f"涨跌分布:强势聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%") |
| | | else: |
| | | signals.append(f"涨跌分布:中度聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%") |
| | | signals.append( |
| | | f"涨跌分布:中度聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%") |
| | | else: |
| | | value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + factors['top_three']['top3']['value'] |
| | | value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + \ |
| | | factors['top_three']['top3']['value'] |
| | | signals.append(f"涨跌分布:均匀分布{value}") |
| | | |
| | | return signals if signals else ["无显著信号:维持当前策略"] |
| | |
| | | # data_cache.today_planned_order_amount = ((data_cache.real_time_market_strong + data_cache.index_trend_expectation_score) * 0.01) * ( |
| | | # usefulMoney * 0.9 * low_emotion_mood_ratio / Unfinished_opening_plan_number) |
| | | # 除以3应该是一个常量,如果以Unfinished_opening_plan_number,会出现float division by zero 错误 |
| | | data_cache.today_planned_order_amount = usefulMoney * 0.95 * ideal_trading_market_score / 3 |
| | | if not data_cache.today_planned_order_amount or data_cache.today_planned_order_amount <= 0: |
| | | data_cache.today_planned_order_amount = usefulMoney * 0.95 * ideal_trading_market_score / 3 |
| | | logger.info(f"第一次计划下单金额==={data_cache.today_planned_order_amount}元") |
| | | # 开仓计划运行时间段 |
| | | if data_cache.OPENING_TIME < now_time < data_cache.NOON_MARKET_TIME: |
| | | # # 如果一日三仓的计划还未完成 且 首次开仓金额为0 |
| | |
| | | # logger.info(f"采用开仓策略计算方式=》今日计划下单金额:{data_cache.today_planned_order_amount}") |
| | | if addition_position_number > 0: |
| | | # 下过一次单过后再计算动态下单金额 |
| | | data_cache.today_first_planned_order_amount = float(data_cache.today_planned_order_amount) |
| | | data_cache.today_first_planned_order_amount = float( |
| | | data_cache.today_planned_order_amount) |
| | | logger.info( |
| | | f"采用开仓策略计算方式--》今日(首个)新增持仓产生,将实时计算金额赋值给首笔持仓金额=》今日计划下单金额:{data_cache.today_planned_order_amount}") |
| | | |
| | |
| | | print(f"总股票数: {factors['total_stocks']}") |
| | | print(f"涨跌比(BDR): {factors['rise_vs_fall']['rise_vs_fall_ratio']:.2f}") |
| | | print(f"极端波动比例: {factors['sentiment']['extreme_ratio']:.2%}") |
| | | print(f"资金净流入(元): {round(factors['capital_flow']['net']/10000, 2)}万") |
| | | print(f"资金净流入(元): {round(factors['capital_flow']['net'] / 10000, 2)}万") |
| | | print(f"涨停股占比: {factors['sentiment']['zt_ratio']:.2%}") |
| | | print(f"聚集前三名情况字典=={factors['top_three']}") |
| | | print(f"上涨幅段最大:{factors['rise_vs_fall']['rise_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['rise_max_key'])}%") |
| | | print(f"下跌幅段最大:{factors['rise_vs_fall']['fall_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['fall_max_key'])}%") |
| | | print(f"聚集区域:{factors['rise_vs_fall']['gather_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['gather_area'])}%") |
| | | print(f"零散区域:{factors['rise_vs_fall']['scattered_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['scattered_area'])}%") |
| | | print( |
| | | f"上涨幅段最大:{factors['rise_vs_fall']['rise_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['rise_max_key'])}%") |
| | | print( |
| | | f"下跌幅段最大:{factors['rise_vs_fall']['fall_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['fall_max_key'])}%") |
| | | print( |
| | | f"聚集区域:{factors['rise_vs_fall']['gather_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['gather_area'])}%") |
| | | print( |
| | | f"零散区域:{factors['rise_vs_fall']['scattered_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['scattered_area'])}%") |
| | | print(f"市场情绪量化: {'积极' if factors['sentiment']['sign'] else '谨慎'}") |
| | | print(f"涨跌因子字典={factors['rise_vs_fall']}") |
| | | |
| | |
| | | for item in factors['rise_vs_fall']['parsed_data']["区间分布"]: |
| | | print(f"{item['区间']}: {item['成交量(手)']}手") |
| | | print(f"\n总成交量: {factors['rise_vs_fall']['parsed_data']['总成交量(手)']}手") |
| | | print(f"说明: {factors['rise_vs_fall']['parsed_data']['说明']}") |
| | | print(f"说明: {factors['rise_vs_fall']['parsed_data']['说明']}") |