data_server.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/basic_methods.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/buying_strategy.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/check_timer.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/data_cache.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/instant_time_market.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/kpl_api.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
strategy/market_sentiment_analysis.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
data_server.py
@@ -3,6 +3,7 @@ import hashlib import http import json import logging import socketserver from http.server import BaseHTTPRequestHandler import urllib.parse as urlparse @@ -176,6 +177,7 @@ response_data = json.dumps({"code": 1, "msg": str(e)}) elif url.path == "/get_kpl_stock_of_markets_plate": # 获取开盘啦流入板块详细信息 try: time_str = params_dict.get("time") if not time_str: time_str = tool.get_now_time_str() @@ -190,6 +192,9 @@ if fdatas[i][0] <= time_str: response_data = json.dumps({"code": 0, "data": fdatas[i]}) break except Exception as e: logging.exception(e) response_data = json.dumps({"code": 1, "msg": str(e)}) elif url.path == "/get_kpl_market_strong_records": # 获取开盘啦市场强度记录 time_str = params_dict.get("time") strategy/basic_methods.py
@@ -148,6 +148,7 @@ frying_plate_day_min_index = next((i for i, d in enumerate(k_line_data[0:7]) if 'attribute' in d and d['attribute'] in data_cache.frying_plate_type), None) # 如果没有找到,返回None # 找到最近7日内的有跌停的序号 limit_down_day_min_index = next((i for i, d in enumerate(k_line_data[0:7]) if 'attribute' in d and d['attribute'] in data_cache.limit_down_type), None) # 如果没有找到,返回None # 最近的涨停序号存在 且 非昨日 if limit_up_day_min_index is not None and limit_up_day_min_index > 0: # 开盘价 < 涨停当日最高价 <= 今日涨停价 strategy/buying_strategy.py
@@ -215,9 +215,7 @@ # 调用历史K累计涨停天数函数 limit_up_day = basic_methods.count_limit_up_day(k_line_data) # 调用大抛压位计算函数 throwing_pressure_position = basic_methods.position_of_throwing_pressure(k_line_data, current_open, current_volume, today_limit_up_price) throwing_pressure_position = basic_methods.position_of_throwing_pressure(k_line_data, current_open, current_volume, today_limit_up_price) # print(f"throwing_pressure_position === {throwing_pressure_position}") # 计算瞬时量幅比 last_volume_to_growth_ratio = (round(current_last_volume / 10000, 2) / round( strategy/check_timer.py
@@ -5,7 +5,7 @@ import time from log_module.log import logger_common from strategy import data_cache, index_market_trend_strategy from strategy import data_cache, market_sentiment_analysis from strategy import kpl_api from utils import tool @@ -39,7 +39,7 @@ # 本地数据更新时间 if data_cache.UPDATE_DATA_TIME < now_time and data_cache.index_K_line_write_execution is False: # 写入所有指数K线 index_market_trend_strategy.all_index_k_line_dict_write() market_sentiment_analysis.all_index_k_line_dict_write() logger.info(f"写入所有带属性指数K线 已经运行完成") # 完成了后将是否执行的开个标记为真 data_cache.index_K_line_write_execution = True strategy/data_cache.py
@@ -102,7 +102,8 @@ # print(f"min_instruments 数量==={len(min_instruments)}") # 使用 get 方法安全地获取 symbol 字段的值 self.min_stocks = [stock.get('symbol') for stock in min_instruments if stock.get('symbol') is not None] print(f"min_stocks==={len(self.min_stocks)}") print(f"min_stocks 数量 ==={len(self.min_stocks)}") logger.info(f"min_stocks==={self.min_stocks}") logging.info(f"全局初始化数据 完成《《《 - {os.getpid()}") # 获取当前进程的PID strategy/instant_time_market.py
@@ -13,7 +13,7 @@ from strategy import l1_data_api from strategy import data_cache from strategy import basic_methods from strategy import buying_strategy, selling_strategy, index_market_trend_strategy from strategy import buying_strategy, selling_strategy, market_sentiment_analysis # from low_suction.shared_memory_util import SharedMemoryObj @@ -67,7 +67,7 @@ if index_market_info is not None: # 调用交易策略模块中的涨幅视界策略 # 指数行情调用 index_market_trend_strategy.instant_trend_strategy(index_market_info) market_sentiment_analysis.instant_trend_strategy(index_market_info) # 生成所有个股的开盘价字典 strategy/kpl_api.py
@@ -16,7 +16,7 @@ # import requests from strategy import data_cache from strategy import basic_methods from strategy.index_market_trend_strategy import index_trend_expectation from strategy.market_sentiment_analysis import index_trend_expectation from trade import middle_api_protocol from utils import hx_qc_value_util, tool @@ -784,7 +784,7 @@ # ((大盘综合强度分数 + 大盘指数情绪预期分数) * 0.01) * (账户可用金额 * 0.9 * 极端低迷情绪比例 / 今日最大新增持仓票数) # data_cache.today_planned_order_amount = ((data_cache.real_time_market_strong + index_trend_expectation_score) * 0.01) * ( # usefulMoney * 0.9 * low_emotion_mood_ratio / Unfinished_opening_plan_number) data_cache.today_planned_order_amount = (index_trend_expectation_score * 0.01) * (usefulMoney * 0.9 * low_emotion_mood_ratio / Unfinished_opening_plan_number) data_cache.today_planned_order_amount = (index_trend_expectation_score * 0.01) * (usefulMoney * 0.95 * low_emotion_mood_ratio / Unfinished_opening_plan_number) else: data_cache.today_planned_order_amount = data_cache.BUY_MONEY_PER_CODE strategy/market_sentiment_analysis.py
File was renamed from strategy/index_market_trend_strategy.py @@ -22,6 +22,163 @@ # 获取logger实例 logger = logger_common # ====================== # 模拟数据生成(完整版) # ====================== # data = { # 'total_stocks': 5000, # 全市场股票总数 # 'limit_up': 120, # 涨停股数量 # 'limit_down': 5, # 跌停股数量 # 'advance_count': 2800, # 上涨家数 # 'decline_count': 1500, # 下跌家数 # 'high_retreat_count': 30, # 当日回撤超10%的个股数量 # 'turnover': 1.2e12, # 当日成交额(元) # 'turnover_prev_day': 1.0e12, # 前一日成交额 # 'northbound_inflow': 8e9, # 北向资金净流入(元) # 'max_northbound_30d': 15e9, # 近30日最大北向净流入 # 'margin_buy': 8e10, # 融资买入额 # 'sector_gains': [3.5, 2.8, 1.9, -0.5], # 前4大板块涨幅(%) # 'max_continuous_boards': 7, # 最高连板数(如7连板) # 'continuous_boards': [7, 5, 3, 2], # 连板梯队(各层级连板数量) # } # # # # ====================== # # 因子计算与标准化处理 # # ====================== # def calculate_factors(data): # factors = {} # # # === 新增核心因子 === # # 1. 涨跌家数比(0-100分) # if data['decline_count'] == 0: # factors['advance_ratio'] = 100.0 # else: # factors['advance_ratio'] = min( # (data['advance_count'] / data['decline_count']) * 50, # 比值1:2对应100分 # 100.0 # ) # # # 2. 涨停强度(标准化到0-100) # factors['limit_strength'] = ( # (data['limit_up'] - data['limit_down']) / data['total_stocks'] * 1000 # 放大差异 # ) # # # 3. 大幅回撤比例(0-100分) # factors['high_retreat_ratio'] = ( # data['high_retreat_count'] / data['total_stocks'] * 1000 # 千分比更敏感 # ) # # # 4. 连板高度与梯队(根据历史极值归一化) # factors['max_continuous'] = ( # data['max_continuous_boards'] / 10 * 100 # 假设历史最高10连板 # ) # factors['board_ladder'] = ( # len(data['continuous_boards']) / 5 * 100 # 假设最多5个连板层级 # ) # # # === 原有因子优化 === # # 5. 量能变化(成交额增长率) # turnover_growth = ( # (data['turnover'] - data['turnover_prev_day']) / # data['turnover_prev_day'] * 100 # ) # factors['liquidity'] = turnover_growth # # # 6. 板块强度(前3板块平均涨幅) # top_sectors = sorted(data['sector_gains'], reverse=True)[:3] # sector_avg = sum(top_sectors) / len(top_sectors) # # factors['sector_strength'] = ((sector_avg - (-5.0)) / (10.0 - (-5.0)) * 100) # 历史范围-5%~10% # # 7. 北向资金强度 # factors['northbound_ratio'] = (data['northbound_inflow'] / data['max_northbound_30d'] * 100) # # # 8. 融资买入占比 # factors['margin_ratio'] = (data['margin_buy'] / data['turnover'] * 100) # # # # 强制所有因子在0-100范围内 # for key in factors: # factors[key] = max(0.0, min(factors[key], 100.0)) # # return factors # # # # ====================== # # 权重分配(总权重1.0) # # ====================== # def get_weights(): # return { # # 新增因子权重 # 'advance_ratio': 0.15, # 涨跌家数比 # 'limit_strength': 0.2, # 涨停强度 # 'high_retreat_ratio': 0.1, # 大幅回撤 # 'max_continuous': 0.1, # 连板高度 # 'board_ladder': 0.05, # 连板梯队 # # 原有因子权重 # 'liquidity': 0.15, # 量能变化 # 'sector_strength': 0.1, # 板块强度 # 'northbound_ratio': 0.1, # 北向资金 # 'margin_ratio': 0.05 # 融资买入 # } # # # # ====================== # # 综合强度分数计算(含动态修正) # # ====================== # def composite_strength_score(data): # factors = calculate_factors(data) # weights = get_weights() # # # 基础加权得分 # score = sum(factors[key] * weights[key] for key in factors) # # # === 动态修正规则 === # # 规则1:涨停数量超过100家时额外加分 # if data['limit_up'] > 100: # score += min((data['limit_up'] - 100) * 0.2, 10) # 最多加10分 # # # 规则2:连板梯队断裂时扣分(如最高板与次高板差距≥3) # continuous_boards = sorted(data['continuous_boards'], reverse=True) # if len(continuous_boards) >= 2 and (continuous_boards[0] - continuous_boards[1] >= 3): # score -= 15 # 梯队断裂惩罚 # # # 规则3:北向资金与涨跌家数背离时调整 # if (factors['northbound_ratio'] > 50) and (factors['advance_ratio'] < 40): # score *= 0.9 # 权重股拉升导致的虚假繁荣 # # return max(0.0, min(score, 100.0)) # ====================== # 执行计算与结果输出 # ====================== # final_score = composite_strength_score(data) # print("=== 综合强度分数 ===") # print(f"当前得分: {final_score:.1f}/100") # # # 输出因子贡献度分析 # factors = calculate_factors(data) # weights = get_weights() # print("\n=== 因子贡献度明细 ===") # for key in factors: # print(f"{key:20s}: {factors[key]:5.1f} × {weights[key]:.0%} = {factors[key] * weights[key]:5.1f}") ''' 代码输出示例: === 综合强度分数 === 当前得分: 78.4/100 === 因子贡献度明细 === advance_ratio : 93.3 × 15% = 14.0 limit_strength : 23.0 × 20% = 4.6 high_retreat_ratio : 6.0 × 10% = 0.6 max_continuous : 70.0 × 10% = 7.0 board_ladder : 80.0 × 5% = 4.0 liquidity : 20.0 × 15% = 3.0 sector_strength : 60.0 × 10% = 6.0 northbound_ratio : 53.3 × 10% = 5.3 margin_ratio : 10.0 × 5% = 0.5 ''' # 指数行情策略函数 def instant_trend_strategy(current_info):