返回介绍

第一部分 新手入门

第二部分 股票量化相关

第三部分 基金、利率互换、固定收益类

第四部分 衍生品相关

3.4 熔断机制 • 股海拾贝之 [熔断错杀股]

发布于 2022-02-20 22:26:14 字数 34572 浏览 751 评论 0 收藏 0

新年伊始,本是普天同庆之时,A股门前却风声鹤唳;熔断机制推出4天,触发-7%熔断两次;千古跌停中,有不少标的遭遇恐慌性抛售,有人称之为熔断机制的磁石效应!

本文中,我们试图以简单的逻辑,来找到今天即7日有可能遭遇恐慌性抛售的熔断错杀股。

import pandas as pd
import numpy as np
from matplotlib import pylab
import matplotlib.pyplot as plt
import seaborn

1. 今日错杀股

from quartz.api import set_universe

univ = set_universe('A')
univ.remove('002778.XSHE')  # 删除2016-01-06上市新股

以最浅显地理解,错杀股票可能存在于以下情况中:

  • 今日开盘涨势不错,到首次熔断时仍为红盘,首次熔断结束后杀跌;
  • 今日开盘处于跌势,首次熔断之前跌的少,而首次熔断到二次熔断之间杀跌;
  • 首次熔断结束后开始交易,先杀跌,然后有明显拉升迹象,使得二次熔断时价格高于首次熔断时价格

三种情况下的走势如下图所示:

# 沪深300指数今日走势
hs300PreClose = DataAPI.MktIdxdGet(tradeDate='20160106',ticker='399300').closeIndex.values[0]
hs300 = DataAPI.MktBarRTIntraDayGet(securityID='399300.XSHE',startTime='09:30',endTime='10:30')
hs300['hs300 index'] = hs300.closePrice/hs300PreClose - 1
hs300 = hs300[['barTime','hs300 index']]

# 第一种情况,例如‘山东黄金’
case1PrePrice = DataAPI.MktEqudAdjGet(tradeDate='20160106',ticker='600547').closePrice.values[0]
case1 = DataAPI.MktBarRTIntraDayGet(securityID='600547.XSHG',startTime='09:30',endTime='10:30')
case1['600547.XSHG'] = case1.closePrice/case1PrePrice - 1
case1 = case1[['barTime','600547.XSHG']]

# 第二种情况,例如‘红豆股份’
case2PrePrice = DataAPI.MktEqudAdjGet(tradeDate='20160106',ticker='600400').closePrice.values[0]
case2 = DataAPI.MktBarRTIntraDayGet(securityID='600400.XSHG',startTime='09:30',endTime='10:30')
case2['600400.XSHG'] = case2.closePrice/case2PrePrice - 1
case2 = case2[['barTime','600400.XSHG']]

# 第三种情况,例如‘天宝股份’
case3PrePrice = DataAPI.MktEqudAdjGet(tradeDate='20160106',ticker='002220').closePrice.values[0]
case3 = DataAPI.MktBarRTIntraDayGet(securityID='002220.XSHE',startTime='09:30',endTime='10:30')
case3['002220.XSHE'] = case3.closePrice/case3PrePrice - 1
case3 = case3[['barTime','002220.XSHE']]

for case in (case1,case2,case3):
    hs300 = pd.merge(hs300,case)

hs300 = hs300.set_index('barTime')
hs300.plot(figsize=(10,6))

<matplotlib.axes.AxesSubplot at 0x6e01210>

根据以上分析,我们拿取今日行情数据,对全A股中的股票做分析,得到表格如下,其中:

  • preClose: 昨日收盘价
  • 1stPrice: 首次熔断时价格
  • 2ndPrice: 二次熔断时价格
  • 1stCollapse: 首次熔断时股价跌幅
  • 2ndCollapse: 首次熔断结束,之后股价继续下跌的幅度,即首次熔断后今日股价又下跌了这么多
  • collapseRatio:首次熔断之后的跌幅和首次熔断之前的跌幅的比例
  • lowBetCollapse:首次熔断和二次熔断之间的股价低点
  • closeToLow: 二次熔断时的价格和lowBetCollapse的比例
