同花顺Supermind量化交易 技术面分析专题(一)--相似k线在预测股价中的运用

本文主要是介绍同花顺Supermind量化交易 技术面分析专题(一)--相似k线在预测股价中的运用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

如何应用“相似K线”来预测未来股价走势?:

我们已经清楚了“相似K线”,接下来让我们尝试将其用于预测未来股价。
第一步:选择浦发银行股票,锁定60个交易日的K线图,2018-10-08至2018-12-28。如下图:
 


第二步:以上证50指数成份股为样本池,对历史4年的所有股票的K线图进行相似度计算,其中K线图长度为60个交易日,时间周期为日级,计算间隔为20个交易日。最终找出2850张K线图。
 


第三步:找出历史中相似度最高的K线图,并观察其后续股价走势情况。我们找到了中国铁建,其在2015-03-31至2015-06-26的K线图与浦发银行在2018-10-08至2018-12-28的K线图相似度高达0.8685。
 


我们观察下图,发现中国铁建出现该段K线后,其后续走势出现反转上涨
 


第四步:根据中国铁建的前车之鉴,我们大胆判断出浦发银行在出现该走势后,也会反转上涨,我们画出K线图,进行验证。观察下图,可以发现,浦发银行也出现了反转上涨。
 


第五步:以上四步,即为“相似K线”预测股价的整个流程,我们将其应用于当下行情,选取浦发银行最近60个交易日的K线图
 


并在上证50指数成份股的历史行情中,找出与其相似度最高的K线图,股票保利地产在2014-01-03至2014-04-04发生与其相似度高达0.8785 观察历史发生该段K线图后的后续走势,我们发生股价出现下跌,根据“历史会重演”的技术理念,判断未来浦发银行的走势大概率出现下跌。
 


 

在“相似K线”的独特视角下,A股市场的价格走势呈现怎样的态势?:

第一步:我们获取上证指数的近60个交易日的K线走势图,如下:
 


第二步:我们计算上证指数的K线图与A股所有个股的近期K线图的相似度。
 


第三步:数据分析,并作出初步结论:
1.A股市场中,接近75%的股票与大盘(上证指数)走势较为相近,与大盘走势无关或者相反的个股股票数量较少占比不到25%
2.近期与大盘走势最为接近的是兴蓉环境,相似度高达0.94
3.近期与大盘走势最为相反的是泰永长征,相似度高达-0.731,其可能与次新炒作相关,脱离大盘走势。


 


 


 

用相似K线进行股价预测,波段操作

浦发银行(600000.SH) 2018-10-08至2018-12-28

In [6]:

stock = ['600000.SH']
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index('20181228')
close = closedf[stock].iloc[num-59:num+1]
opens = opendf[stock].iloc[num-59:num+1]
high = highdf[stock].iloc[num-59:num+1]
low = lowdf[stock].iloc[num-59:num+1]
low

Out[6]:

600000.SH
2018-10-0810.15
2018-10-0910.07
2018-10-1010.13
2018-10-119.71
2018-10-129.83
2018-10-159.97
2018-10-169.97
2018-10-1710.14
2018-10-1810.16
2018-10-1910.07
2018-10-2210.32
2018-10-2310.45
2018-10-2410.52
2018-10-2510.54
2018-10-2610.74
2018-10-2910.71
2018-10-3010.89
2018-10-3110.87
2018-11-0110.86
2018-11-0210.94
2018-11-0511.08
2018-11-0611.00
2018-11-0710.87
2018-11-0810.90
2018-11-0910.70
2018-11-1210.75
2018-11-1310.68
2018-11-1410.68
2018-11-1510.65
2018-11-1610.71
2018-11-1910.77
2018-11-2010.65
2018-11-2110.61
2018-11-2210.57
2018-11-2310.50
2018-11-2610.43
2018-11-2710.45
2018-11-2810.50
2018-11-2910.54
2018-11-3010.62
2018-12-0310.84
2018-12-0410.97
2018-12-0510.96
2018-12-0610.82
2018-12-0710.88
2018-12-1010.77
2018-12-1110.69
2018-12-1210.70
2018-12-1310.73
2018-12-1410.59
2018-12-1710.62
2018-12-1810.54
2018-12-1910.54
2018-12-2010.11
2018-12-2110.00
2018-12-249.86
2018-12-259.60
2018-12-269.64
2018-12-279.66
2018-12-289.71

In [7]:

import numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
for s in stock:open1=list(opens[s])high1=list(high[s])low1=list(low[s])close1=list(close[s])#画图fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')fig.subplots_adjust() ticks = ax.set_xticks([0,60])labels = ax.set_xticklabels([list(opens.index.strftime('%Y%m%d'))[0],list(opens.index.strftime('%Y%m%d'))[-1]], 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')

