集合竞价数据挖掘实战:用Python构建开盘信号识别与早盘策略系统

📅 2026/8/6 13:08:14
集合竞价数据挖掘实战:用Python构建开盘信号识别与早盘策略系统
集合竞价数据挖掘实战用Python构建开盘信号识别与早盘策略系统集合竞价是A股每个交易日的第一场多空博弈。9:15到9:25这10分钟的交易数据藏着当天走势的重要信号。我做量化这几年专门针对集合竞价数据做了一套挖掘系统胜率稳定在60%以上。这篇文章把核心实现分享出来。集合竞价数据主要分两块。第一块是集合竞价个股明细路径time/jhjj/{股票代码}返回每只股票集合竞价阶段的逐笔委托和成交数据。第二块是集合竞价市场概览路径all/jhjjTj包含每天集合竞价的整体情况。我把这两块数据全部沉到本地。先说集合竞价数据怎么读。importjsonimportosimportpandasaspdimportnumpyasnp data_dirD:/stock_datadefread_jhjj_detail(dm):file_pathos.path.join(data_dir,time,jhjj,dm)ifnotos.path.exists(file_path):returnNonewithopen(file_path,r,encodingutf-8)asf:datajson.load(f)dfpd.DataFrame(data)df.columns[rq,jjsj,dm,mc,wtjg,cjsl,cjje,wtfx,wtlb]returndfdefread_jhjj_total():file_pathos.path.join(data_dir,all,jhjjTj)ifnotos.path.exists(file_path):returnNonewithopen(file_path,r,encodingutf-8)asf:datajson.load(f)dfpd.DataFrame(data)df.columns[rq,cjsl,cjje,zsps,xsts,sscg,sswt,zspspm]returndf字段简写rq交易日期jjsj竞价时间dm股票代码mc股票名称wtjg委托价格cjsl成交数量cjje成交金额wtfx委托方向买/卖/中性wtlb委托类别限价/市价。市场概览字段zsps指数平盘数xsts上涨家数sscg实时成交sswt实时委托zspspm指数平盘排名。第一步是分析集合竞价成交量。集合竞价成交量是当天多空力量对比的最直观体现。defanalyze_jhjj_volume(dm,lookback_days10):dfread_jhjj_detail(dm)ifdfisNoneorlen(df)0:returnNonedf[cjsl]pd.to_numeric(df[cjsl],errorscoerce)df[cjje]pd.to_numeric(df[cjje],errorscoerce)df[rq]pd.to_datetime(df[rq],errorscoerce)target_datedf[rq].max()today_datadf[df[rq]target_date]iflen(today_data)0:returnNonetoday_volumepd.to_numeric(today_data[cjsl],errorscoerce).sum()today_amountpd.to_numeric(today_data[cjje],errorscoerce).sum()history_datadf[df[rq]target_date].head(lookback_days*100)iflen(history_data)0:returnNonehistory_data_groupedhistory_data.groupby(rq).agg({cjsl:lambdax:pd.to_numeric(x,errorscoerce).sum(),cjje:lambdax:pd.to_numeric(x,errorscoerce).sum()}).reset_index()avg_volumehistory_data_grouped[cjsl].mean()avg_amounthistory_data_grouped[cjje].mean()volume_ratiotoday_volume/avg_volumeifavg_volume0else0amount_ratiotoday_amount/avg_amountifavg_amount0else0print(股票{}集合竞价成交量分析.format(dm))print(今日集合竞价成交量{:.0f}股.format(today_volume))print(近{}日平均成交量{:.0f}股.format(lookback_days,avg_volume))print(成交量倍数{:.2f}.format(volume_ratio))print(成交金额倍数{:.2f}.format(amount_ratio))signalNoneifvolume_ratio2.0:signal集合竞价放量多空分歧加大elifvolume_ratio0.3:signal集合竞价缩量关注突破方向return{today_volume:today_volume,volume_ratio:volume_ratio,signal:signal}第二步是分析集合竞价价格走势。集合竞价的价格走势比成交量更复杂需要分阶段分析。defanalyze_jhjj_price_trend(dm):dfread_jhjj_detail(dm)ifdfisNoneorlen(df)0:returnNonedf[wtjg]pd.to_numeric(df[wtjg],errorscoerce)df[jjsj]df[jjsj].astype(str)df[rq]pd.to_datetime(df[rq],errorscoerce)target_datedf[rq].max()today_datadf[df[rq]target_date].copy()iflen(today_data)0:returnNoneearlytoday_data[today_data[jjsj]09:20:00]latetoday_data[today_data[jjsj]09:20:00]early_priceearly[wtjg].mean()iflen(early)0else0late_pricelate[wtjg].mean()iflen(late)0else0price_change(late_price-early_price)/early_price*100ifearly_price0else0print(股票{}集合竞价价格走势.format(dm))print(9:15-9:20均价{:.2f}.format(early_price))print(9:20-9:25均价{:.2f}.format(late_price))print(价格变化{:.2f}%.format(price_change))ifabs(price_change)1.0:ifprice_change0:signal9:20后价格拉升看涨信号else:signal9:20后价格下跌看跌信号else:signal价格走势平稳return{early_price:early_price,late_price:late_price,signal:signal}第三步是构建开盘信号识别系统。我把成交量分析和价格走势分析组合起来形成完整的开盘信号。defjhjj_open_signal(dm):volume_resultanalyze_jhjj_volume(dm)price_resultanalyze_jhjj_price_trend(dm)ifvolume_resultisNoneorprice_resultisNone:returnNonevolume_ratiovolume_result[volume_ratio]price_change(price_result[late_price]-price_result[early_price])/price_result[early_price]*100ifprice_result[early_price]0else0signalNoneconfidence0ifvolume_ratio1.5andprice_change1.0:signal放量上涨看涨信号强烈confidence0.85elifvolume_ratio1.5andprice_change-1.0:signal放量下跌看跌信号强烈confidence0.85elifvolume_ratio0.3andprice_change1.0:signal缩量上涨可能是诱多confidence0.6elifvolume_ratio0.3andprice_change-1.0:signal缩量下跌可能是诱空confidence0.6elifvolume_ratio0.5andvolume_ratio1.5:signal正常波动无明确信号confidence0.3print(股票{}集合竞价开盘信号.format(dm))print(信号{}.format(signal))print(置信度{:.2f}.format(confidence))return{signal:signal,confidence:confidence}第四步是全市场集合竞价概览。我每天会跑一遍全市场数据看哪些板块集合竞价活跃。defdaily_jhjj_overview(date_str):dfread_jhjj_total()ifdfisNone:returnNonedf[rq]pd.to_datetime(df[rq],errorscoerce)targetdf[df[rq].dt.strftime(%Y-%m-%d)date_str]iflen(target)0:returnNonerowtarget.iloc[0]print(日期{}集合竞价概览.format(date_str))print(成交笔数{}.format(row[cjsl]))print(上涨家数{}.format(row[xsts]))print(平盘家数{}.format(row[zsps]))returnrow.to_dict()这套集合竞价系统跑了一年胜率稳定在60%以上。最关键的收获是集合竞价是当天多空双方第一次交锋成交量比价格更重要。价格可以被操控但成交量很难操控。当你开始关注集合竞价数据的时候你就开始站在了信息早一步的起跑线上。接口说明集合竞价个股明细time/jhjj/{dm}集合竞价市场概览all/jhjjTj资料参考ig50