cols = ['preClose','1stPrice','2ndPrice','1stCollapse','2ndCollapse','collapseRatio','lowBetCollapse','closeToLow']
collapse0107 = pd.DataFrame(0.0,index=univ,columns=cols)

# 股票前收盘价
collapse0107['preClose'] = DataAPI.MktEqudGet(tradeDate='20160106',secID=univ,field='secID,closePrice',pandas='1').set_index('secID')

# 股票在-5%和-7%熔断时候的价格
for stk in collapse0107.index:
    price = DataAPI.MktBarRTIntraDayGet(securityID=stk,startTime='09:56',endTime='10:03').closePrice.values
    collapse0107['1stPrice'][stk] = price[0]
    collapse0107['2ndPrice'][stk] = price[-1]
    collapse0107['lowBetCollapse'][stk] = np.min(price)

# 两次熔断前的股票跌幅
collapse0107['1stCollapse'] = 1-collapse0107['1stPrice']/collapse0107['preClose']
collapse0107['2ndCollapse'] = 1-collapse0107['2ndPrice']/collapse0107['preClose'] - collapse0107['1stCollapse']

# 二次熔断跌幅和一次熔断跌幅比
collapse0107['collapseRatio'] = collapse0107['2ndCollapse']/collapse0107['1stCollapse']

# 第二次熔断时价格与两次熔断之间的最低价的比值
collapse0107['closeToLow'] = collapse0107['2ndPrice']/collapse0107['lowBetCollapse']

collapse0107.sort(columns='collapseRatio',inplace=True)
collapse0107 = collapse0107[~np.isnan(collapse0107.collapseRatio)]

collapse0107.tail()
preClose1stPrice2ndPrice1stCollapse2ndCollapsecollapseRatiolowBetCollapsecloseToLow
603398.XSHG123.01121.00110.710.0163400.0836525.119403110.711
002750.XSHE40.5940.0537.000.0133040.0751425.64814837.001
600569.XSHG3.583.553.310.0083800.0670398.0000003.311
002768.XSHE71.1771.0066.000.0023890.07025429.41176566.001
600782.XSHG5.815.805.310.0017210.08433749.0000005.311

按照以上数据,综合前面的简单逻辑,我们利用以下条件来选择错杀股:

  • collapseRatio > 1.5
  • collapseRatio < -0.9
  • closeToLow > 1.02

得到约40只股票如下