寻找出上证50指数成份股内,与该段行情最接近的行情

In [8]:

dt = pd.DataFrame(columns=['stock','startdate','enddate','T'])
stock = '600000.SH'
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index('20181228')
close = list(closedf[stock].iloc[num-59:num+1])
opens = list(opendf[stock].iloc[num-59:num+1])
high = list(highdf[stock].iloc[num-59:num+1])
low = list(lowdf[stock].iloc[num-59:num+1])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(opens,opens2[s])[0][1],3)corrhigh = round(np.corrcoef(high,high2[s])[0][1],3)corrlow = round(np.corrcoef(low,low2[s])[0][1],3)corrclose = round(np.corrcoef(close,close2[s])[0][1],3)#综合值T = (corropen+corrhigh+corrlow+corrclose)/4startdate = 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 1219
80 1219
100 1219
120 1219
140 1219
160 1219
180 1219
200 1219
220 1219
240 1219
260 1219
280 1219
300 1219
320 1219
340 1219
360 1219
380 1219
400 1219
420 1219
440 1219
460 1219
480 1219
500 1219
520 1219
540 1219
560 1219
580 1219
600 1219
620 1219
640 1219
660 1219
680 1219
700 1219
720 1219
740 1219
760 1219
780 1219
800 1219
820 1219
840 1219
860 1219
880 1219
900 1219
920 1219
940 1219
960 1219
980 1219
1000 1219
1020 1219
1040 1219
1060 1219
1080 1219
1100 1219
1120 1219
1140 1219
1160 1219
1180 1219

Out[8]:

stockstartdateenddateT
776601186.SH20150331201506260.86850
790601766.SH20150331201506260.82450
1520600887.SH20160621201609130.81300
2200600000.SH20170811201711100.79325
2246601988.SH20170811201711100.78500
1504600029.SH20160621201609130.78300
1145601939.SH20151027201601200.77400
1683601360.SH20160913201612150.76775
2668600690.SH20180511201808060.76775
784601390.SH20150331201506260.76100
2239601688.SH20170811201711100.74875
1105600030.SH20151027201601200.74600
2670600887.SH20180511201808060.74400
2616600585.SH20180411201807090.74325
1346601988.SH20160224201605200.74275
1557600048.SH20160719201610200.73550
1883601360.SH20170113201704180.73075
2227601211.SH20170811201711100.72825
2622601088.SH20180411201807090.72750
2636601601.SH20180411201807090.72750
751600016.SH20150331201506260.72675
1142601818.SH20151027201601200.72600
1342601818.SH20160224201605200.72150
1146601988.SH20151027201601200.71950
1338601668.SH20160224201605200.71900
2054600029.SH20170517201708110.71750
1117600606.SH20151027201601200.71700
1331601328.SH20160224201605200.71600
2337601628.SH20171013201801080.70975
788601668.SH20150331201506260.70750
...............
1632601336.SH2016081620161117-0.74300
1799603993.SH2016111720170217-0.74375
1437601628.SH2016042120160719-0.74750
1401600016.SH2016042120160719-0.74775
192601818.SH2014040420140703-0.75200
626601186.SH2014122620150331-0.75275
1443601857.SH2016042120160719-0.75475
1427601211.SH2016042120160719-0.75875
2329601288.SH2017101320180108-0.75925
634601390.SH2014122620150331-0.76600
638601668.SH2014122620150331-0.76800
1937601628.SH2017021720170517-0.76800
1201600016.SH2015122220160323-0.76850
1438601668.SH2016042120160719-0.76925
1932601336.SH2017021720170517-0.77175
605600030.SH2014122620150331-0.77400
639601688.SH2014122620150331-0.78350
152600019.SH2014040420140703-0.78500
215600547.SH2014050720140731-0.78625
239601688.SH2014050720140731-0.78850
2159600104.SH2017071420171013-0.79475
1403600028.SH2016042120160719-0.79875
602600019.SH2014122620150331-0.80200
1416600585.SH2016042120160719-0.80500
220600887.SH2014050720140731-0.80775
620600887.SH2014122620150331-0.80825
2730601318.SH2018060820180903-0.81375
2568600690.SH2018031220180608-0.81875
1422601088.SH2016042120160719-0.82450
1408600050.SH2016042120160719-0.83000

2850 rows × 4 columns

In [9]:

