形态验证并选股-“相似K线”的技术应用:
“W底”,“多头上涨”,“趋势回踩”,”上涨中继“这些都是常见的K线形态,以”上涨中继“为例,当股价快速上涨后,出现盘整形态而非顶部形态,预示股价还会进一步上涨,那么本节主要讲述”上涨中继”形态是否能够预测未来股价上涨,以及如何应用“上涨中继”形态,来快速选股。
第一步:选取一段标准的“上涨中继”形态K线图
第二步:形态验证,在历史行情中寻找相似度高达0.8的K线图,并计算后5日、20日、60日的收益率。分析: 1.历史4年中“上涨中继”形态发生后,后5日上涨概率仅为30%,后20上涨概率也仅为50%,但后60日上涨概率高达70% 2.形态发生后,5日收益率均值为-2.45%,20日收益率均值仅为0.97%,但后60日收益率均值高达15.60% 并初步得出结论: 上涨中继形态发生后,技术分析者应该尽量选择低位介入,并且持有一段时间,而不是早早离场。
第三步:形态选股应用,我们认为“上涨中继”是一个较优质的中线买入机会,我们对全市场个股进行“上涨中继”形态选股,寻找出相似度最高的股票:ST天业,相似度为0.895,K线形态符合“上涨中继”,如下:
结束语:
"相似K线"技术相比于传统的K线组合而言更具技术性,其还有较多的运用空间,比如:运用顶部形态来监控个股潜在的下跌风险,运用相似度来监控个股是否脱离大盘走势,研究各类形态的上涨预测能力,并应用于选股等等。 注意:文中对股价的预测来源于模型运算结果,不构成投资建议!
参考文献:
-日本蜡烛图技术 [美] 史蒂夫·尼森
点击获取内容完整源码(仅支持PC):
点击→机器学习
微信扫码,在线阅读~:
形态验证:快速上涨后,出现盘整形态,后续上涨的可能性多大?
data = get_price('603383.SH',None,'20190114','1d',['open','high','low','close'],bar_count=60,is_panel =1)
startdate ='20181019'
enddate ='20190114'
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import datetime
close1 = data['close']
open1 = data['open']
high1 = data['high']
low1 = data['low']
#画图
fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')
fig.subplots_adjust()
ticks = ax.set_xticks([0,60])
labels = ax.set_xticklabels([startdate,enddate], fontsize=10)
plt.yticks()
plt.title("{} K线走势图".format('上涨中继'),fontsize = 15)
plt.ylabel("股价",fontsize = 15)
candlestick2_ohlc(ax,open1,high1,low1,close1,width=0.6,colorup='red',colordown='green')
(<matplotlib.collections.LineCollection at 0x7f8b266317f0>, <matplotlib.collections.PolyCollection at 0x7f8b26983da0>)
data = get_price('603383.SH','20181019','20190211','1d',['open','high','low','close'],is_panel =1)
startdate ='20181019'
enddate ='20190211'
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import datetime
close1 = data['close']
open1 = data['open']
high1 = data['high']
low1 = data['low']
#画图
fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')
fig.subplots_adjust()
ticks = ax.set_xticks([0,60])
labels = ax.set_xticklabels([startdate,enddate], fontsize=10)
#支撑线
plt.plot([60,60],[np.min(low1),np.max(high1)],'gold',linewidth=3)
plt.yticks()
plt.title("{}形态发生后,理想中的后续走势".format('上涨中继'),fontsize = 15)
plt.ylabel("股价",fontsize = 15)
candlestick2_ohlc(ax,open1,high1,low1,close1,width=0.6,colorup='red',colordown='green')
(<matplotlib.collections.LineCollection at 0x7f8b25d5b978>, <matplotlib.collections.PolyCollection at 0x7f8b25d5b780>)
data = get_price('603383.SH',None,'20190114','1d',['open','high','low','close'],bar_count=60,is_panel =1)
close1 = data['close']
open1 = data['open']
high1 = data['high']
low1 = data['low']
indexcode = '000300.SH'
startdate = '20140101'
enddate = '20190201'
stocklist = get_index_stocks(indexcode,enddate)
data = get_price(stocklist,startdate,enddate,'1d',['open','high','low','close'],is_panel =1)
#收盘价
closedf = data['close'].fillna(0)
opendf = data['open'].fillna(0)
highdf = data['high'].fillna(0)
lowdf = data['low'].fillna(0)
dt = pd.DataFrame(columns=['stock','startdate','enddate','T'])
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index(enddate)
stocklist = list(closedf.columns)
y=0
import datetime
for d in list(range(60,num-20,20)):
print(d,num)
close2 = closedf.iloc[d-59:d+1]
opens2 = opendf.iloc[d-59:d+1]
high2 = highdf.iloc[d-59:d+1]
low2 = lowdf.iloc[d-59:d+1]
for s in stocklist:
corropen = round(np.corrcoef(open1,opens2[s])[0][1],3)
corrhigh = round(np.corrcoef(high1,high2[s])[0][1],3)
corrlow = round(np.corrcoef(low1,low2[s])[0][1],3)
corrclose = round(np.corrcoef(close1,close2[s])[0][1],3)
#综合值
T = (corropen+corrhigh+corrlow+corrclose)/4
startdate = trade[d-59]
enddate = trade[d+1]
dt.loc[y] = [s,startdate,enddate,T]
y+=1
dt = dt.fillna(0)
dt = dt.sort_values(by='T',ascending=False)
dt
60 1242 80 1242 100 1242 120 1242 140 1242 160 1242 180 1242 200 1242 220 1242 240 1242 260 1242 280 1242 300 1242 320 1242 340 1242 360 1242 380 1242 400 1242 420 1242 440 1242 460 1242 480 1242 500 1242 520 1242 540 1242 560 1242 580 1242 600 1242 620 1242 640 1242 660 1242 680 1242 700 1242 720 1242 740 1242 760 1242 780 1242 800 1242 820 1242 840 1242 860 1242 880 1242 900 1242 920 1242 940 1242 960 1242 980 1242 1000 1242 1020 1242 1040 1242 1060 1242 1080 1242 1100 1242 1120 1242 1140 1242 1160 1242 1180 1242 1200 1242 1220 1242
Out[29]:
stock | startdate | enddate | T | |
---|---|---|---|---|
2046 | 601328.SH | 20140703 | 20140926 | 0.92825 |
2066 | 601788.SH | 20140703 | 20140926 | 0.92750 |
14425 | 000703.SZ | 20171208 | 20180312 | 0.92525 |
13279 | 002460.SZ | 20170811 | 20171110 | 0.92400 |
1859 | 002142.SZ | 20140703 | 20140926 | 0.92225 |
3194 | 600637.SH | 20141031 | 20150127 | 0.91750 |
1916 | 600000.SH | 20140703 | 20140926 | 0.91350 |
9898 | 603986.SH | 20160816 | 20161117 | 0.91200 |
4871 | 002310.SZ | 20150429 | 20150724 | 0.91000 |
4977 | 600482.SH | 20150429 | 20150724 | 0.90850 |
9533 | 601166.SH | 20160719 | 20161020 | 0.90450 |
11941 | 601228.SH | 20170317 | 20170616 | 0.90325 |
14971 | 601838.SH | 20180108 | 20180411 | 0.90300 |
5383 | 601985.SH | 20150528 | 20150821 | 0.90200 |
1921 | 600015.SH | 20140703 | 20140926 | 0.90075 |
6901 | 000002.SZ | 20151124 | 20160224 | 0.90000 |
12625 | 000703.SZ | 20170616 | 20170908 | 0.89900 |
14093 | 603260.SH | 20171013 | 20180108 | 0.89825 |
5310 | 600886.SH | 20150528 | 20150821 | 0.89750 |
3776 | 600438.SH | 20141226 | 20150331 | 0.89675 |
1803 | 000069.SZ | 20140703 | 20140926 | 0.89625 |
2079 | 601901.SH | 20140703 | 20140926 | 0.89575 |
2022 | 601009.SH | 20140703 | 20140926 | 0.89500 |
11382 | 601939.SH | 20170113 | 20170418 | 0.89475 |
2082 | 601939.SH | 20140703 | 20140926 | 0.89475 |
2089 | 601998.SH | 20140703 | 20140926 | 0.89350 |
2453 | 002044.SZ | 20140828 | 20141128 | 0.89300 |
1932 | 600036.SH | 20140703 | 20140926 | 0.89125 |
240 | 601225.SH | 20140103 | 20140404 | 0.89075 |
9416 | 600000.SH | 20160719 | 20161020 | 0.88725 |
... | ... | ... | ... | ... |
10657 | 600233.SH | 20161117 | 20170217 | -0.86350 |
16076 | 600438.SH | 20180511 | 20180806 | -0.86425 |
5164 | 002230.SZ | 20150528 | 20150821 | -0.86425 |
2738 | 000895.SZ | 20140926 | 20141226 | -0.86475 |
7396 | 600674.SH | 20151222 | 20160323 | -0.86825 |
11925 | 601021.SH | 20170317 | 20170616 | -0.86825 |
14339 | 601216.SH | 20171110 | 20180205 | -0.86850 |
10763 | 601688.SH | 20161117 | 20170217 | -0.86875 |
11936 | 601198.SH | 20170317 | 20170616 | -0.86900 |
14379 | 601901.SH | 20171110 | 20180205 | -0.86900 |
14863 | 600339.SH | 20180108 | 20180411 | -0.87000 |
9747 | 600153.SH | 20160816 | 20161117 | -0.87000 |
365 | 002236.SZ | 20140207 | 20140507 | -0.87075 |
15448 | 600157.SH | 20180312 | 20180608 | -0.87100 |
12086 | 002558.SZ | 20170418 | 20170714 | -0.87575 |
12015 | 000503.SZ | 20170418 | 20170714 | -0.87675 |
15385 | 002555.SZ | 20180312 | 20180608 | -0.87825 |
10725 | 601021.SH | 20161117 | 20170217 | -0.87975 |
14711 | 000413.SZ | 20180108 | 20180411 | -0.88000 |
16123 | 601012.SH | 20180511 | 20180806 | -0.88050 |
16553 | 002044.SZ | 20180709 | 20181009 | -0.88150 |
16244 | 000983.SZ | 20180608 | 20180903 | -0.88225 |
15977 | 002450.SZ | 20180511 | 20180806 | -0.88375 |
16209 | 000402.SZ | 20180608 | 20180903 | -0.88650 |
15993 | 002673.SZ | 20180511 | 20180806 | -0.89125 |
3392 | 002625.SZ | 20141128 | 20150303 | -0.89250 |
209 | 600867.SH | 20140103 | 20140404 | -0.90050 |
10890 | 002602.SZ | 20161215 | 20170317 | -0.90350 |
12097 | 002797.SZ | 20170418 | 20170714 | -0.91150 |
8847 | 600153.SH | 20160520 | 20160816 | -0.91225 |
17700 rows × 4 columns
In [30]:
for s in [0,-1]:
stock = dt.iloc[s].stock
startdate = dt.iloc[s].startdate
enddate = dt.iloc[s].enddate
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stock
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index(enddate)
close1 = closedf[s].iloc[num-59:num+21]
open1 = opendf[s].iloc[num-59:num+21]
high1 = highdf[s].iloc[num-59:num+21]
low1 = lowdf[s].iloc[num-59:num+21]
#画图
fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')
fig.subplots_adjust()
#支撑线
plt.plot([60,60],[np.min(low1),np.max(high1)],'gold',linewidth=3)
ticks = ax.set_xticks([0,60])
labels = ax.set_xticklabels([startdate,enddate], fontsize=10)
plt.yticks()
plt.title("{} K线走势图".format(s),fontsize = 15)
plt.ylabel("股价",fontsize = 15)
candlestick2_ohlc(ax,open1,high1,low1,close1,width=0.6,colorup='red',colordown='green')
highdt = dt[dt['T']>0.8]
highdt['code'] = highdt.index
highdt['buyprice'] = highdt['code'].apply(lambda x:closedf[list(highdt['stock'])[list(highdt['code']).index(x)]].iloc[list(highdt['code']).index(x)])
highdt = highdt[highdt['buyprice']!=0]
highdt['5day'] = highdt['code'].apply(lambda x:closedf[list(highdt['stock'])[list(highdt['code']).index(x)]].iloc[list(highdt['code']).index(x)+5])
highdt['20day'] = highdt['code'].apply(lambda x:closedf[list(highdt['stock'])[list(highdt['code']).index(x)]].iloc[list(highdt['code']).index(x)+20])
highdt['60day'] = highdt['code'].apply(lambda x:closedf[list(highdt['stock'])[list(highdt['code']).index(x)]].iloc[list(highdt['code']).index(x)+60])
highdt['5day']=highdt['5day']/highdt['buyprice']-1
highdt['20day']=highdt['20day']/highdt['buyprice']-1
highdt['60day']=highdt['60day']/highdt['buyprice']-1
highdt
stock | startdate | enddate | T | code | buyprice | 5day | 20day | 60day | |
---|---|---|---|---|---|---|---|---|---|
2046 | 601328.SH | 20140703 | 20140926 | 0.92825 | 2046 | 2.46 | -0.012195 | -0.016260 | -0.032520 |
2066 | 601788.SH | 20140703 | 20140926 | 0.92750 | 2066 | 7.42 | -0.084906 | -0.060647 | -0.080863 |
14425 | 000703.SZ | 20171208 | 20180312 | 0.92525 | 14425 | 4.88 | -0.096311 | -0.008197 | -0.026639 |
13279 | 002460.SZ | 20170811 | 20171110 | 0.92400 | 13279 | 3.46 | -0.031792 | 0.309249 | 0.462428 |
1859 | 002142.SZ | 20140703 | 20140926 | 0.92225 | 1859 | 4.32 | -0.064815 | -0.004630 | -0.002315 |
3194 | 600637.SH | 20141031 | 20150127 | 0.91750 | 3194 | 31.28 | -0.026535 | -0.039003 | -0.158568 |
1916 | 600000.SH | 20140703 | 20140926 | 0.91350 | 1916 | 4.98 | -0.042169 | 0.024096 | 0.098394 |
4871 | 002310.SZ | 20150429 | 20150724 | 0.91000 | 4871 | 7.44 | -0.026882 | 0.056452 | -0.134409 |
4977 | 600482.SH | 20150429 | 20150724 | 0.90850 | 4977 | 8.69 | -0.002301 | 0.146145 | 0.215190 |
9533 | 601166.SH | 20160719 | 20161020 | 0.90450 | 9533 | 6.61 | 0.007564 | 0.039334 | 0.077156 |
1921 | 600015.SH | 20140703 | 20140926 | 0.90075 | 1921 | 4.46 | -0.020179 | 0.006726 | 0.044843 |
6901 | 000002.SZ | 20151124 | 20160224 | 0.90000 | 6901 | 4.17 | 0.071942 | -0.079137 | 0.040767 |
12625 | 000703.SZ | 20170616 | 20170908 | 0.89900 | 12625 | 4.91 | 0.008147 | 0.032587 | -0.075356 |
5310 | 600886.SH | 20150528 | 20150821 | 0.89750 | 5310 | 2.98 | 0.000000 | 0.010067 | 0.204698 |
3776 | 600438.SH | 20141226 | 20150331 | 0.89675 | 3776 | 3.94 | 0.000000 | 0.043147 | 0.025381 |
1803 | 000069.SZ | 20140703 | 20140926 | 0.89625 | 1803 | 4.29 | 0.000000 | -0.116550 | -0.053613 |
2079 | 601901.SH | 20140703 | 20140926 | 0.89575 | 2079 | 5.57 | 0.000000 | 0.007181 | -0.016158 |
2022 | 601009.SH | 20140703 | 20140926 | 0.89500 | 2022 | 2.09 | 0.000000 | 0.000000 | -0.038278 |
11382 | 601939.SH | 20170113 | 20170418 | 0.89475 | 11382 | 2.56 | 0.000000 | -0.062500 | -0.015625 |
2082 | 601939.SH | 20140703 | 20140926 | 0.89475 | 2082 | 2.54 | 0.000000 | -0.059055 | -0.011811 |
2089 | 601998.SH | 20140703 | 20140926 | 0.89350 | 2089 | 4.02 | 0.000000 | -0.024876 | -0.069652 |
2453 | 002044.SZ | 20140828 | 20141128 | 0.89300 | 2453 | 2.27 | 0.000000 | -0.057269 | -0.136564 |
1932 | 600036.SH | 20140703 | 20140926 | 0.89125 | 1932 | 6.95 | 0.000000 | -0.149640 | -0.089209 |
240 | 601225.SH | 20140103 | 20140404 | 0.89075 | 240 | 4.27 | 0.000000 | -0.182670 | -0.206089 |
9416 | 600000.SH | 20160719 | 20161020 | 0.88725 | 9416 | 5.03 | 0.000000 | -0.129225 | 0.061630 |
4780 | 601919.SH | 20150331 | 20150626 | 0.88725 | 4780 | 3.38 | 0.000000 | 0.000000 | -0.076923 |
2474 | 002411.SZ | 20140828 | 20141128 | 0.88700 | 2474 | 10.03 | 0.000000 | -0.103689 | -0.325025 |
1986 | 600547.SH | 20140703 | 20140926 | 0.88675 | 1986 | 16.10 | 0.000000 | 0.140373 | -0.037888 |
1842 | 000961.SZ | 20140703 | 20140926 | 0.88575 | 1842 | 2.57 | 0.000000 | 0.054475 | 0.058366 |
9561 | 601668.SH | 20160719 | 20161020 | 0.88525 | 9561 | 1.33 | 0.000000 | -0.022556 | 0.067669 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
4205 | 000157.SZ | 20150303 | 20150528 | 0.80525 | 4205 | 5.52 | 0.018116 | -0.003623 | 0.369565 |
12840 | 601225.SH | 20170616 | 20170908 | 0.80475 | 12840 | 5.34 | 0.131086 | 0.011236 | 0.625468 |
14872 | 600398.SH | 20180108 | 20180411 | 0.80450 | 14872 | 10.45 | 0.023923 | 0.035407 | 0.408612 |
3786 | 600547.SH | 20141226 | 20150331 | 0.80425 | 3786 | 24.61 | 0.089395 | -0.042259 | 0.225518 |
9564 | 601727.SH | 20160719 | 20161020 | 0.80425 | 9564 | 9.96 | 0.134538 | -0.022088 | 0.867470 |
1837 | 000876.SZ | 20140703 | 20140926 | 0.80425 | 1837 | 6.92 | -0.049133 | -0.013006 | 0.575145 |
9917 | 000553.SZ | 20160913 | 20161215 | 0.80425 | 9917 | 14.45 | -0.010381 | -0.005536 | 0.074048 |
14583 | 600519.SH | 20171208 | 20180312 | 0.80425 | 14583 | 142.24 | -0.056384 | -0.007944 | 0.400028 |
11170 | 002304.SZ | 20170113 | 20170418 | 0.80400 | 11170 | 46.80 | 0.064957 | 0.010470 | 0.259829 |
12889 | 601998.SH | 20170616 | 20170908 | 0.80400 | 12889 | 5.89 | 0.023769 | -0.003396 | 0.234295 |
9509 | 600867.SH | 20160719 | 20161020 | 0.80375 | 9509 | 9.63 | -0.164071 | -0.046729 | 0.470405 |
7875 | 002415.SZ | 20160224 | 20160520 | 0.80375 | 7875 | 11.21 | -0.068689 | -0.033898 | 0.134701 |
9016 | 000538.SZ | 20160621 | 20160913 | 0.80375 | 9016 | 59.77 | -0.041660 | 0.010708 | 0.061904 |
8415 | 000503.SZ | 20160421 | 20160719 | 0.80375 | 8415 | 40.70 | -0.057740 | -0.004914 | 0.094595 |
6401 | 300017.SZ | 20150922 | 20151222 | 0.80350 | 6401 | 12.25 | -0.166531 | -0.025306 | 0.462041 |
14115 | 000503.SZ | 20171110 | 20180205 | 0.80350 | 14115 | 43.64 | -0.121448 | -0.060495 | 0.112511 |
11144 | 000983.SZ | 20170113 | 20170418 | 0.80350 | 11144 | 8.07 | -0.078067 | -0.006196 | 0.080545 |
12722 | 600016.SH | 20170616 | 20170908 | 0.80325 | 12722 | 7.33 | -0.042292 | -0.020464 | 0.099591 |
3310 | 000408.SZ | 20141128 | 20150303 | 0.80275 | 3310 | 13.40 | -0.140299 | 0.007463 | 0.567164 |
12791 | 600585.SH | 20170616 | 20170908 | 0.80275 | 12791 | 18.66 | -0.051447 | -0.004287 | 0.087889 |
13280 | 002466.SZ | 20170811 | 20171110 | 0.80250 | 13280 | 13.35 | 0.068165 | 0.003745 | 0.240449 |
3567 | 601800.SH | 20141128 | 20150303 | 0.80250 | 3567 | 14.60 | -0.121918 | -0.002055 | 0.276712 |
2784 | 002508.SZ | 20140926 | 20141226 | 0.80250 | 2784 | 13.53 | -0.073910 | 0.003695 | 0.481153 |
9513 | 600900.SH | 20160719 | 20161020 | 0.80200 | 9513 | 8.68 | -0.101382 | -0.002304 | 0.267281 |
4762 | 601669.SH | 20150331 | 20150626 | 0.80175 | 4762 | 8.83 | -0.163080 | -0.046433 | 0.921857 |
852 | 601398.SH | 20140307 | 20140605 | 0.80150 | 852 | 3.96 | -0.146465 | -0.053030 | 0.131313 |
9587 | 601992.SH | 20160719 | 20161020 | 0.80125 | 9587 | 5.45 | -0.183486 | 0.020183 | 0.170642 |
9360 | 002146.SZ | 20160719 | 20161020 | 0.80025 | 9360 | 10.29 | -0.376093 | -0.081633 | -0.124393 |
6408 | 300124.SZ | 20150922 | 20151222 | 0.80025 | 6408 | 20.78 | -0.162175 | -0.026949 | 0.446583 |
13613 | 300296.SZ | 20170908 | 20171208 | 0.80025 | 13613 | 5.59 | -0.273703 | -0.051878 | 0.329159 |
284 rows × 9 columns
highdt.describe()
Out[32]:
T | code | buyprice | 5day | 20day | 60day | |
---|---|---|---|---|---|---|
count | 284.000000 | 284.000000 | 284.000000 | 284.000000 | 284.000000 | 284.000000 |
mean | 0.839151 | 6365.904930 | 10.044085 | -0.025943 | 0.008055 | 0.157349 |
std | 0.030846 | 4523.933308 | 14.091066 | 0.086513 | 0.063017 | 0.220266 |
min | 0.800250 | 4.000000 | 1.330000 | -0.507956 | -0.186047 | -0.325025 |
25% | 0.814625 | 2054.750000 | 4.057500 | -0.050792 | -0.022619 | 0.000000 |
50% | 0.830625 | 4756.000000 | 6.615000 | -0.008753 | 0.002213 | 0.118084 |
75% | 0.856938 | 9569.750000 | 11.180000 | 0.007572 | 0.034661 | 0.262899 |
max | 0.928250 | 17491.000000 | 142.240000 | 0.289093 | 0.314885 | 1.057554 |
In [33]:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 1, 0.618]) #插入面板2
x1_list = list(highdt['5day'])
y=np.array(x1_list)
x=np.array(range(0,len(x1_list)))
axes.plot(x, y, 'r')
axes.set_xlabel('相似度递减',fontsize=15)
axes.set_ylabel('收益率',fontsize=15)
axes.set_title('上涨中继买入后五日收益率',fontsize=15)
<matplotlib.text.Text at 0x7f8b26065f60>
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 1, 0.618]) #插入面板2
x1_list = list(highdt['20day'])
y=np.array(x1_list)
x=np.array(range(0,len(x1_list)))
axes.plot(x, y, 'r')
axes.set_xlabel('相似度递减',fontsize=15)
axes.set_ylabel('收益率',fontsize=15)
axes.set_title('上涨中继买入后二十日收益率',fontsize=15)
<matplotlib.text.Text at 0x7f8b273dcc18>
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 1, 0.618]) #插入面板2
x1_list = list(highdt['60day'])
y=np.array(x1_list)
x=np.array(range(0,len(x1_list)))
axes.plot(x, y, 'r')
axes.set_xlabel('相似度递减',fontsize=15)
axes.set_ylabel('收益率',fontsize=15)
axes.set_title('上涨中继买入后六十日收益率',fontsize=15)
<matplotlib.text.Text at 0x7f8b25cb0748>
形态选股应用
以上涨中继作为筛选形态,从历史行情中挑出一段行情。
data = get_price('603383.SH',None,'20190114','1d',['open','high','low','close'],bar_count=60,is_panel =1)
startdate ='20181019'
enddate ='20190114'
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import datetime
close1 = data['close']
open1 = data['open']
high1 = data['high']
low1 = data['low']
#画图
fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')
fig.subplots_adjust()
ticks = ax.set_xticks([0,60])
labels = ax.set_xticklabels([startdate,enddate], fontsize=10)
plt.yticks()
plt.title("{} K线走势图".format('趋势上涨'),fontsize = 15)
plt.ylabel("股价",fontsize = 15)
candlestick2_ohlc(ax,open1,high1,low1,close1,width=0.6,colorup='red',colordown='green')
(<matplotlib.collections.LineCollection at 0x7f8b273c4a90>, <matplotlib.collections.PolyCollection at 0x7f8b273c4e80>)
全市场中寻找目前趋势上涨的股票
date = '20190211'
stocklist = list(get_all_securities('stock',date).index)
stocklist
['300056.SZ', '300674.SZ', '300108.SZ', '300357.SZ', '600841.SH', '600495.SH', '300249.SZ', '002852.SZ', '000058.SZ', '002568.SZ', '300199.SZ', '300490.SZ', '000893.SZ', '603859.SH', '600565.SH', '603063.SH', '600117.SH', '300036.SZ', '300746.SZ', '002906.SZ', '600052.SH', '002187.SZ', '300613.SZ', '000596.SZ', '002351.SZ', '000736.SZ', '000810.SZ', '002767.SZ', '601318.SH', '300183.SZ', '002755.SZ', '002502.SZ', '603722.SH', '002298.SZ', '300711.SZ', '300678.SZ', '600362.SH', '002176.SZ', '600887.SH', '300430.SZ', '300712.SZ', '300291.SZ', '300486.SZ', '600876.SH', '601988.SH', '601100.SH', '603688.SH', '600078.SH', '603958.SH', '000811.SZ', '000537.SZ', '300260.SZ', '002434.SZ', '000541.SZ', '002673.SZ', '600804.SH', '603268.SH', '300567.SZ', '600038.SH', '300382.SZ', '600370.SH', '000150.SZ', '600158.SH', '000888.SZ', '603458.SH', '300723.SZ', '300670.SZ', '600100.SH', '600678.SH', '603566.SH', '600237.SH', '002166.SZ', '002073.SZ', '300071.SZ', '601666.SH', '600422.SH', '002642.SZ', '000027.SZ', '002537.SZ', '000631.SZ', '002457.SZ', '603359.SH', '600189.SH', '600592.SH', '600290.SH', '603988.SH', '002857.SZ', '300105.SZ', '603321.SH', '601398.SH', '600755.SH', '002480.SZ', '600919.SH', '300690.SZ', '603133.SH', '300328.SZ', '300759.SZ', '603979.SH', '002055.SZ', '002741.SZ', '300391.SZ', '600211.SH', '002278.SZ', '000639.SZ', '300273.SZ', '300543.SZ', '000823.SZ', '300521.SZ', '000762.SZ', '002493.SZ', '000597.SZ', '600765.SH', '000826.SZ', '300680.SZ', '300341.SZ', '002628.SZ', '603611.SH', '000573.SZ', '000766.SZ', '001979.SZ', '600620.SH', '300575.SZ', '000726.SZ', '002920.SZ', '002081.SZ', '002797.SZ', '002383.SZ', '300471.SZ', '600011.SH', '600151.SH', '300628.SZ', '600007.SH', '300488.SZ', '300539.SZ', '000831.SZ', '000539.SZ', '300538.SZ', '600814.SH', '000889.SZ', '002839.SZ', '600926.SH', '600805.SH', '002155.SZ', '002319.SZ', '600562.SH', '000652.SZ', '000603.SZ', '600313.SH', '002131.SZ', '000812.SZ', '300332.SZ', '600775.SH', '603886.SH', '000963.SZ', '300535.SZ', '000656.SZ', '002261.SZ', '603029.SH', '300369.SZ', '600326.SH', '600811.SH', '300451.SZ', '600488.SH', '600392.SH', '603966.SH', '600597.SH', '002651.SZ', '002733.SZ', '600509.SH', '600477.SH', '300485.SZ', '600978.SH', '603712.SH', '601179.SH', '600055.SH', '002903.SZ', '000968.SZ', '002526.SZ', '000088.SZ', '603260.SH', '000690.SZ', '600185.SH', '002392.SZ', '600398.SH', '300444.SZ', '002865.SZ', '002897.SZ', '002057.SZ', '603678.SH', '002510.SZ', '600409.SH', '002484.SZ', '300065.SZ', '002943.SZ', '002276.SZ', '000510.SZ', '300431.SZ', '300097.SZ', '600022.SH', '600171.SH', '000014.SZ', '300124.SZ', '300651.SZ', '600983.SH', '002915.SZ', '600010.SH', '000683.SZ', '600621.SH', '002476.SZ', '300368.SZ', '300525.SZ', '300394.SZ', '300453.SZ', '000955.SZ', '300003.SZ', '600777.SH', '002144.SZ', '002584.SZ', '002592.SZ', '600220.SH', '600221.SH', '603716.SH', '300658.SZ', '600622.SH', '002832.SZ', '603603.SH', '002381.SZ', '300195.SZ', '000806.SZ', '002451.SZ', '300224.SZ', '600088.SH', '002418.SZ', '300347.SZ', '603733.SH', '600153.SH', '603679.SH', '601800.SH', '601108.SH', '002743.SZ', '600982.SH', '300320.SZ', '000922.SZ', '603648.SH', '300045.SZ', '600187.SH', '600594.SH', '300634.SZ', '600673.SH', '000096.SZ', '600306.SH', '600651.SH', '002577.SZ', '601010.SH', '600103.SH', '002204.SZ', '603311.SH', '600846.SH', '000760.SZ', '002033.SZ', '603585.SH', '600396.SH', '002438.SZ', '002564.SZ', '000543.SZ', '601311.SH', '603689.SH', '000782.SZ', '300725.SZ', '002727.SZ', '603685.SH', '600094.SH', '600609.SH', '300365.SZ', '002691.SZ', '600785.SH', '002037.SZ', '601966.SH', '300591.SZ', '000902.SZ', '600888.SH', '603036.SH', '603916.SH', '002668.SZ', '600405.SH', '603839.SH', '300167.SZ', '002294.SZ', '600209.SH', '000589.SZ', '603986.SH', '000925.SZ', '002390.SZ', '600826.SH', '000068.SZ', '000680.SZ', '300139.SZ', '603383.SH', '603887.SH', '000973.SZ', '002137.SZ', '300505.SZ', '002788.SZ', '300026.SZ', '000055.SZ', '002787.SZ', '000004.SZ', '600360.SH', '600480.SH', '000558.SZ', '300545.SZ', '300305.SZ', '600059.SH', '603520.SH', '002397.SZ', '300307.SZ', '300620.SZ', '002314.SZ', '000403.SZ', '600086.SH', '000070.SZ', '002009.SZ', '002302.SZ', '300705.SZ', '600583.SH', '300572.SZ', '000868.SZ', '603701.SH', '002032.SZ', '603056.SH', '600499.SH', '600936.SH', '603612.SH', '000605.SZ', '300103.SZ', '300663.SZ', '000807.SZ', '300581.SZ', '300450.SZ', '603059.SH', '600764.SH', '600395.SH', '601952.SH', '600272.SH', '002761.SZ', '000969.SZ', '002201.SZ', '300091.SZ', '002689.SZ', '300079.SZ', '300161.SZ', '600280.SH', '300321.SZ', '600579.SH', '300423.SZ', '603917.SH', '000533.SZ', '300151.SZ', '002747.SZ', '603037.SH', '002181.SZ', '002461.SZ', '002305.SZ', '002112.SZ', '600338.SH', '600839.SH', '300514.SZ', '600248.SH', '002309.SZ', '603897.SH', '300568.SZ', '603829.SH', '601633.SH', '600714.SH', '300311.SZ', '600724.SH', '300532.SZ', '600284.SH', '601838.SH', '000521.SZ', '300114.SZ', '603589.SH', '002329.SZ', '002024.SZ', '600779.SH', '603718.SH', '300573.SZ', '002663.SZ', '000069.SZ', '002817.SZ', '300698.SZ', '603668.SH', '000937.SZ', '603908.SH', '002156.SZ', '000531.SZ', '601668.SH', '600292.SH', '002725.SZ', '603500.SH', '000528.SZ', '002026.SZ', '002648.SZ', '601038.SH', '000629.SZ', '000777.SZ', '000692.SZ', '000566.SZ', '603111.SH', '002653.SZ', '000548.SZ', '300659.SZ', '600063.SH', '600066.SH', '300482.SZ', '002866.SZ', '300176.SZ', '300403.SZ', '002530.SZ', '600702.SH', '600985.SH', '000861.SZ', '600416.SH', '002268.SZ', '300326.SZ', '002323.SZ', '300638.SZ', '600606.SH', '300603.SZ', '603227.SH', '600293.SH', '600812.SH', '000835.SZ', '002106.SZ', '000421.SZ', '000666.SZ', '002478.SZ', '300381.SZ', '603033.SH', '600998.SH', '600479.SH', '600079.SH', '600875.SH', '002095.SZ', '300295.SZ', '600819.SH', '000892.SZ', '300044.SZ', '600848.SH', '603936.SH', '600635.SH', '600468.SH', '000407.SZ', '002931.SZ', '300258.SZ', '600029.SH', '300336.SZ', '002690.SZ', '600655.SH', '300399.SZ', '300325.SZ', '600555.SH', '000821.SZ', '600677.SH', '600572.SH', '002858.SZ', '600240.SH', '603138.SH', '600608.SH', '600310.SH', '600522.SH', '000587.SZ', '601211.SH', '600335.SH', '000988.SZ', '600196.SH', '600435.SH', '300107.SZ', '600099.SH', '600433.SH', '600641.SH', '603787.SH', '600067.SH', '601579.SH', '600385.SH', '002100.SZ', '002345.SZ', '603222.SH', '000635.SZ', '300319.SZ', '002688.SZ', '600207.SH', '000153.SZ', '002833.SZ', '600235.SH', '603677.SH', '002084.SZ', '000619.SZ', '603968.SH', '603085.SH', '603889.SH', '002170.SZ', '002358.SZ', '601808.SH', '603198.SH', '000655.SZ', '002695.SZ', '300069.SZ', '603810.SH', '600893.SH', '300081.SZ', '600508.SH', '601128.SH', '000819.SZ', '002815.SZ', '600871.SH', '601368.SH', '600665.SH', '002221.SZ', '600418.SH', '600536.SH', '600255.SH', '300123.SZ', '603189.SH', '300078.SZ', '600854.SH', '603690.SH', '601101.SH', '601828.SH', '002013.SZ', '600163.SH', '002344.SZ', '603919.SH', '002444.SZ', '300134.SZ', '300480.SZ', '600461.SH', '300256.SZ', '600082.SH', '002572.SZ', '000001.SZ', '601777.SH', '002242.SZ', '300353.SZ', '000977.SZ', '002341.SZ', '300607.SZ', '000576.SZ', '603659.SH', '002543.SZ', '601326.SH', '600999.SH', '000516.SZ', '002758.SZ', '600020.SH', '300266.SZ', '300616.SZ', '300682.SZ', '002621.SZ', '000410.SZ', '000897.SZ', '300225.SZ', '600793.SH', '002003.SZ', '600817.SH', '000938.SZ', '002371.SZ', '002353.SZ', '300261.SZ', '002064.SZ', '002548.SZ', '300452.SZ', '603517.SH', '002677.SZ', '300642.SZ', '600550.SH', '600009.SH', '000735.SZ', '002336.SZ', '000595.SZ', '300588.SZ', '002054.SZ', '002824.SZ', '300232.SZ', '603389.SH', '000961.SZ', '002440.SZ', '300013.SZ', '603166.SH', '300218.SZ', '300677.SZ', '002317.SZ', '002508.SZ', '002664.SZ', '300226.SZ', '300269.SZ', '002905.SZ', '000783.SZ', '002582.SZ', '300741.SZ', '000509.SZ', '600323.SH', '002731.SZ', '600618.SH', '601996.SH', '603299.SH', '300310.SZ', '603328.SH', '600083.SH', '600823.SH', '300030.SZ', '300197.SZ', '002448.SZ', '300717.SZ', '300188.SZ', '600798.SH', '603456.SH', '002819.SZ', '002545.SZ', '603999.SH', '300121.SZ', '000505.SZ', '300635.SZ', '300145.SZ', '002306.SZ', '300395.SZ', '300590.SZ', '603496.SH', '002483.SZ', '603351.SH', '000932.SZ', '002554.SZ', '002005.SZ', '002307.SZ', '002789.SZ', '300021.SZ', '300424.SZ', '600726.SH', '600507.SH', '600657.SH', '000585.SZ', '300052.SZ', '000554.SZ', '002250.SZ', '300020.SZ', '000801.SZ', '603416.SH', '002883.SZ', '300083.SZ', '600460.SH', '601678.SH', '601228.SH', '300633.SZ', '002316.SZ', '002368.SZ', '300294.SZ', '600653.SH', '002099.SZ', '002586.SZ', '600881.SH', '601858.SH', '600822.SH', '300417.SZ', '600800.SH', '601086.SH', '300208.SZ', '600987.SH', '603880.SH', '000623.SZ', '000007.SZ', '600397.SH', '300407.SZ', '000995.SZ', '300059.SZ', '300173.SZ', '000951.SZ', '603901.SH', '600319.SH', '600525.SH', '603136.SH', '600271.SH', '002578.SZ', '600642.SH', '600801.SH', '603179.SH', '300459.SZ', '300533.SZ', '601799.SH', '000828.SZ', '600090.SH', '600267.SH', '000839.SZ', '300697.SZ', '000933.SZ', '600995.SH', '300418.SZ', '603183.SH', '600420.SH', '300117.SZ', '601208.SH', '000719.SZ', '300560.SZ', '000778.SZ', '300293.SZ', '300461.SZ', '002802.SZ', '300040.SZ', '601555.SH', '002665.SZ', '600410.SH', '002193.SZ', '300074.SZ', '600652.SH', '002409.SZ', '000780.SZ', '002297.SZ', '300089.SZ', '300171.SZ', '002606.SZ', '600278.SH', '600346.SH', '002888.SZ', '600016.SH', '600241.SH', '002566.SZ', '603506.SH', '002539.SZ', '600275.SH', '002705.SZ', '603789.SH', '002619.SZ', '002855.SZ', '300720.SZ', '600637.SH', '300660.SZ', '300436.SZ', '600623.SH', '000488.SZ', '600260.SH', '300398.SZ', '000858.SZ', '002707.SZ', '603976.SH', '002401.SZ', '300462.SZ', '000536.SZ', '001696.SZ', '002928.SZ', '600966.SH', '600439.SH', '300507.SZ', '002464.SZ', '300593.SZ', '000795.SZ', '002022.SZ', '600792.SH', '000939.SZ', '300033.SZ', '000878.SZ', '300489.SZ', '603159.SH', '603838.SH', '600231.SH', '600145.SH', '300262.SZ', '002827.SZ', '601099.SH', '300109.SZ', '002110.SZ', '300440.SZ', '300760.SZ', '002282.SZ', '300062.SZ', '600467.SH', '603866.SH', '600601.SH', '603011.SH', '600213.SH', '600282.SH', '600816.SH', '300622.SZ', '300244.SZ', '600519.SH', '603569.SH', '600184.SH', '600114.SH', '603819.SH', '603869.SH', '002419.SZ', '300213.SZ', '600093.SH', '603386.SH', '002718.SZ', '601020.SH', '002714.SZ', '002835.SZ', '000705.SZ', '002312.SZ', '600838.SH', '002763.SZ', '300137.SZ', '300702.SZ', '300279.SZ', '300589.SZ', '300541.SZ', '600517.SH', '300277.SZ', '002004.SZ', '002659.SZ', '300247.SZ', '300067.SZ', '600733.SH', '603039.SH', '000950.SZ', '002060.SZ', '002849.SZ', '002645.SZ', '002078.SZ', '300684.SZ', '600035.SH', '000561.SZ', '603987.SH', '002056.SZ', '300322.SZ', '000613.SZ', '000860.SZ', '600614.SH', '601598.SH', '000006.SZ', '300189.SZ', '002732.SZ', '000971.SZ', '300058.SZ', '603158.SH', '600363.SH', '603638.SH', '300443.SZ', '603667.SH', '600559.SH', '002420.SZ', '002528.SZ', '002909.SZ', '000710.SZ', '002765.SZ', '002929.SZ', '603626.SH', '600372.SH', '300526.SZ', '002223.SZ', '000166.SZ', '600098.SH', '603700.SH', '600379.SH', '002002.SZ', '300467.SZ', '002311.SZ', '600222.SH', '601857.SH', '603933.SH', '600586.SH', '002334.SZ', '002198.SZ', '300229.SZ', '300283.SZ', '000921.SZ', '600436.SH', '002366.SZ', '600845.SH', '000532.SZ', '600810.SH', '300136.SZ', '300601.SZ', '601929.SH', '002927.SZ', '600959.SH', '603366.SH', '603555.SH', '600201.SH', '603583.SH', '603797.SH', '601226.SH', '300017.SZ', '601901.SH', '002875.SZ', '300404.SZ', '603077.SH', '600682.SH', '002547.SZ', '300665.SZ', '002244.SZ', '600225.SH', '300066.SZ', '300555.SZ', '002191.SZ', '601162.SH', '603556.SH', '002154.SZ', '600735.SH', '601958.SH', '603607.SH', '600754.SH', '002473.SZ', '601118.SH', '002254.SZ', '600890.SH', '002426.SZ', '300379.SZ', '000593.SZ', '002696.SZ', '000901.SZ', '300692.SZ', '002801.SZ', '603396.SH', '002333.SZ', '000712.SZ', '002910.SZ', '000158.SZ', '002722.SZ', '600901.SH', '600667.SH', '603533.SH', '002837.SZ', '002738.SZ', '600072.SH', '600423.SH', '603167.SH', '300509.SZ', '600452.SH', '002210.SZ', '000018.SZ', '600366.SH', '603336.SH', '000581.SZ', '002212.SZ', '300276.SZ', '000818.SZ', '300722.SZ', '002088.SZ', '300112.SZ', '601699.SH', '600885.SH', '600546.SH', '300126.SZ', '600685.SH', '601606.SH', '601615.SH', '600356.SH', '601158.SH', '002945.SZ', '002753.SZ', '600766.SH', '600829.SH', '600148.SH', '300495.SZ', '601798.SH', '000607.SZ', '300504.SZ', '601766.SH', '603363.SH', '600686.SH', '002911.SZ', '300222.SZ', '600179.SH', '600723.SH', '002708.SZ', '300548.SZ', '300618.SZ', '603939.SH', '300164.SZ', '300344.SZ', '601811.SH', '300481.SZ', '300389.SZ', '600337.SH', '002076.SZ', '000790.SZ', '300455.SZ', '002011.SZ', '002602.SZ', '000998.SZ', '600076.SH', '000852.SZ', '603629.SH', '000962.SZ', '002590.SZ', '600183.SH', '601007.SH', '002327.SZ', '002864.SZ', '002068.SZ', '603018.SH', '300375.SZ', '601021.SH', '600567.SH', '600860.SH', '603666.SH', '601928.SH', '002559.SZ', '002678.SZ', '603816.SH', ...]
data = get_price(stocklist,None,date,'1d',['open','high','low','close'],bar_count = 60,is_panel =1)
data
<class 'pandas.core.panel.Panel'> Dimensions: 4 (items) x 60 (major_axis) x 3585 (minor_axis) Items axis: close to open Major_axis axis: 2018-11-09 00:00:00 to 2019-02-11 00:00:00 Minor_axis axis: 000001.SZ to 603999.SH
closedf = data['close'].fillna(0)
opendf = data['open'].fillna(0)
highdf = data['high'].fillna(0)
lowdf = data['low'].fillna(0)
lowdf
lowdf
Out[39]:
000001.SZ | 000002.SZ | 000004.SZ | 000005.SZ | 000006.SZ | 000007.SZ | 000008.SZ | 000009.SZ | 000010.SZ | 000011.SZ | ... | 603987.SH | 603988.SH | 603989.SH | 603990.SH | 603991.SH | 603993.SH | 603996.SH | 603997.SH | 603998.SH | 603999.SH | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2018-11-09 | 10.40 | 23.53 | 16.00 | 2.86 | 5.03 | 6.71 | 4.43 | 4.27 | 4.26 | 8.92 | ... | 6.04 | 9.92 | 22.10 | 30.01 | 17.70 | 4.10 | 8.40 | 7.95 | 5.18 | 4.75 |
2018-11-12 | 10.38 | 23.40 | 16.15 | 2.79 | 4.97 | 7.06 | 3.99 | 4.26 | 4.20 | 8.82 | ... | 6.01 | 10.99 | 22.30 | 30.15 | 17.90 | 4.04 | 8.44 | 7.91 | 5.20 | 4.74 |
2018-11-13 | 10.38 | 23.44 | 16.50 | 2.93 | 5.05 | 8.03 | 4.12 | 4.37 | 4.23 | 9.08 | ... | 6.09 | 10.86 | 22.33 | 30.50 | 18.18 | 4.06 | 8.40 | 7.93 | 5.33 | 4.82 |
2018-11-14 | 10.42 | 23.96 | 17.00 | 3.04 | 5.24 | 7.92 | 4.19 | 4.50 | 4.33 | 9.29 | ... | 6.25 | 10.64 | 22.51 | 32.03 | 19.14 | 4.13 | 8.72 | 8.16 | 5.58 | 5.08 |
2018-11-15 | 10.42 | 23.96 | 16.80 | 3.01 | 5.24 | 7.70 | 4.15 | 4.59 | 4.34 | 9.39 | ... | 6.28 | 10.60 | 22.51 | 31.99 | 19.51 | 4.10 | 8.87 | 8.18 | 5.53 | 5.11 |
2018-11-16 | 10.49 | 24.02 | 16.93 | 3.04 | 5.45 | 7.75 | 4.15 | 4.87 | 4.40 | 9.58 | ... | 6.43 | 10.62 | 22.80 | 32.70 | 20.30 | 4.15 | 8.96 | 8.26 | 5.64 | 5.21 |
2018-11-19 | 10.57 | 24.68 | 17.30 | 3.11 | 5.51 | 8.15 | 4.13 | 5.33 | 4.42 | 10.04 | ... | 6.45 | 10.82 | 22.55 | 32.26 | 20.07 | 4.11 | 8.85 | 8.26 | 5.68 | 5.25 |
2018-11-20 | 10.52 | 25.23 | 16.80 | 3.03 | 5.47 | 7.88 | 4.00 | 5.02 | 4.30 | 10.16 | ... | 6.27 | 10.70 | 22.08 | 31.85 | 19.34 | 4.10 | 8.74 | 8.00 | 5.52 | 5.11 |
2018-11-21 | 10.48 | 25.35 | 16.65 | 2.97 | 5.39 | 8.23 | 3.96 | 5.04 | 4.25 | 9.98 | ... | 6.19 | 10.60 | 21.00 | 31.50 | 19.35 | 3.97 | 8.53 | 7.88 | 5.42 | 4.98 |
2018-11-22 | 10.48 | 25.28 | 17.04 | 3.03 | 5.45 | 9.05 | 4.12 | 5.00 | 4.32 | 10.25 | ... | 6.43 | 10.75 | 21.18 | 31.66 | 19.45 | 4.05 | 8.72 | 8.19 | 5.57 | 5.11 |
2018-11-23 | 10.31 | 24.68 | 16.49 | 2.88 | 5.25 | 9.37 | 4.01 | 4.74 | 4.31 | 9.66 | ... | 6.06 | 10.35 | 21.01 | 31.21 | 18.51 | 3.85 | 7.96 | 8.36 | 5.21 | 5.04 |
2018-11-26 | 10.30 | 24.74 | 16.35 | 2.87 | 5.25 | 8.64 | 3.95 | 4.75 | 4.34 | 9.65 | ... | 6.07 | 10.11 | 20.68 | 31.50 | 18.35 | 3.79 | 7.95 | 8.20 | 5.15 | 5.12 |
2018-11-27 | 10.16 | 24.78 | 16.46 | 2.89 | 5.26 | 8.14 | 3.95 | 4.84 | 4.47 | 9.70 | ... | 6.14 | 10.01 | 20.70 | 31.76 | 18.53 | 3.80 | 8.02 | 8.21 | 5.13 | 5.17 |
2018-11-28 | 10.16 | 24.99 | 16.67 | 2.89 | 5.17 | 7.93 | 3.89 | 4.74 | 4.42 | 9.49 | ... | 6.03 | 10.12 | 20.50 | 31.88 | 18.13 | 3.77 | 7.88 | 8.25 | 5.08 | 5.02 |
2018-11-29 | 10.19 | 25.00 | 16.32 | 2.99 | 5.32 | 7.29 | 3.75 | 4.69 | 4.45 | 9.54 | ... | 6.40 | 9.80 | 19.70 | 31.70 | 17.73 | 3.86 | 7.96 | 8.00 | 5.11 | 5.10 |
2018-11-30 | 10.17 | 25.03 | 15.96 | 2.90 | 5.22 | 6.87 | 3.66 | 4.58 | 4.02 | 9.40 | ... | 6.60 | 8.87 | 19.80 | 31.70 | 17.80 | 3.82 | 7.86 | 7.96 | 5.06 | 4.80 |
2018-12-03 | 10.47 | 24.81 | 16.39 | 3.03 | 5.44 | 7.26 | 3.85 | 4.85 | 4.06 | 9.85 | ... | 6.70 | 10.80 | 20.72 | 32.66 | 18.68 | 4.05 | 8.25 | 8.16 | 5.25 | 5.05 |
2018-12-04 | 10.53 | 24.86 | 16.52 | 3.03 | 5.49 | 7.39 | 3.96 | 4.89 | 4.06 | 9.93 | ... | 6.77 | 10.71 | 21.05 | 32.76 | 18.91 | 4.03 | 8.34 | 8.11 | 5.27 | 5.05 |
2018-12-05 | 10.40 | 24.76 | 16.55 | 2.98 | 5.47 | 7.84 | 3.91 | 4.80 | 4.01 | 9.92 | ... | 6.61 | 10.70 | 21.38 | 31.35 | 18.80 | 3.97 | 8.19 | 8.15 | 5.47 | 5.35 |
2018-12-06 | 10.23 | 24.90 | 16.64 | 2.95 | 5.55 | 7.76 | 3.91 | 4.75 | 4.02 | 10.15 | ... | 6.66 | 10.38 | 21.46 | 32.42 | 18.50 | 4.05 | 8.18 | 8.10 | 5.30 | 5.80 |
2018-12-07 | 10.27 | 25.12 | 16.30 | 3.00 | 5.62 | 7.91 | 3.90 | 4.76 | 3.86 | 10.47 | ... | 6.55 | 10.20 | 21.25 | 32.60 | 18.63 | 4.03 | 8.21 | 8.00 | 5.20 | 5.46 |
2018-12-10 | 10.13 | 24.90 | 15.80 | 2.91 | 5.53 | 7.20 | 3.80 | 4.65 | 3.82 | 10.20 | ... | 6.35 | 10.19 | 21.10 | 32.08 | 18.03 | 3.97 | 8.16 | 7.66 | 5.05 | 5.12 |
2018-12-11 | 10.17 | 24.91 | 16.07 | 2.93 | 5.62 | 7.38 | 3.83 | 4.66 | 3.70 | 10.36 | ... | 6.43 | 10.23 | 21.20 | 32.12 | 18.20 | 3.97 | 8.22 | 7.65 | 5.07 | 5.19 |
2018-12-12 | 10.20 | 26.14 | 16.52 | 2.99 | 5.76 | 8.25 | 3.85 | 4.71 | 3.61 | 10.76 | ... | 6.40 | 10.28 | 21.26 | 31.74 | 18.31 | 4.03 | 8.24 | 7.79 | 5.10 | 5.25 |
2018-12-13 | 10.20 | 26.40 | 16.41 | 2.99 | 5.72 | 8.34 | 3.86 | 4.73 | 3.52 | 10.88 | ... | 6.71 | 10.42 | 21.28 | 31.53 | 18.35 | 4.07 | 8.16 | 8.15 | 5.09 | 5.21 |
2018-12-14 | 10.16 | 26.31 | 16.46 | 2.92 | 5.66 | 8.10 | 3.96 | 4.58 | 3.38 | 10.61 | ... | 6.46 | 9.96 | 20.88 | 31.20 | 18.03 | 4.07 | 8.01 | 8.10 | 5.03 | 5.10 |
2018-12-17 | 10.10 | 25.94 | 17.25 | 2.91 | 5.72 | 8.05 | 3.90 | 4.52 | 3.38 | 10.58 | ... | 6.31 | 9.90 | 20.30 | 31.51 | 17.75 | 4.04 | 7.94 | 7.92 | 4.88 | 5.03 |
2018-12-18 | 10.10 | 25.34 | 16.83 | 2.87 | 5.38 | 8.22 | 3.82 | 4.56 | 3.45 | 9.92 | ... | 6.33 | 9.83 | 20.21 | 32.19 | 17.66 | 4.09 | 7.68 | 7.82 | 4.89 | 5.08 |
2018-12-19 | 9.90 | 25.15 | 16.32 | 2.86 | 5.42 | 8.79 | 3.81 | 4.55 | 3.47 | 9.97 | ... | 6.33 | 9.98 | 20.21 | 32.10 | 17.61 | 4.08 | 7.71 | 7.80 | 4.88 | 5.08 |
2018-12-20 | 9.63 | 24.91 | 16.30 | 2.84 | 5.40 | 8.61 | 3.79 | 4.53 | 3.45 | 9.81 | ... | 6.36 | 9.95 | 20.19 | 31.90 | 17.51 | 4.01 | 7.75 | 7.71 | 4.84 | 5.06 |
2018-12-21 | 9.33 | 23.70 | 16.17 | 2.83 | 5.33 | 8.23 | 3.80 | 4.48 | 3.46 | 9.67 | ... | 6.54 | 9.89 | 20.32 | 31.28 | 17.55 | 3.91 | 7.62 | 7.70 | 4.86 | 5.11 |
2018-12-24 | 9.31 | 23.33 | 16.08 | 2.82 | 5.27 | 8.18 | 3.80 | 4.50 | 3.45 | 9.60 | ... | 6.61 | 9.80 | 20.20 | 31.80 | 17.61 | 3.92 | 7.65 | 7.72 | 4.91 | 5.09 |
2018-12-25 | 9.21 | 23.38 | 15.92 | 2.72 | 5.03 | 8.01 | 3.85 | 4.23 | 3.32 | 9.27 | ... | 6.35 | 9.80 | 20.07 | 31.60 | 17.45 | 3.76 | 7.33 | 7.38 | 4.79 | 4.80 |
2018-12-26 | 9.27 | 23.58 | 16.16 | 2.73 | 5.15 | 8.46 | 3.96 | 4.37 | 3.40 | 9.41 | ... | 6.43 | 10.06 | 20.45 | 32.26 | 18.36 | 3.84 | 7.56 | 7.46 | 4.85 | 4.90 |
2018-12-27 | 9.28 | 23.44 | 16.03 | 2.66 | 5.16 | 8.10 | 3.84 | 4.30 | 3.26 | 9.13 | ... | 6.42 | 9.95 | 20.10 | 32.79 | 18.37 | 3.75 | 7.43 | 7.50 | 4.65 | 4.81 |
2018-12-28 | 9.31 | 23.67 | 15.73 | 2.65 | 5.15 | 7.90 | 3.85 | 4.30 | 3.20 | 9.12 | ... | 6.34 | 9.98 | 20.00 | 32.60 | 18.18 | 3.74 | 7.36 | 7.40 | 4.67 | 4.81 |
2019-01-02 | 9.16 | 23.67 | 16.01 | 2.66 | 5.10 | 7.99 | 3.81 | 4.26 | 3.25 | 9.20 | ... | 6.42 | 9.82 | 19.25 | 32.15 | 18.06 | 3.65 | 7.48 | 7.65 | 4.52 | 4.75 |
2019-01-03 | 9.15 | 23.71 | 16.00 | 2.65 | 5.11 | 7.58 | 3.83 | 4.23 | 3.26 | 9.29 | ... | 6.40 | 9.66 | 18.75 | 31.80 | 17.82 | 3.67 | 7.47 | 7.70 | 4.53 | 4.72 |
2019-01-04 | 9.22 | 23.85 | 16.01 | 2.66 | 5.06 | 7.50 | 3.80 | 4.18 | 3.22 | 9.14 | ... | 6.36 | 9.62 | 18.59 | 31.79 | 17.42 | 3.67 | 7.36 | 7.72 | 4.50 | 4.66 |
2019-01-07 | 9.63 | 24.99 | 16.46 | 2.76 | 5.28 | 7.93 | 3.92 | 4.41 | 3.32 | 9.68 | ... | 6.58 | 9.95 | 19.39 | 31.80 | 18.36 | 3.83 | 7.73 | 7.75 | 4.74 | 4.92 |
2019-01-08 | 9.62 | 24.63 | 16.80 | 2.82 | 5.31 | 7.82 | 4.03 | 4.44 | 3.35 | 9.63 | ... | 6.55 | 10.03 | 19.20 | 31.81 | 18.56 | 3.85 | 7.74 | 7.78 | 4.86 | 5.01 |
2019-01-09 | 9.70 | 25.11 | 16.72 | 2.84 | 5.34 | 7.80 | 4.06 | 4.46 | 3.36 | 9.72 | ... | 6.80 | 10.18 | 19.53 | 31.87 | 18.85 | 3.83 | 8.01 | 7.85 | 4.92 | 5.00 |
2019-01-10 | 9.86 | 25.03 | 16.66 | 2.84 | 5.29 | 7.77 | 4.00 | 4.41 | 3.36 | 9.52 | ... | 6.72 | 10.22 | 19.16 | 31.81 | 18.85 | 3.80 | 7.89 | 7.90 | 4.98 | 4.96 |
2019-01-11 | 10.05 | 25.01 | 16.49 | 2.91 | 5.30 | 7.63 | 3.98 | 4.40 | 3.34 | 9.55 | ... | 6.68 | 10.19 | 19.23 | 31.55 | 18.79 | 3.80 | 7.91 | 7.70 | 5.00 | 4.95 |
2019-01-14 | 10.07 | 24.92 | 16.49 | 2.97 | 5.28 | 6.97 | 4.00 | 4.44 | 3.52 | 9.52 | ... | 6.35 | 9.94 | 18.76 | 31.50 | 19.06 | 3.80 | 7.87 | 7.64 | 5.00 | 4.93 |
2019-01-15 | 10.09 | 24.32 | 16.40 | 3.04 | 5.23 | 7.05 | 3.98 | 4.44 | 3.47 | 9.53 | ... | 6.35 | 10.01 | 18.90 | 31.52 | 18.88 | 3.80 | 7.91 | 7.77 | 5.00 | 4.94 |
2019-01-16 | 10.23 | 24.83 | 16.55 | 2.96 | 5.31 | 7.07 | 4.00 | 4.43 | 3.51 | 9.64 | ... | 6.40 | 10.24 | 19.38 | 31.56 | 19.14 | 3.81 | 8.08 | 7.77 | 5.03 | 4.97 |
2019-01-17 | 10.17 | 24.94 | 16.40 | 2.95 | 5.25 | 6.77 | 3.95 | 4.37 | 3.42 | 9.66 | ... | 6.28 | 9.88 | 18.80 | 31.50 | 18.69 | 3.78 | 7.99 | 7.62 | 4.96 | 4.95 |
2019-01-18 | 10.28 | 24.99 | 16.44 | 2.95 | 5.24 | 6.56 | 3.80 | 4.33 | 3.27 | 9.51 | ... | 6.34 | 9.75 | 18.86 | 31.50 | 18.58 | 3.81 | 7.95 | 7.61 | 4.98 | 4.86 |
2019-01-21 | 10.32 | 25.40 | 16.42 | 2.96 | 5.33 | 6.72 | 3.89 | 4.40 | 3.31 | 9.62 | ... | 6.42 | 9.81 | 18.91 | 31.05 | 18.28 | 3.91 | 7.99 | 7.66 | 5.02 | 5.07 |
2019-01-22 | 10.26 | 25.23 | 16.28 | 2.92 | 5.25 | 6.70 | 3.89 | 4.25 | 3.34 | 9.53 | ... | 6.42 | 9.68 | 18.82 | 31.36 | 18.89 | 3.85 | 7.87 | 7.65 | 4.97 | 5.03 |
2019-01-23 | 10.29 | 25.20 | 16.20 | 2.97 | 5.23 | 6.62 | 3.86 | 4.26 | 3.31 | 9.53 | ... | 6.37 | 9.66 | 18.71 | 31.53 | 18.75 | 3.83 | 7.86 | 7.61 | 4.93 | 4.97 |
2019-01-24 | 10.37 | 24.93 | 16.22 | 2.90 | 5.20 | 6.45 | 3.84 | 4.28 | 3.28 | 9.43 | ... | 6.39 | 9.68 | 17.95 | 31.85 | 18.59 | 3.83 | 8.07 | 7.62 | 4.94 | 4.97 |
2019-01-25 | 10.55 | 25.49 | 16.27 | 2.91 | 5.25 | 6.20 | 3.85 | 4.28 | 3.25 | 9.48 | ... | 6.36 | 9.59 | 17.73 | 32.03 | 18.43 | 3.83 | 8.02 | 7.63 | 4.93 | 4.93 |
2019-01-28 | 10.88 | 25.86 | 16.01 | 2.90 | 5.20 | 5.61 | 3.85 | 4.22 | 3.24 | 9.25 | ... | 6.12 | 9.32 | 17.75 | 32.22 | 18.23 | 3.83 | 7.93 | 7.54 | 4.86 | 4.93 |
2019-01-29 | 10.77 | 25.87 | 15.00 | 2.78 | 5.10 | 5.05 | 3.80 | 4.08 | 3.02 | 8.93 | ... | 5.92 | 9.07 | 17.63 | 32.27 | 17.53 | 3.62 | 7.23 | 7.41 | 4.71 | 5.10 |
2019-01-30 | 10.86 | 26.63 | 15.03 | 2.80 | 5.12 | 4.61 | 3.82 | 4.12 | 2.82 | 8.99 | ... | 6.05 | 9.22 | 17.51 | 32.39 | 17.27 | 3.73 | 7.28 | 7.33 | 4.65 | 4.92 |
2019-01-31 | 10.94 | 27.00 | 14.05 | 2.82 | 5.11 | 4.75 | 3.50 | 4.02 | 2.85 | 8.94 | ... | 5.85 | 8.41 | 17.50 | 32.60 | 16.57 | 3.78 | 7.25 | 7.01 | 4.61 | 4.72 |
2019-02-01 | 10.96 | 26.98 | 14.70 | 2.85 | 5.17 | 4.88 | 3.65 | 4.08 | 2.91 | 9.07 | ... | 5.96 | 8.75 | 17.56 | 33.13 | 16.80 | 3.83 | 7.46 | 7.12 | 4.66 | 4.73 |
2019-02-11 | 10.97 | 26.89 | 14.85 | 2.97 | 5.25 | 5.12 | 3.61 | 4.26 | 3.04 | 9.29 | ... | 6.19 | 9.04 | 18.12 | 34.91 | 17.45 | 3.89 | 7.92 | 7.45 | 4.77 | 4.86 |
dt = pd.DataFrame(columns=['stock','startdate','enddate','T'])
data = get_price('603383.SH',None,'20190114','1d',['open','high','low','close'],bar_count=60,is_panel =1)
close1 = data['close']
open1 = data['open']
high1 = data['high']
low1 = data['low']
stocklist = list(closedf.columns)
y=0
for s in stocklist:
corropen = round(np.corrcoef(open1,opendf[s])[0][1],3)
corrhigh = round(np.corrcoef(high1,highdf[s])[0][1],3)
corrlow = round(np.corrcoef(low1,lowdf[s])[0][1],3)
corrclose = round(np.corrcoef(close1,closedf[s])[0][1],3)
#综合值
T = (corropen+corrhigh+corrlow+corrclose)/4
startdate = '20181109'
enddate = '20190211'
dt.loc[y] = [s,startdate,enddate,T]
y+=1
dt = dt.fillna(0)
dt = dt.sort_values(by='T',ascending=False)
dt
dt
Out[40]:
stock | startdate | enddate | T | |
---|---|---|---|---|
2810 | 600807.SH | 20181109 | 20190211 | 0.89650 |
1385 | 002943.SZ | 20181109 | 20190211 | 0.89125 |
2125 | 300752.SZ | 20181109 | 20190211 | 0.87300 |
510 | 002047.SZ | 20181109 | 20190211 | 0.84575 |
3237 | 603187.SH | 20181109 | 20190211 | 0.84575 |
1384 | 002942.SZ | 20181109 | 20190211 | 0.83925 |
3450 | 603711.SH | 20181109 | 20190211 | 0.83775 |
74 | 000401.SZ | 20181109 | 20190211 | 0.83650 |
2382 | 600298.SH | 20181109 | 20190211 | 0.83650 |
1564 | 300176.SZ | 20181109 | 20190211 | 0.81875 |
3357 | 603520.SH | 20181109 | 20190211 | 0.81850 |
2575 | 600547.SH | 20181109 | 20190211 | 0.81725 |
1403 | 300014.SZ | 20181109 | 20190211 | 0.81275 |
3445 | 603703.SH | 20181109 | 20190211 | 0.80975 |
2526 | 600489.SH | 20181109 | 20190211 | 0.80850 |
3152 | 603026.SH | 20181109 | 20190211 | 0.80850 |
1165 | 002705.SZ | 20181109 | 20190211 | 0.79425 |
3568 | 603976.SH | 20181109 | 20190211 | 0.79150 |
1461 | 300073.SZ | 20181109 | 20190211 | 0.78925 |
1568 | 300180.SZ | 20181109 | 20190211 | 0.78800 |
2713 | 600702.SH | 20181109 | 20190211 | 0.78725 |
1649 | 300262.SZ | 20181109 | 20190211 | 0.78250 |
2492 | 600436.SH | 20181109 | 20190211 | 0.77825 |
3242 | 603197.SH | 20181109 | 20190211 | 0.77450 |
134 | 000543.SZ | 20181109 | 20190211 | 0.76650 |
2080 | 300702.SZ | 20181109 | 20190211 | 0.75825 |
2561 | 600529.SH | 20181109 | 20190211 | 0.75750 |
552 | 002089.SZ | 20181109 | 20190211 | 0.75500 |
3392 | 603605.SH | 20181109 | 20190211 | 0.75350 |
3367 | 603558.SH | 20181109 | 20190211 | 0.75275 |
... | ... | ... | ... | ... |
2240 | 600131.SH | 20181109 | 20190211 | -0.78025 |
2699 | 600687.SH | 20181109 | 20190211 | -0.78100 |
201 | 000629.SZ | 20181109 | 20190211 | -0.78225 |
3158 | 603032.SH | 20181109 | 20190211 | -0.78300 |
1624 | 300237.SZ | 20181109 | 20190211 | -0.78350 |
444 | 000981.SZ | 20181109 | 20190211 | -0.78600 |
3492 | 603811.SH | 20181109 | 20190211 | -0.78775 |
2701 | 600689.SH | 20181109 | 20190211 | -0.79025 |
2330 | 600235.SH | 20181109 | 20190211 | -0.79200 |
2294 | 600195.SH | 20181109 | 20190211 | -0.79450 |
3105 | 601918.SH | 20181109 | 20190211 | -0.79450 |
2695 | 600683.SH | 20181109 | 20190211 | -0.79550 |
3267 | 603269.SH | 20181109 | 20190211 | -0.80200 |
2237 | 600128.SH | 20181109 | 20190211 | -0.80400 |
2646 | 600624.SH | 20181109 | 20190211 | -0.80500 |
1108 | 002647.SZ | 20181109 | 20190211 | -0.80700 |
656 | 002193.SZ | 20181109 | 20190211 | -0.80850 |
3042 | 601577.SH | 20181109 | 20190211 | -0.80975 |
517 | 002054.SZ | 20181109 | 20190211 | -0.81150 |
2801 | 600796.SH | 20181109 | 20190211 | -0.81350 |
103 | 000504.SZ | 20181109 | 20190211 | -0.81375 |
610 | 002147.SZ | 20181109 | 20190211 | -0.81500 |
2370 | 600283.SH | 20181109 | 20190211 | -0.82150 |
1382 | 002940.SZ | 20181109 | 20190211 | -0.82250 |
1381 | 002939.SZ | 20181109 | 20190211 | -0.82825 |
1492 | 300104.SZ | 20181109 | 20190211 | -0.83000 |
2399 | 600317.SH | 20181109 | 20190211 | -0.83900 |
1711 | 300324.SZ | 20181109 | 20190211 | -0.84800 |
1046 | 002585.SZ | 20181109 | 20190211 | -0.85300 |
2926 | 600981.SH | 20181109 | 20190211 | -0.87450 |
3585 rows × 4 columns
查看相似最高的股票和最低的股票
for s in [0,-1]:
stock = dt.iloc[s].stock
startdate = dt.iloc[s].startdate
enddate = dt.iloc[s].enddate
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stock
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index(enddate)
close1 = closedf[s]
open1 = opendf[s]
high1 = highdf[s]
low1 = lowdf[s]
#画图
fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')
fig.subplots_adjust()
ticks = ax.set_xticks([0,60])
labels = ax.set_xticklabels([startdate,enddate], fontsize=10)
plt.yticks()
plt.title("{} K线走势图".format(s),fontsize = 15)
plt.ylabel("股价",fontsize = 15)
candlestick2_ohlc(ax,open1,high1,low1,close1,width=0.6,colorup='red',colordown='green')
查看以上策略详细请 到 supermind量化交易官网查看:技术面分析专题(一)-- 相似k线的形态验证与选股