good = collapse0107[(collapse0107.collapseRatio>1.5) | (collapse0107.collapseRatio<-0.9) | (collapse0107.closeToLow>1.02)].index
good_stks = DataAPI.MktEqudGet(secID=good,tradeDate='20160107',field='secID,secShortName,tradeDate,preClosePrice,closePrice')
good_stks
secIDsecShortNametradeDatepreClosePriceclosePrice
0000726.XSHE鲁泰A2016-01-0713.6713.05
1000766.XSHE通化金马2016-01-0714.0412.68
2000838.XSHE财信发展2016-01-0753.3449.92
3000856.XSHE冀东装备2016-01-0712.9112.00
4000937.XSHE冀中能源2016-01-075.375.14
5002155.XSHE湖南黄金2016-01-079.399.14
6002220.XSHE天宝股份2016-01-0716.4615.15
7002251.XSHE步步高2016-01-0714.6213.62
8002283.XSHE天润曲轴2016-01-0719.4718.35
9002291.XSHE星期六2016-01-0714.2413.03
10002355.XSHE兴民钢圈2016-01-0718.8316.95
11002444.XSHE巨星科技2016-01-0719.4417.85
12002506.XSHE协鑫集成2016-01-079.859.66
13002517.XSHE泰亚股份2016-01-0757.9852.93
14002575.XSHE群兴玩具2016-01-0717.6716.87
15002588.XSHE史丹利2016-01-0731.1528.13
16002615.XSHE哈尔斯2016-01-0729.1626.64
17002617.XSHE露笑科技2016-01-0723.1721.12
18002621.XSHE三垒股份2016-01-0720.9120.00
19002640.XSHE跨境通2016-01-0731.6831.42
20002702.XSHE海欣食品2016-01-0724.5923.05
21002750.XSHE龙津药业2016-01-0740.5937.96
22002768.XSHE国恩股份2016-01-0771.1767.03
23002779.XSHE中坚科技2016-01-0791.2082.62
24300013.XSHE新宁物流2016-01-0717.5016.38
25300148.XSHE天舟文化2016-01-0723.4321.48
26300179.XSHE四方达2016-01-079.799.18
27300320.XSHE海达股份2016-01-0712.8811.95
28600005.XSHG武钢股份2016-01-073.663.30
29600057.XSHG象屿股份2016-01-0712.0111.25
30600262.XSHG北方股份2016-01-0735.6933.50
31600265.XSHGST景谷2016-01-0729.8128.36
32600291.XSHG西水股份2016-01-0726.1124.16
33600298.XSHG安琪酵母2016-01-0730.3029.47
34600328.XSHG兰太实业2016-01-0713.6312.54
35600395.XSHG盘江股份2016-01-079.108.19
36600448.XSHG华纺股份2016-01-079.018.60
37600547.XSHG山东黄金2016-01-0721.8921.10
38600569.XSHG安阳钢铁2016-01-073.583.38
39600671.XSHG天目药业2016-01-0732.9832.82
40600732.XSHG*ST新梅2016-01-078.518.46
41600782.XSHG新钢股份2016-01-075.815.54
42600874.XSHG创业环保2016-01-079.639.67
43601001.XSHG大同煤业2016-01-075.785.75
44603398.XSHG邦宝益智2016-01-07123.01111.39

我们还想看一下上述股票在过去的05、06两个交易日的表现:

fig = plt.figure(figsize=(10,8))

ax = fig.add_subplot(211)
fullA = DataAPI.MktEqudAdjGet(secID=univ, beginDate='20160104', endDate='20160106', field='secID,tradeDate,closePrice', pandas='1')
fullA = pd.DataFrame(fullA.groupby('secID').last().closePrice/fullA.groupby('secID').first().closePrice - 1)
ax = pylab.hist(fullA.closePrice,bins=50,histtype='stepfilled',range=(-0.22,0.22))
pylab.xlabel("(01-05 to 01-06) 2 Days' Returns")
pylab.ylabel('Number of stocks')

ax = fig.add_subplot(212)
good_stk_data = DataAPI.MktEqudAdjGet(secID=good, beginDate='20160104', endDate='20160106', field='secID,tradeDate,closePrice', pandas='1')
good_stk_data = pd.DataFrame(good_stk_data.groupby('secID').last().closePrice/good_stk_data.groupby('secID').first().closePrice - 1)
ax = pylab.hist(good_stk_data.closePrice,bins=50,histtype='stepfilled',range=(-0.22,0.22))
pylab.xlabel("(01-05 to 01-06) 2 Days' Returns")
pylab.ylabel('Number of stocks')

<matplotlib.text.Text at 0x7335050>

图中,上图为全A股在过去的5、6日两个交易日收益表现分布;下图为我们选出来的今日错杀股在5、6两个交易日的收益表现分布;

明显地,我们看出选出来的股票在过去两天表现比较出色;当然,过去两天的表现好不代表它们今天被错杀

2. 上次熔断时的4日被错杀股

利用上节中的选股条件,我们选出来4日熔断错杀股,来验证我们的逻辑

cols = ['preClose','1stPrice','2ndPrice','1stCollapse','2ndCollapse','collapseRatio','lowBetCollapse','closeToLow']
collapse0104 = pd.DataFrame(0.0,index=univ,columns=cols)

# 股票前收盘价
collapse0104['preClose'] = DataAPI.MktEqudGet(tradeDate='20151231',secID=univ,field='secID,closePrice',pandas='1').set_index('secID')