Tdt = dt.iloc[0]
stock = Tdt.stock
startdate = Tdt.startdate     
enddate = Tdt.enddate   import numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index(enddate)
close1 = closedf[s].iloc[num-59:num+1]
open1 = opendf[s].iloc[num-59:num+1]
high1 = highdf[s].iloc[num-59:num+1]
low1 = lowdf[s].iloc[num-59:num+1]#画图
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')

Out[9]:

(<matplotlib.collections.LineCollection at 0x7f8b256197b8>,<matplotlib.collections.PolyCollection at 0x7f8b255f82e8>)

6.分析分析相似行情是否具备延续性

In [10]:

Tdt = dt.iloc[0]
Tdt.T

Out[10]:

stock        601186.SH
startdate     20150331
enddate       20150626
T               0.8685
Name: 776, dtype: object

相似度最高

In [11]:

stock = Tdt.stock
startdate =Tdt.startdate
enddate = Tdt.enddateimport numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = 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')

Out[11]:

(<matplotlib.collections.LineCollection at 0x7f8b25036a58>,<matplotlib.collections.PolyCollection at 0x7f8b250364a8>)

In [12]:

stock = '600000.SH'
startdate = '20181008'
enddate = '20181228'import numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = 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')

Out[12]:

(<matplotlib.collections.LineCollection at 0x7f8b275eb048>,<matplotlib.collections.PolyCollection at 0x7f8b275eb588>)

相似K线预测应用

In [13]:

data = get_price(stocklist,'20140101','20190211','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)stock = ['600000.SH']
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index('20190211')
close = closedf[stock].iloc[num-59:num+1]
opens = opendf[stock].iloc[num-59:num+1]
high = highdf[stock].iloc[num-59:num+1]
low = lowdf[stock].iloc[num-59:num+1]
import numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
for s in stock:open1=list(opens[s])high1=list(high[s])low1=list(low[s])close1=list(close[s])#画图fig,ax = plt.subplots(figsize = (10,6.18),facecolor='white')fig.subplots_adjust() ticks = ax.set_xticks([0,60])labels = ax.set_xticklabels([list(opens.index.strftime('%Y%m%d'))[0],list(opens.index.strftime('%Y%m%d'))[-1]], 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')

In [14]:

dt = pd.DataFrame(columns=['stock','startdate','enddate','T'])
stock = '600000.SH'
trade = list(closedf.index.strftime('%Y%m%d'))
num = trade.index('20190211')
close = list(closedf[stock].iloc[num-59:num+1])
opens = list(opendf[stock].iloc[num-59:num+1])
high = list(highdf[stock].iloc[num-59:num+1])
low = list(lowdf[stock].iloc[num-59:num+1])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(opens,opens2[s])[0][1],3)corrhigh = round(np.corrcoef(high,high2[s])[0][1],3)corrlow = round(np.corrcoef(low,low2[s])[0][1],3)corrclose = round(np.corrcoef(close,close2[s])[0][1],3)#综合值T = (corropen+corrhigh+corrlow+corrclose)/4startdate = 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 1243
80 1243
100 1243
120 1243
140 1243
160 1243
180 1243
200 1243
220 1243
240 1243
260 1243
280 1243
300 1243
320 1243
340 1243
360 1243
380 1243
400 1243
420 1243
440 1243
460 1243
480 1243
500 1243
520 1243
540 1243
560 1243
580 1243
600 1243
620 1243
640 1243
660 1243
680 1243
700 1243
720 1243
740 1243
760 1243
780 1243
800 1243
820 1243
840 1243
860 1243
880 1243
900 1243
920 1243
940 1243
960 1243
980 1243
1000 1243
1020 1243
1040 1243
1060 1243
1080 1243
1100 1243
1120 1243
1140 1243
1160 1243
1180 1243
1200 1243
1220 1243

Out[14]:

stockstartdateenddateT
7600048.SH20140103201404040.87700
2674601166.SH20180511201808060.85375
2650600000.SH20180511201808060.85150
2656600036.SH20180511201808060.84825
2687601628.SH20180511201808060.84050
2680601318.SH20180511201808060.83975
2692601818.SH20180511201808060.83725
2679601288.SH20180511201808060.83650
1218600690.SH20151222201603230.82425
2651600016.SH20180511201808060.81625
1966600585.SH20170317201706160.81250
1396601988.SH20160323201606210.79950
2909600104.SH20181009201901030.79650
1377601211.SH20160323201606210.79200
1975601169.SH20170317201706160.79100
1381601328.SH20160323201606210.79075
2695601939.SH20180511201808060.79025
269600703.SH20140605201408280.79000
2690601766.SH20180511201808060.78700
1853600028.SH20170113201704180.78625
2868600690.SH20180903201812040.78550
1394601888.SH20160323201606210.78475
38601668.SH20140103201404040.78050
2521601006.SH20180205201805110.77425
1392601818.SH20160323201606210.77375
2296601988.SH20170908201712080.77000
2281601328.SH20170908201712080.76975
1993601857.SH20170317201706160.76900
2518600690.SH20180205201805110.76850
2655600030.SH20180511201808060.76800
...............
721601006.SH2015030320150528-0.78000
2648603259.SH2018041120180709-0.78025
264600519.SH2014060520140828-0.78100
590601766.SH2014112820150303-0.78550
2428601229.SH2017120820180312-0.79150
1055600030.SH2015092220151222-0.79475
63600340.SH2014020720140507-0.79525
3600028.SH2014010320140404-0.79925
1689601688.SH2016091320161215-0.79925
740601766.SH2015030320150528-0.80600
1489601688.SH2016052020160816-0.81050
2189601688.SH2017071420171013-0.81650
2741601800.SH2018060820180903-0.81750
367600606.SH2014073120141031-0.81800
257600048.SH2014060520140828-0.81800
263600340.SH2014060520140828-0.82200
2004600029.SH2017041820170714-0.82300
2429601288.SH2017120820180312-0.82525
1913600340.SH2017021720170517-0.83075
1938601668.SH2017021720170517-0.83975
10600196.SH2014010320140404-0.84200
2186601601.SH2017071420171013-0.84600
2431601328.SH2017120820180312-0.84950
2445601939.SH2017120820180312-0.84975
2435601398.SH2017120820180312-0.85700
2843601857.SH2018080620181106-0.86225
2446601988.SH2017120820180312-0.86375
67600606.SH2014020720140507-0.86875
2442601818.SH2017120820180312-0.87700
1497601989.SH2016052020160816-0.87900

2950 rows × 4 columns

In [15]:

Tdt = dt.iloc[0]stock = Tdt.stock
startdate = Tdt.startdate     
enddate = Tdt.enddate   import numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = 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')

Out[15]:

(<matplotlib.collections.LineCollection at 0x7f8b26a53b00>,<matplotlib.collections.PolyCollection at 0x7f8b26a50ef0>)

快速挑选出与大盘走势同步、相反的个股

In [16]:

indexcode = '000001.SH'
date = '20190211'
stocklist = list(get_all_securities('stock',date).index)+[indexcode]
stocklist

Out[16]:

['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',...]

获取数据

In [17]:

data = get_price(stocklist,None,date,'1d',['open','high','low','close'],bar_count = 60,is_panel =1)
data

Out[17]:

<class 'pandas.core.panel.Panel'>
Dimensions: 4 (items) x 60 (major_axis) x 3586 (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.SH to 603999.SH

In [18]:

closedf = data['close'].fillna(0)
opendf = data['open'].fillna(0)
highdf = data['high'].fillna(0)
lowdf = data['low'].fillna(0)
lowdf

Out[18]:

000001.SH000001.SZ000002.SZ000004.SZ000005.SZ000006.SZ000007.SZ000008.SZ000009.SZ000010.SZ...603987.SH603988.SH603989.SH603990.SH603991.SH603993.SH603996.SH603997.SH603998.SH603999.SH
2018-11-092598.161010.4023.5316.002.865.036.714.434.274.26...6.049.9222.1030.0117.704.108.407.955.184.75
2018-11-122590.211010.3823.4016.152.794.977.063.994.264.20...6.0110.9922.3030.1517.904.048.447.915.204.74
2018-11-132597.348010.3823.4416.502.935.058.034.124.374.23...6.0910.8622.3330.5018.184.068.407.935.334.82
2018-11-142627.956510.4223.9617.003.045.247.924.194.504.33...6.2510.6422.5132.0319.144.138.728.165.585.08
2018-11-152631.887510.4223.9616.803.015.247.704.154.594.34...6.2810.6022.5131.9919.514.108.878.185.535.11
2018-11-162657.034110.4924.0216.933.045.457.754.154.874.40...6.4310.6222.8032.7020.304.158.968.265.645.21
2018-11-192674.178110.5724.6817.303.115.518.154.135.334.42...6.4510.8222.5532.2620.074.118.858.265.685.25
2018-11-202643.358810.5225.2316.803.035.477.884.005.024.30...6.2710.7022.0831.8519.344.108.748.005.525.11
2018-11-212617.775910.4825.3516.652.975.398.233.965.044.25...6.1910.6021.0031.5019.353.978.537.885.424.98
2018-11-222634.482710.4825.2817.043.035.459.054.125.004.32...6.4310.7521.1831.6619.454.058.728.195.575.11
2018-11-232577.351110.3124.6816.492.885.259.374.014.744.31...6.0610.3521.0131.2118.513.857.968.365.215.04
2018-11-262568.035210.3024.7416.352.875.258.643.954.754.34...6.0710.1120.6831.5018.353.797.958.205.155.12
2018-11-272566.166310.1624.7816.462.895.268.143.954.844.47...6.1410.0120.7031.7618.533.808.028.215.135.17
2018-11-282561.561810.1624.9916.672.895.177.933.894.744.42...6.0310.1220.5031.8818.133.777.888.255.085.02
2018-11-292567.443410.1925.0016.322.995.327.293.754.694.45...6.409.8019.7031.7017.733.867.968.005.115.10
2018-11-302555.322310.1725.0315.962.905.226.873.664.584.02...6.608.8719.8031.7017.803.827.867.965.064.80
2018-12-032629.184310.4724.8116.393.035.447.263.854.854.06...6.7010.8020.7232.6618.684.058.258.165.255.05
2018-12-042644.896410.5324.8616.523.035.497.393.964.894.06...6.7710.7121.0532.7618.914.038.348.115.275.05
2018-12-052625.913210.4024.7616.552.985.477.843.914.804.01...6.6110.7021.3831.3518.803.978.198.155.475.35
2018-12-062603.132310.2324.9016.642.955.557.763.914.754.02...6.6610.3821.4632.4218.504.058.188.105.305.80
2018-12-072599.277510.2725.1216.303.005.627.913.904.763.86...6.5510.2021.2532.6018.634.038.218.005.205.46
2018-12-102576.242410.1324.9015.802.915.537.203.804.653.82...6.3510.1921.1032.0818.033.978.167.665.055.12
2018-12-112583.195910.1724.9116.072.935.627.383.834.663.70...6.4310.2321.2032.1218.203.978.227.655.075.19
2018-12-122595.075010.2026.1416.522.995.768.253.854.713.61...6.4010.2821.2631.7418.314.038.247.795.105.25
2018-12-132599.458610.2026.4016.412.995.728.343.864.733.52...6.7110.4221.2831.5318.354.078.168.155.095.21
2018-12-142593.740710.1626.3116.462.925.668.103.964.583.38...6.469.9620.8831.2018.034.078.018.105.035.10
2018-12-172573.867410.1025.9417.252.915.728.053.904.523.38...6.319.9020.3031.5117.754.047.947.924.885.03
2018-12-182563.573110.1025.3416.832.875.388.223.824.563.45...6.339.8320.2132.1917.664.097.687.824.895.08
2018-12-192547.07839.9025.1516.322.865.428.793.814.553.47...6.339.9820.2132.1017.614.087.717.804.885.08
2018-12-202516.01939.6324.9116.302.845.408.613.794.533.45...6.369.9520.1931.9017.514.017.757.714.845.06
2018-12-212498.69379.3323.7016.172.835.338.233.804.483.46...6.549.8920.3231.2817.553.917.627.704.865.11
2018-12-242500.44309.3123.3316.082.825.278.183.804.503.45...6.619.8020.2031.8017.613.927.657.724.915.09
2018-12-252462.84489.2123.3815.922.725.038.013.854.233.32...6.359.8020.0731.6017.453.767.337.384.794.80
2018-12-262492.07589.2723.5816.162.735.158.463.964.373.40...6.4310.0620.4532.2618.363.847.567.464.854.90
2018-12-272483.08649.2823.4416.032.665.168.103.844.303.26...6.429.9520.1032.7918.373.757.437.504.654.81
2018-12-282478.32509.3123.6715.732.655.157.903.854.303.20...6.349.9820.0032.6018.183.747.367.404.674.81
2019-01-022456.42339.1623.6716.012.665.107.993.814.263.25...6.429.8219.2532.1518.063.657.487.654.524.75
2019-01-032455.92569.1523.7116.002.655.117.583.834.233.26...6.409.6618.7531.8017.823.677.477.704.534.72
2019-01-042440.90669.2223.8516.012.665.067.503.804.183.22...6.369.6218.5931.7917.423.677.367.724.504.66
2019-01-072515.50839.6324.9916.462.765.287.933.924.413.32...6.589.9519.3931.8018.363.837.737.754.744.92
2019-01-082520.16489.6224.6316.802.825.317.824.034.443.35...6.5510.0319.2031.8118.563.857.747.784.865.01
2019-01-092536.15709.7025.1116.722.845.347.804.064.463.36...6.8010.1819.5331.8718.853.838.017.854.925.00
2019-01-102531.66389.8625.0316.662.845.297.774.004.413.36...6.7210.2219.1631.8118.853.807.897.904.984.96
2019-01-112533.358610.0525.0116.492.915.307.633.984.403.34...6.6810.1919.2331.5518.793.807.917.705.004.95
2019-01-142533.010110.0724.9216.492.975.286.974.004.443.52...6.359.9418.7631.5019.063.807.877.645.004.93
2019-01-152532.433310.0924.3216.403.045.237.053.984.443.47...6.3510.0118.9031.5218.883.807.917.775.004.94
2019-01-162563.006110.2324.8316.552.965.317.074.004.433.51...6.4010.2419.3831.5619.143.818.087.775.034.97
2019-01-172557.711410.1724.9416.402.955.256.773.954.373.42...6.289.8818.8031.5018.693.787.997.624.964.95
2019-01-182565.904310.2824.9916.442.955.246.563.804.333.27...6.349.7518.8631.5018.583.817.957.614.984.86
2019-01-212599.057510.3225.4016.422.965.336.723.894.403.31...6.429.8118.9131.0518.283.917.997.665.025.07
2019-01-222573.061710.2625.2316.282.925.256.703.894.253.34...6.429.6818.8231.3618.893.857.877.654.975.03
2019-01-232572.405410.2925.2016.202.975.236.623.864.263.31...6.379.6618.7131.5318.753.837.867.614.934.97
2019-01-242569.700410.3724.9316.222.905.206.453.844.283.28...6.399.6817.9531.8518.593.838.077.624.944.97
2019-01-252595.629410.5525.4916.272.915.256.203.854.283.25...6.369.5917.7332.0318.433.838.027.634.934.93
2019-01-282591.100010.8825.8616.012.905.205.613.854.223.24...6.129.3217.7532.2218.233.837.937.544.864.93
2019-01-292559.982010.7725.8715.002.785.105.053.804.083.02...5.929.0717.6332.2717.533.627.237.414.715.10
2019-01-302575.409110.8626.6315.032.805.124.613.824.122.82...6.059.2217.5132.3917.273.737.287.334.654.92
2019-01-312571.578910.9427.0014.052.825.114.753.504.022.85...5.858.4117.5032.6016.573.787.257.014.614.72
2019-02-012590.554310.9626.9814.702.855.174.883.654.082.91...5.968.7517.5633.1316.803.837.467.124.664.73
2019-02-112613.174210.9726.8914.852.975.255.123.614.263.04...6.199.0418.1234.9117.453.897.927.454.774.86

60 rows × 3586 columns

绘制大盘走势图

In [19]:

stock = indexcode
startdate = '20181109'
enddate = dateimport numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = 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() 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')

Out[19]:

(<matplotlib.collections.LineCollection at 0x7f8b25f69588>,<matplotlib.collections.PolyCollection at 0x7f8b25f695f8>)

In [20]:

dt = pd.DataFrame(columns=['stock','startdate','enddate','T'])
stock = '000001.SH'
trade = list(closedf.index.strftime('%Y%m%d'))
close = list(closedf[stock])
opens = list(opendf[stock])
high = list(highdf[stock])
low = list(lowdf[stock])stocklist = list(closedf.columns)
y=0
for s in stocklist:corropen = round(np.corrcoef(opens,opendf[s])[0][1],3)corrhigh = round(np.corrcoef(high,highdf[s])[0][1],3)corrlow = round(np.corrcoef(low,lowdf[s])[0][1],3)corrclose = round(np.corrcoef(close,closedf[s])[0][1],3)#综合值T = (corropen+corrhigh+corrlow+corrclose)/4startdate = '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

Out[20]:

stockstartdateenddateT
0000001.SH20181109201902111.00000
177000598.SZ20181109201902110.94000
3382603588.SH20181109201902110.93050
51000066.SZ20181109201902110.92375
144000553.SZ20181109201902110.92275
2499600449.SH20181109201902110.91825
1285002833.SZ20181109201902110.91250
2806600801.SH20181109201902110.91150
2993601169.SH20181109201902110.90825
2441600367.SH20181109201902110.90800
704002240.SZ20181109201902110.90800
1213002756.SZ20181109201902110.90750
592002128.SZ20181109201902110.90675
2903600926.SH20181109201902110.90550
700002236.SZ20181109201902110.90250
882002419.SZ20181109201902110.90175
192000616.SZ20181109201902110.90175
2641600618.SH20181109201902110.89975
3126601996.SH20181109201902110.89875
99000488.SZ20181109201902110.89700
542002078.SZ20181109201902110.89700
3018601318.SH20181109201902110.89650
1762300376.SZ20181109201902110.89625
2857600859.SH20181109201902110.89625
2951601009.SH20181109201902110.89550
211000639.SZ20181109201902110.89550
869002406.SZ20181109201902110.89450
2234600123.SH20181109201902110.89300
738002275.SZ20181109201902110.89275
838002375.SZ20181109201902110.89200
...............
2811600807.SH2018110920190211-0.56725
707002243.SZ2018110920190211-0.56775
1333002885.SZ2018110920190211-0.56900
3293603322.SH2018110920190211-0.58125
1223002767.SZ2018110920190211-0.58325
181000603.SZ2018110920190211-0.58875
2576600547.SH2018110920190211-0.59000
3194603098.SH2018110920190211-0.59300
1944300560.SZ2018110920190211-0.59350
1883300497.SZ2018110920190211-0.59400
29000035.SZ2018110920190211-0.60075
2127300753.SZ2018110920190211-0.60125
132000539.SZ2018110920190211-0.60200
909002446.SZ2018110920190211-0.60250
2577600548.SH2018110920190211-0.60575
2338600242.SH2018110920190211-0.60775
899002436.SZ2018110920190211-0.61050
1529300140.SZ2018110920190211-0.61400
1264002811.SZ2018110920190211-0.61625
2015300635.SZ2018110920190211-0.62075
2635600612.SH2018110920190211-0.62150
516002052.SZ2018110920190211-0.62925
1948300565.SZ2018110920190211-0.63600
3368603558.SH2018110920190211-0.64475
1815300429.SZ2018110920190211-0.66475
2527600489.SH2018110920190211-0.68400
2783600775.SH2018110920190211-0.70025
1054002592.SZ2018110920190211-0.70950
1693300305.SZ2018110920190211-0.71700
1371002927.SZ2018110920190211-0.73100

3586 rows × 4 columns

In [21]:

dt =dt.iloc[1:]
dt.describe()

Out[21]:

T
count3585.000000
mean0.421866
std0.349293
min-0.731000
25%0.240000
50%0.524750
75%0.682250
max0.940000

In [22]:

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]) 
x=range(0,len(list(dt.index)))
y=list(dt['T'])
axes.scatter(x,y,color='tomato')
axes.set_title('相似度分布',fontsize=15)#设置Y轴
axes.set_yticks([-1,0,1])
axes.set_yticklabels(['-1','0','1'], fontsize=18)