# 股票在-5%和-7%熔断时候的价格
for stk in collapse0104.index:
    price = DataAPI.MktBarHistOneDayGet(securityID=stk,date='20160104',startTime='13:25',endTime='13:40').closePrice.values
    collapse0104['1stPrice'][stk] = price[0]
    collapse0104['2ndPrice'][stk] = price[-1]
    collapse0104['lowBetCollapse'][stk] = np.min(price)

# 两次熔断前的股票跌幅
collapse0104['1stCollapse'] = 1-collapse0104['1stPrice']/collapse0104['preClose']
collapse0104['2ndCollapse'] = 1-collapse0104['2ndPrice']/collapse0104['preClose'] - collapse0104['1stCollapse']

collapse0104['closeToLow'] = collapse0104['2ndPrice']/collapse0104['lowBetCollapse']

# 二次熔断跌幅和一次熔断跌幅比
collapse0104['collapseRatio'] = collapse0104['2ndCollapse']/collapse0104['1stCollapse']

collapse0104.sort(columns='collapseRatio',inplace=True)
collapse0104 = collapse0104[~np.isnan(collapse0104.collapseRatio)]

collapse0104.tail()
preClose1stPrice2ndPrice1stCollapse2ndCollapsecollapseRatiolowBetCollapsecloseToLow
600836.XSHG31.3131.2830.370.0009580.02906430.33333329.471.030540
600178.XSHG11.2311.2310.600.0000000.056100inf10.481.011450
600822.XSHG15.0115.0114.280.0000000.048634inf14.111.012048
002686.XSHE17.6217.6216.900.0000000.040863inf16.181.044499
002009.XSHE20.7520.7519.710.0000000.050120inf19.201.026563

按照之前的选股条件,我们选出来了4日熔断被错杀的股票如下:

good = collapse0104[(collapse0104.collapseRatio>1.5) | (collapse0104.collapseRatio<-0.9) | (collapse0104.closeToLow>1.02)].index
good_stks = DataAPI.MktEqudGet(secID=good,tradeDate='20160107',field='secID,secShortName,tradeDate,preClosePrice,closePrice')
good_stks
secIDsecShortNametradeDatepreClosePriceclosePrice
0000040.XSHE宝安地产2016-01-0715.4513.91
1000048.XSHE康达尔2016-01-0744.6840.21
2000517.XSHE荣安地产2016-01-076.205.58
3000519.XSHE江南红箭2016-01-0719.2017.28
4000520.XSHE长航凤凰2016-01-0713.1111.80
5000547.XSHE航天发展2016-01-0718.8116.94
6000552.XSHE靖远煤电2016-01-079.858.87
7000597.XSHE东北制药2016-01-0711.5010.36
8000667.XSHE美好集团2016-01-075.625.06
9000708.XSHE大冶特钢2016-01-0713.2011.88
10000709.XSHE河北钢铁2016-01-073.673.30
11000723.XSHE美锦能源2016-01-0714.1912.77
12000757.XSHE浩物股份2016-01-0710.809.72
13000767.XSHE漳泽电力2016-01-076.295.66
14000795.XSHE太原刚玉2016-01-0717.1215.41
15000801.XSHE四川九洲2016-01-0730.2627.24
16000898.XSHE鞍钢股份2016-01-075.194.68
17000932.XSHE华菱钢铁2016-01-073.854.14
18000952.XSHE广济药业2016-01-0721.1119.00
19000990.XSHE诚志股份2016-01-0724.5922.18
20002009.XSHE天奇股份2016-01-0722.8520.57
21002013.XSHE中航机电2016-01-0724.0221.62
22002025.XSHE航天电器2016-01-0725.4222.89
23002045.XSHE国光电器2016-01-0718.1016.29
24002149.XSHE西部材料2016-01-0729.7026.73
25002157.XSHE正邦科技2016-01-0721.1319.30
26002179.XSHE中航光电2016-01-0737.5634.11
27002191.XSHE劲嘉股份2016-01-0716.7115.04
28002200.XSHE云投生态2016-01-0727.9925.19
29002220.XSHE天宝股份2016-01-0716.4615.15
..................
104600655.XSHG豫园商城2016-01-0715.4414.20
105600662.XSHG强生控股2016-01-0717.1315.42
106600663.XSHG陆家嘴2016-01-0750.9445.93
107600685.XSHG中船防务2016-01-0741.4137.27
108600734.XSHG实达集团2016-01-0724.9022.41
109600755.XSHG厦门国贸2016-01-078.247.43
110600760.XSHG中航黑豹2016-01-0714.6013.17
111600774.XSHG汉商集团2016-01-0729.0026.10
112600822.XSHG上海物贸2016-01-0715.9714.37
113600826.XSHG兰生股份2016-01-0736.1632.54
114600833.XSHG第一医药2016-01-0718.5516.71
115600834.XSHG申通地铁2016-01-0720.3018.27
116600836.XSHG界龙实业2016-01-0734.3230.89
117600841.XSHG上柴股份2016-01-0718.2816.45
118600855.XSHG航天长峰2016-01-0745.3040.77
119600860.XSHG京城股份2016-01-0711.3810.24
120600868.XSHG梅雁吉祥2016-01-077.616.89
121600879.XSHG航天电子2016-01-0718.9417.05
122600893.XSHG中航动力2016-01-0742.8738.58
123600965.XSHG福成五丰2016-01-0714.8513.66
124601069.XSHG西部黄金2016-01-0723.7121.97
125601233.XSHG桐昆股份2016-01-0712.3711.16
126601636.XSHG旗滨集团2016-01-075.184.70
127601700.XSHG风范股份2016-01-0710.809.72
128601888.XSHG中国国旅2016-01-0756.4951.97
129601890.XSHG亚星锚链2016-01-0713.4312.09
130601989.XSHG中国重工2016-01-079.408.48
131601998.XSHG中信银行2016-01-076.846.39
132603696.XSHG安记食品2016-01-0764.1157.70
133603901.XSHG永创智能2016-01-0740.8436.76
134 rows × 5 columns