Out[22]:

[<matplotlib.text.Text at 0x7f8b26360470>,<matplotlib.text.Text at 0x7f8b2750f630>,<matplotlib.text.Text at 0x7f8b2695a0b8>]

In [23]:

s = 1
d = 0.2
sdf = pd.DataFrame(columns=['min','max','数量'])
for t in range(0,10):s = round(s-d,2)mn=smx=s+dnum = len(dt[(dt['T']>mn)&(dt['T']<mx)])sdf.loc[s]=[mn,mx,num]
sdf

Out[23]:

minmax数量
0.80.81.0282.0
0.60.60.81089.0
0.40.40.6920.0
0.20.20.4454.0
0.00.00.2311.0
-0.2-0.20.0232.0
-0.4-0.4-0.2169.0
-0.6-0.6-0.496.0
-0.8-0.8-0.620.0
-1.0-1.0-0.80.0

In [24]:

fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 1, 0.618]) 
x=range(0,10)
y=list(sdf['数量'])
axes.bar(x,y,color ='tomato')
axes.set_title('相似度数量分布',fontsize = 20)#设置Y轴
axes.set_xticks(x)
axes.set_xticklabels(['1.0~0.8','0.8~0.6','0.6~0.4','0.4~0.2','0.2~0.0','0.0~-0.2','-0.2~-0.4','-0.4~-0.6','-0.6~-0.8','-0.8~-1.0'], fontsize=10)

Out[24]:

[<matplotlib.text.Text at 0x7f8b261da780>,<matplotlib.text.Text at 0x7f8b26acefd0>,<matplotlib.text.Text at 0x7f8b25e29710>,<matplotlib.text.Text at 0x7f8b264e6a58>,<matplotlib.text.Text at 0x7f8b2745fc18>,<matplotlib.text.Text at 0x7f8b274f3198>,<matplotlib.text.Text at 0x7f8b273dc048>,<matplotlib.text.Text at 0x7f8b266bb400>,<matplotlib.text.Text at 0x7f8b2607d240>,<matplotlib.text.Text at 0x7f8b26445ef0>]

近期与大盘走势最相似的个股

In [25]:

stock = dt.iloc[0].stock
startdate = dt.iloc[0].startdate
enddate = dt.iloc[0].enddateimport numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = 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() 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')

Out[25]:

(<matplotlib.collections.LineCollection at 0x7f8b263082e8>,<matplotlib.collections.PolyCollection at 0x7f8b273ce518>)

近期与大盘走势最不相似的个股

In [26]:

stock = dt.iloc[-1].stock
startdate = dt.iloc[-1].startdate
enddate = dt.iloc[-1].enddateimport numpy as np
import matplotlib.pyplot as plt 
from matplotlib.finance import candlestick2_ohlc
import datetime
s = stocktrade = 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() 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')