我们选出来的4日熔断被错杀的股票,在后面的5、6两日的表现究竟如何呢?请看下图

fig = plt.figure(figsize=(10,8))

ax = fig.add_subplot(211)
fullA = DataAPI.MktEqudAdjGet(secID=univ, beginDate='20160104', endDate='20160106', field='secID,tradeDate,closePrice', pandas='1')
fullA = pd.DataFrame(fullA.groupby('secID').last().closePrice/fullA.groupby('secID').first().closePrice - 1)
ax = pylab.hist(fullA.closePrice,bins=50,histtype='stepfilled',range=(-0.22,0.22))
pylab.xlabel("(01-05 to 01-06) 2 Days' Returns")
pylab.ylabel('Number of stocks')

ax = fig.add_subplot(212)
good_stk_data = DataAPI.MktEqudAdjGet(secID=good, beginDate='20160104', endDate='20160106', field='secID,tradeDate,closePrice', pandas='1')
good_stk_data = pd.DataFrame(good_stk_data.groupby('secID').last().closePrice/good_stk_data.groupby('secID').first().closePrice - 1)
ax = pylab.hist(good_stk_data.closePrice,bins=50,histtype='stepfilled',range=(-0.22,0.22))
pylab.xlabel("(01-05 to 01-06) 2 Days' Returns")
pylab.ylabel('Number of stocks')

<matplotlib.text.Text at 0x74df810>

图中,上图为全A股在过去的5、6日两个交易日收益表现分布;下图为我们选出来的4日熔断错杀股在5、6两个交易日的收益表现分布,可以看出选出的错杀股在过去两天均有10%左右的涨幅;

明显地,我们看出选出来的4日熔断错杀股在后面的两天表现出色

3. 结论

2节中对于4日熔断错杀股在5、6两个交易日的数据,似乎能够支持我们在第1节中的错杀股选股逻辑;对于1节中选出来的今天即7日错杀股,搬个板凳看后面走势究竟如何

PS:股市风险大,投资需谨慎;本文仅是研究之用,不构成任何荐股观点

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文