Out[26]:

(<matplotlib.collections.LineCollection at 0x7f8b275c8da0>,<matplotlib.collections.PolyCollection at 0x7f8b257a6ba8>)

In [ ]:

查看以上策略详细请 到 supermind量化交易官网查看:技术面分析专题(一)--相似k线在预测股价中的运用

这篇关于同花顺Supermind量化交易 技术面分析专题(一)--相似k线在预测股价中的运用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/395123

相关文章

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)

原文链接: https://tecdat.cn/?p=37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预售小鹏汇天分体式飞行汽车,探索分体式飞行汽车城际通勤。阅读原文,获取专题报告合集全文,解锁文末271份飞行汽车相关行业研究报告。 据悉,业内人士对飞行汽车行业

金融业开源技术 术语

金融业开源技术  术语 1  范围 本文件界定了金融业开源技术的常用术语。 本文件适用于金融业中涉及开源技术的相关标准及规范性文件制定和信息沟通等活动。

poj 2431 poj 3253 优先队列的运用

poj 2431: 题意: 一条路起点为0, 终点为l。 卡车初始时在0点,并且有p升油,假设油箱无限大。 给n个加油站,每个加油站距离终点 l 距离为 x[i],可以加的油量为fuel[i]。 问最少加几次油可以到达终点,若不能到达,输出-1。 解析: 《挑战程序设计竞赛》: “在卡车开往终点的途中,只有在加油站才可以加油。但是,如果认为“在到达加油站i时,就获得了一

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

MOLE 2.5 分析分子通道和孔隙

软件介绍 生物大分子通道和孔隙在生物学中发挥着重要作用,例如在分子识别和酶底物特异性方面。 我们介绍了一种名为 MOLE 2.5 的高级软件工具,该工具旨在分析分子通道和孔隙。 与其他可用软件工具的基准测试表明,MOLE 2.5 相比更快、更强大、功能更丰富。作为一项新功能,MOLE 2.5 可以估算已识别通道的物理化学性质。 软件下载 https://pan.quark.cn/s/57

衡石分析平台使用手册-单机安装及启动

单机安装及启动​ 本文讲述如何在单机环境下进行 HENGSHI SENSE 安装的操作过程。 在安装前请确认网络环境,如果是隔离环境,无法连接互联网时,请先按照 离线环境安装依赖的指导进行依赖包的安装,然后按照本文的指导继续操作。如果网络环境可以连接互联网,请直接按照本文的指导进行安装。 准备工作​ 请参考安装环境文档准备安装环境。 配置用户与安装目录。 在操作前请检查您是否有 sud

线性因子模型 - 独立分量分析(ICA)篇

序言 线性因子模型是数据分析与机器学习中的一类重要模型,它们通过引入潜变量( latent variables \text{latent variables} latent variables)来更好地表征数据。其中,独立分量分析( ICA \text{ICA} ICA)作为线性因子模型的一种,以其独特的视角和广泛的应用领域而备受关注。 ICA \text{ICA} ICA旨在将观察到的复杂信号

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出 在数字化时代,文本到语音(Text-to-Speech, TTS)技术已成为人机交互的关键桥梁,无论是为视障人士提供辅助阅读,还是为智能助手注入声音的灵魂,TTS 技术都扮演着至关重要的角色。从最初的拼接式方法到参数化技术,再到现今的深度学习解决方案,TTS 技术经历了一段长足的进步。这篇文章将带您穿越时

系统架构设计师: 信息安全技术

简简单单 Online zuozuo: 简简单单 Online zuozuo 简简单单 Online zuozuo 简简单单 Online zuozuo 简简单单 Online zuozuo :本心、输入输出、结果 简简单单 Online zuozuo : 文章目录 系统架构设计师: 信息安全技术前言信息安全的基本要素:信息安全的范围:安全措施的目标:访问控制技术要素:访问控制包括:等保