本文主要是介绍同花顺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-08 | 10.15 |
2018-10-09 | 10.07 |
2018-10-10 | 10.13 |
2018-10-11 | 9.71 |
2018-10-12 | 9.83 |
2018-10-15 | 9.97 |
2018-10-16 | 9.97 |
2018-10-17 | 10.14 |
2018-10-18 | 10.16 |
2018-10-19 | 10.07 |
2018-10-22 | 10.32 |
2018-10-23 | 10.45 |
2018-10-24 | 10.52 |
2018-10-25 | 10.54 |
2018-10-26 | 10.74 |
2018-10-29 | 10.71 |
2018-10-30 | 10.89 |
2018-10-31 | 10.87 |
2018-11-01 | 10.86 |
2018-11-02 | 10.94 |
2018-11-05 | 11.08 |
2018-11-06 | 11.00 |
2018-11-07 | 10.87 |
2018-11-08 | 10.90 |
2018-11-09 | 10.70 |
2018-11-12 | 10.75 |
2018-11-13 | 10.68 |
2018-11-14 | 10.68 |
2018-11-15 | 10.65 |
2018-11-16 | 10.71 |
2018-11-19 | 10.77 |
2018-11-20 | 10.65 |
2018-11-21 | 10.61 |
2018-11-22 | 10.57 |
2018-11-23 | 10.50 |
2018-11-26 | 10.43 |
2018-11-27 | 10.45 |
2018-11-28 | 10.50 |
2018-11-29 | 10.54 |
2018-11-30 | 10.62 |
2018-12-03 | 10.84 |
2018-12-04 | 10.97 |
2018-12-05 | 10.96 |
2018-12-06 | 10.82 |
2018-12-07 | 10.88 |
2018-12-10 | 10.77 |
2018-12-11 | 10.69 |
2018-12-12 | 10.70 |
2018-12-13 | 10.73 |
2018-12-14 | 10.59 |
2018-12-17 | 10.62 |
2018-12-18 | 10.54 |
2018-12-19 | 10.54 |
2018-12-20 | 10.11 |
2018-12-21 | 10.00 |
2018-12-24 | 9.86 |
2018-12-25 | 9.60 |
2018-12-26 | 9.64 |
2018-12-27 | 9.66 |
2018-12-28 | 9.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]:
stock | startdate | enddate | T | |
---|---|---|---|---|
776 | 601186.SH | 20150331 | 20150626 | 0.86850 |
790 | 601766.SH | 20150331 | 20150626 | 0.82450 |
1520 | 600887.SH | 20160621 | 20160913 | 0.81300 |
2200 | 600000.SH | 20170811 | 20171110 | 0.79325 |
2246 | 601988.SH | 20170811 | 20171110 | 0.78500 |
1504 | 600029.SH | 20160621 | 20160913 | 0.78300 |
1145 | 601939.SH | 20151027 | 20160120 | 0.77400 |
1683 | 601360.SH | 20160913 | 20161215 | 0.76775 |
2668 | 600690.SH | 20180511 | 20180806 | 0.76775 |
784 | 601390.SH | 20150331 | 20150626 | 0.76100 |
2239 | 601688.SH | 20170811 | 20171110 | 0.74875 |
1105 | 600030.SH | 20151027 | 20160120 | 0.74600 |
2670 | 600887.SH | 20180511 | 20180806 | 0.74400 |
2616 | 600585.SH | 20180411 | 20180709 | 0.74325 |
1346 | 601988.SH | 20160224 | 20160520 | 0.74275 |
1557 | 600048.SH | 20160719 | 20161020 | 0.73550 |
1883 | 601360.SH | 20170113 | 20170418 | 0.73075 |
2227 | 601211.SH | 20170811 | 20171110 | 0.72825 |
2622 | 601088.SH | 20180411 | 20180709 | 0.72750 |
2636 | 601601.SH | 20180411 | 20180709 | 0.72750 |
751 | 600016.SH | 20150331 | 20150626 | 0.72675 |
1142 | 601818.SH | 20151027 | 20160120 | 0.72600 |
1342 | 601818.SH | 20160224 | 20160520 | 0.72150 |
1146 | 601988.SH | 20151027 | 20160120 | 0.71950 |
1338 | 601668.SH | 20160224 | 20160520 | 0.71900 |
2054 | 600029.SH | 20170517 | 20170811 | 0.71750 |
1117 | 600606.SH | 20151027 | 20160120 | 0.71700 |
1331 | 601328.SH | 20160224 | 20160520 | 0.71600 |
2337 | 601628.SH | 20171013 | 20180108 | 0.70975 |
788 | 601668.SH | 20150331 | 20150626 | 0.70750 |
... | ... | ... | ... | ... |
1632 | 601336.SH | 20160816 | 20161117 | -0.74300 |
1799 | 603993.SH | 20161117 | 20170217 | -0.74375 |
1437 | 601628.SH | 20160421 | 20160719 | -0.74750 |
1401 | 600016.SH | 20160421 | 20160719 | -0.74775 |
192 | 601818.SH | 20140404 | 20140703 | -0.75200 |
626 | 601186.SH | 20141226 | 20150331 | -0.75275 |
1443 | 601857.SH | 20160421 | 20160719 | -0.75475 |
1427 | 601211.SH | 20160421 | 20160719 | -0.75875 |
2329 | 601288.SH | 20171013 | 20180108 | -0.75925 |
634 | 601390.SH | 20141226 | 20150331 | -0.76600 |
638 | 601668.SH | 20141226 | 20150331 | -0.76800 |
1937 | 601628.SH | 20170217 | 20170517 | -0.76800 |
1201 | 600016.SH | 20151222 | 20160323 | -0.76850 |
1438 | 601668.SH | 20160421 | 20160719 | -0.76925 |
1932 | 601336.SH | 20170217 | 20170517 | -0.77175 |
605 | 600030.SH | 20141226 | 20150331 | -0.77400 |
639 | 601688.SH | 20141226 | 20150331 | -0.78350 |
152 | 600019.SH | 20140404 | 20140703 | -0.78500 |
215 | 600547.SH | 20140507 | 20140731 | -0.78625 |
239 | 601688.SH | 20140507 | 20140731 | -0.78850 |
2159 | 600104.SH | 20170714 | 20171013 | -0.79475 |
1403 | 600028.SH | 20160421 | 20160719 | -0.79875 |
602 | 600019.SH | 20141226 | 20150331 | -0.80200 |
1416 | 600585.SH | 20160421 | 20160719 | -0.80500 |
220 | 600887.SH | 20140507 | 20140731 | -0.80775 |
620 | 600887.SH | 20141226 | 20150331 | -0.80825 |
2730 | 601318.SH | 20180608 | 20180903 | -0.81375 |
2568 | 600690.SH | 20180312 | 20180608 | -0.81875 |
1422 | 601088.SH | 20160421 | 20160719 | -0.82450 |
1408 | 600050.SH | 20160421 | 20160719 | -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]:
stock | startdate | enddate | T | |
---|---|---|---|---|
7 | 600048.SH | 20140103 | 20140404 | 0.87700 |
2674 | 601166.SH | 20180511 | 20180806 | 0.85375 |
2650 | 600000.SH | 20180511 | 20180806 | 0.85150 |
2656 | 600036.SH | 20180511 | 20180806 | 0.84825 |
2687 | 601628.SH | 20180511 | 20180806 | 0.84050 |
2680 | 601318.SH | 20180511 | 20180806 | 0.83975 |
2692 | 601818.SH | 20180511 | 20180806 | 0.83725 |
2679 | 601288.SH | 20180511 | 20180806 | 0.83650 |
1218 | 600690.SH | 20151222 | 20160323 | 0.82425 |
2651 | 600016.SH | 20180511 | 20180806 | 0.81625 |
1966 | 600585.SH | 20170317 | 20170616 | 0.81250 |
1396 | 601988.SH | 20160323 | 20160621 | 0.79950 |
2909 | 600104.SH | 20181009 | 20190103 | 0.79650 |
1377 | 601211.SH | 20160323 | 20160621 | 0.79200 |
1975 | 601169.SH | 20170317 | 20170616 | 0.79100 |
1381 | 601328.SH | 20160323 | 20160621 | 0.79075 |
2695 | 601939.SH | 20180511 | 20180806 | 0.79025 |
269 | 600703.SH | 20140605 | 20140828 | 0.79000 |
2690 | 601766.SH | 20180511 | 20180806 | 0.78700 |
1853 | 600028.SH | 20170113 | 20170418 | 0.78625 |
2868 | 600690.SH | 20180903 | 20181204 | 0.78550 |
1394 | 601888.SH | 20160323 | 20160621 | 0.78475 |
38 | 601668.SH | 20140103 | 20140404 | 0.78050 |
2521 | 601006.SH | 20180205 | 20180511 | 0.77425 |
1392 | 601818.SH | 20160323 | 20160621 | 0.77375 |
2296 | 601988.SH | 20170908 | 20171208 | 0.77000 |
2281 | 601328.SH | 20170908 | 20171208 | 0.76975 |
1993 | 601857.SH | 20170317 | 20170616 | 0.76900 |
2518 | 600690.SH | 20180205 | 20180511 | 0.76850 |
2655 | 600030.SH | 20180511 | 20180806 | 0.76800 |
... | ... | ... | ... | ... |
721 | 601006.SH | 20150303 | 20150528 | -0.78000 |
2648 | 603259.SH | 20180411 | 20180709 | -0.78025 |
264 | 600519.SH | 20140605 | 20140828 | -0.78100 |
590 | 601766.SH | 20141128 | 20150303 | -0.78550 |
2428 | 601229.SH | 20171208 | 20180312 | -0.79150 |
1055 | 600030.SH | 20150922 | 20151222 | -0.79475 |
63 | 600340.SH | 20140207 | 20140507 | -0.79525 |
3 | 600028.SH | 20140103 | 20140404 | -0.79925 |
1689 | 601688.SH | 20160913 | 20161215 | -0.79925 |
740 | 601766.SH | 20150303 | 20150528 | -0.80600 |
1489 | 601688.SH | 20160520 | 20160816 | -0.81050 |
2189 | 601688.SH | 20170714 | 20171013 | -0.81650 |
2741 | 601800.SH | 20180608 | 20180903 | -0.81750 |
367 | 600606.SH | 20140731 | 20141031 | -0.81800 |
257 | 600048.SH | 20140605 | 20140828 | -0.81800 |
263 | 600340.SH | 20140605 | 20140828 | -0.82200 |
2004 | 600029.SH | 20170418 | 20170714 | -0.82300 |
2429 | 601288.SH | 20171208 | 20180312 | -0.82525 |
1913 | 600340.SH | 20170217 | 20170517 | -0.83075 |
1938 | 601668.SH | 20170217 | 20170517 | -0.83975 |
10 | 600196.SH | 20140103 | 20140404 | -0.84200 |
2186 | 601601.SH | 20170714 | 20171013 | -0.84600 |
2431 | 601328.SH | 20171208 | 20180312 | -0.84950 |
2445 | 601939.SH | 20171208 | 20180312 | -0.84975 |
2435 | 601398.SH | 20171208 | 20180312 | -0.85700 |
2843 | 601857.SH | 20180806 | 20181106 | -0.86225 |
2446 | 601988.SH | 20171208 | 20180312 | -0.86375 |
67 | 600606.SH | 20140207 | 20140507 | -0.86875 |
2442 | 601818.SH | 20171208 | 20180312 | -0.87700 |
1497 | 601989.SH | 20160520 | 20160816 | -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.SH | 000001.SZ | 000002.SZ | 000004.SZ | 000005.SZ | 000006.SZ | 000007.SZ | 000008.SZ | 000009.SZ | 000010.SZ | ... | 603987.SH | 603988.SH | 603989.SH | 603990.SH | 603991.SH | 603993.SH | 603996.SH | 603997.SH | 603998.SH | 603999.SH | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2018-11-09 | 2598.1610 | 10.40 | 23.53 | 16.00 | 2.86 | 5.03 | 6.71 | 4.43 | 4.27 | 4.26 | ... | 6.04 | 9.92 | 22.10 | 30.01 | 17.70 | 4.10 | 8.40 | 7.95 | 5.18 | 4.75 |
2018-11-12 | 2590.2110 | 10.38 | 23.40 | 16.15 | 2.79 | 4.97 | 7.06 | 3.99 | 4.26 | 4.20 | ... | 6.01 | 10.99 | 22.30 | 30.15 | 17.90 | 4.04 | 8.44 | 7.91 | 5.20 | 4.74 |
2018-11-13 | 2597.3480 | 10.38 | 23.44 | 16.50 | 2.93 | 5.05 | 8.03 | 4.12 | 4.37 | 4.23 | ... | 6.09 | 10.86 | 22.33 | 30.50 | 18.18 | 4.06 | 8.40 | 7.93 | 5.33 | 4.82 |
2018-11-14 | 2627.9565 | 10.42 | 23.96 | 17.00 | 3.04 | 5.24 | 7.92 | 4.19 | 4.50 | 4.33 | ... | 6.25 | 10.64 | 22.51 | 32.03 | 19.14 | 4.13 | 8.72 | 8.16 | 5.58 | 5.08 |
2018-11-15 | 2631.8875 | 10.42 | 23.96 | 16.80 | 3.01 | 5.24 | 7.70 | 4.15 | 4.59 | 4.34 | ... | 6.28 | 10.60 | 22.51 | 31.99 | 19.51 | 4.10 | 8.87 | 8.18 | 5.53 | 5.11 |
2018-11-16 | 2657.0341 | 10.49 | 24.02 | 16.93 | 3.04 | 5.45 | 7.75 | 4.15 | 4.87 | 4.40 | ... | 6.43 | 10.62 | 22.80 | 32.70 | 20.30 | 4.15 | 8.96 | 8.26 | 5.64 | 5.21 |
2018-11-19 | 2674.1781 | 10.57 | 24.68 | 17.30 | 3.11 | 5.51 | 8.15 | 4.13 | 5.33 | 4.42 | ... | 6.45 | 10.82 | 22.55 | 32.26 | 20.07 | 4.11 | 8.85 | 8.26 | 5.68 | 5.25 |
2018-11-20 | 2643.3588 | 10.52 | 25.23 | 16.80 | 3.03 | 5.47 | 7.88 | 4.00 | 5.02 | 4.30 | ... | 6.27 | 10.70 | 22.08 | 31.85 | 19.34 | 4.10 | 8.74 | 8.00 | 5.52 | 5.11 |
2018-11-21 | 2617.7759 | 10.48 | 25.35 | 16.65 | 2.97 | 5.39 | 8.23 | 3.96 | 5.04 | 4.25 | ... | 6.19 | 10.60 | 21.00 | 31.50 | 19.35 | 3.97 | 8.53 | 7.88 | 5.42 | 4.98 |
2018-11-22 | 2634.4827 | 10.48 | 25.28 | 17.04 | 3.03 | 5.45 | 9.05 | 4.12 | 5.00 | 4.32 | ... | 6.43 | 10.75 | 21.18 | 31.66 | 19.45 | 4.05 | 8.72 | 8.19 | 5.57 | 5.11 |
2018-11-23 | 2577.3511 | 10.31 | 24.68 | 16.49 | 2.88 | 5.25 | 9.37 | 4.01 | 4.74 | 4.31 | ... | 6.06 | 10.35 | 21.01 | 31.21 | 18.51 | 3.85 | 7.96 | 8.36 | 5.21 | 5.04 |
2018-11-26 | 2568.0352 | 10.30 | 24.74 | 16.35 | 2.87 | 5.25 | 8.64 | 3.95 | 4.75 | 4.34 | ... | 6.07 | 10.11 | 20.68 | 31.50 | 18.35 | 3.79 | 7.95 | 8.20 | 5.15 | 5.12 |
2018-11-27 | 2566.1663 | 10.16 | 24.78 | 16.46 | 2.89 | 5.26 | 8.14 | 3.95 | 4.84 | 4.47 | ... | 6.14 | 10.01 | 20.70 | 31.76 | 18.53 | 3.80 | 8.02 | 8.21 | 5.13 | 5.17 |
2018-11-28 | 2561.5618 | 10.16 | 24.99 | 16.67 | 2.89 | 5.17 | 7.93 | 3.89 | 4.74 | 4.42 | ... | 6.03 | 10.12 | 20.50 | 31.88 | 18.13 | 3.77 | 7.88 | 8.25 | 5.08 | 5.02 |
2018-11-29 | 2567.4434 | 10.19 | 25.00 | 16.32 | 2.99 | 5.32 | 7.29 | 3.75 | 4.69 | 4.45 | ... | 6.40 | 9.80 | 19.70 | 31.70 | 17.73 | 3.86 | 7.96 | 8.00 | 5.11 | 5.10 |
2018-11-30 | 2555.3223 | 10.17 | 25.03 | 15.96 | 2.90 | 5.22 | 6.87 | 3.66 | 4.58 | 4.02 | ... | 6.60 | 8.87 | 19.80 | 31.70 | 17.80 | 3.82 | 7.86 | 7.96 | 5.06 | 4.80 |
2018-12-03 | 2629.1843 | 10.47 | 24.81 | 16.39 | 3.03 | 5.44 | 7.26 | 3.85 | 4.85 | 4.06 | ... | 6.70 | 10.80 | 20.72 | 32.66 | 18.68 | 4.05 | 8.25 | 8.16 | 5.25 | 5.05 |
2018-12-04 | 2644.8964 | 10.53 | 24.86 | 16.52 | 3.03 | 5.49 | 7.39 | 3.96 | 4.89 | 4.06 | ... | 6.77 | 10.71 | 21.05 | 32.76 | 18.91 | 4.03 | 8.34 | 8.11 | 5.27 | 5.05 |
2018-12-05 | 2625.9132 | 10.40 | 24.76 | 16.55 | 2.98 | 5.47 | 7.84 | 3.91 | 4.80 | 4.01 | ... | 6.61 | 10.70 | 21.38 | 31.35 | 18.80 | 3.97 | 8.19 | 8.15 | 5.47 | 5.35 |
2018-12-06 | 2603.1323 | 10.23 | 24.90 | 16.64 | 2.95 | 5.55 | 7.76 | 3.91 | 4.75 | 4.02 | ... | 6.66 | 10.38 | 21.46 | 32.42 | 18.50 | 4.05 | 8.18 | 8.10 | 5.30 | 5.80 |
2018-12-07 | 2599.2775 | 10.27 | 25.12 | 16.30 | 3.00 | 5.62 | 7.91 | 3.90 | 4.76 | 3.86 | ... | 6.55 | 10.20 | 21.25 | 32.60 | 18.63 | 4.03 | 8.21 | 8.00 | 5.20 | 5.46 |
2018-12-10 | 2576.2424 | 10.13 | 24.90 | 15.80 | 2.91 | 5.53 | 7.20 | 3.80 | 4.65 | 3.82 | ... | 6.35 | 10.19 | 21.10 | 32.08 | 18.03 | 3.97 | 8.16 | 7.66 | 5.05 | 5.12 |
2018-12-11 | 2583.1959 | 10.17 | 24.91 | 16.07 | 2.93 | 5.62 | 7.38 | 3.83 | 4.66 | 3.70 | ... | 6.43 | 10.23 | 21.20 | 32.12 | 18.20 | 3.97 | 8.22 | 7.65 | 5.07 | 5.19 |
2018-12-12 | 2595.0750 | 10.20 | 26.14 | 16.52 | 2.99 | 5.76 | 8.25 | 3.85 | 4.71 | 3.61 | ... | 6.40 | 10.28 | 21.26 | 31.74 | 18.31 | 4.03 | 8.24 | 7.79 | 5.10 | 5.25 |
2018-12-13 | 2599.4586 | 10.20 | 26.40 | 16.41 | 2.99 | 5.72 | 8.34 | 3.86 | 4.73 | 3.52 | ... | 6.71 | 10.42 | 21.28 | 31.53 | 18.35 | 4.07 | 8.16 | 8.15 | 5.09 | 5.21 |
2018-12-14 | 2593.7407 | 10.16 | 26.31 | 16.46 | 2.92 | 5.66 | 8.10 | 3.96 | 4.58 | 3.38 | ... | 6.46 | 9.96 | 20.88 | 31.20 | 18.03 | 4.07 | 8.01 | 8.10 | 5.03 | 5.10 |
2018-12-17 | 2573.8674 | 10.10 | 25.94 | 17.25 | 2.91 | 5.72 | 8.05 | 3.90 | 4.52 | 3.38 | ... | 6.31 | 9.90 | 20.30 | 31.51 | 17.75 | 4.04 | 7.94 | 7.92 | 4.88 | 5.03 |
2018-12-18 | 2563.5731 | 10.10 | 25.34 | 16.83 | 2.87 | 5.38 | 8.22 | 3.82 | 4.56 | 3.45 | ... | 6.33 | 9.83 | 20.21 | 32.19 | 17.66 | 4.09 | 7.68 | 7.82 | 4.89 | 5.08 |
2018-12-19 | 2547.0783 | 9.90 | 25.15 | 16.32 | 2.86 | 5.42 | 8.79 | 3.81 | 4.55 | 3.47 | ... | 6.33 | 9.98 | 20.21 | 32.10 | 17.61 | 4.08 | 7.71 | 7.80 | 4.88 | 5.08 |
2018-12-20 | 2516.0193 | 9.63 | 24.91 | 16.30 | 2.84 | 5.40 | 8.61 | 3.79 | 4.53 | 3.45 | ... | 6.36 | 9.95 | 20.19 | 31.90 | 17.51 | 4.01 | 7.75 | 7.71 | 4.84 | 5.06 |
2018-12-21 | 2498.6937 | 9.33 | 23.70 | 16.17 | 2.83 | 5.33 | 8.23 | 3.80 | 4.48 | 3.46 | ... | 6.54 | 9.89 | 20.32 | 31.28 | 17.55 | 3.91 | 7.62 | 7.70 | 4.86 | 5.11 |
2018-12-24 | 2500.4430 | 9.31 | 23.33 | 16.08 | 2.82 | 5.27 | 8.18 | 3.80 | 4.50 | 3.45 | ... | 6.61 | 9.80 | 20.20 | 31.80 | 17.61 | 3.92 | 7.65 | 7.72 | 4.91 | 5.09 |
2018-12-25 | 2462.8448 | 9.21 | 23.38 | 15.92 | 2.72 | 5.03 | 8.01 | 3.85 | 4.23 | 3.32 | ... | 6.35 | 9.80 | 20.07 | 31.60 | 17.45 | 3.76 | 7.33 | 7.38 | 4.79 | 4.80 |
2018-12-26 | 2492.0758 | 9.27 | 23.58 | 16.16 | 2.73 | 5.15 | 8.46 | 3.96 | 4.37 | 3.40 | ... | 6.43 | 10.06 | 20.45 | 32.26 | 18.36 | 3.84 | 7.56 | 7.46 | 4.85 | 4.90 |
2018-12-27 | 2483.0864 | 9.28 | 23.44 | 16.03 | 2.66 | 5.16 | 8.10 | 3.84 | 4.30 | 3.26 | ... | 6.42 | 9.95 | 20.10 | 32.79 | 18.37 | 3.75 | 7.43 | 7.50 | 4.65 | 4.81 |
2018-12-28 | 2478.3250 | 9.31 | 23.67 | 15.73 | 2.65 | 5.15 | 7.90 | 3.85 | 4.30 | 3.20 | ... | 6.34 | 9.98 | 20.00 | 32.60 | 18.18 | 3.74 | 7.36 | 7.40 | 4.67 | 4.81 |
2019-01-02 | 2456.4233 | 9.16 | 23.67 | 16.01 | 2.66 | 5.10 | 7.99 | 3.81 | 4.26 | 3.25 | ... | 6.42 | 9.82 | 19.25 | 32.15 | 18.06 | 3.65 | 7.48 | 7.65 | 4.52 | 4.75 |
2019-01-03 | 2455.9256 | 9.15 | 23.71 | 16.00 | 2.65 | 5.11 | 7.58 | 3.83 | 4.23 | 3.26 | ... | 6.40 | 9.66 | 18.75 | 31.80 | 17.82 | 3.67 | 7.47 | 7.70 | 4.53 | 4.72 |
2019-01-04 | 2440.9066 | 9.22 | 23.85 | 16.01 | 2.66 | 5.06 | 7.50 | 3.80 | 4.18 | 3.22 | ... | 6.36 | 9.62 | 18.59 | 31.79 | 17.42 | 3.67 | 7.36 | 7.72 | 4.50 | 4.66 |
2019-01-07 | 2515.5083 | 9.63 | 24.99 | 16.46 | 2.76 | 5.28 | 7.93 | 3.92 | 4.41 | 3.32 | ... | 6.58 | 9.95 | 19.39 | 31.80 | 18.36 | 3.83 | 7.73 | 7.75 | 4.74 | 4.92 |
2019-01-08 | 2520.1648 | 9.62 | 24.63 | 16.80 | 2.82 | 5.31 | 7.82 | 4.03 | 4.44 | 3.35 | ... | 6.55 | 10.03 | 19.20 | 31.81 | 18.56 | 3.85 | 7.74 | 7.78 | 4.86 | 5.01 |
2019-01-09 | 2536.1570 | 9.70 | 25.11 | 16.72 | 2.84 | 5.34 | 7.80 | 4.06 | 4.46 | 3.36 | ... | 6.80 | 10.18 | 19.53 | 31.87 | 18.85 | 3.83 | 8.01 | 7.85 | 4.92 | 5.00 |
2019-01-10 | 2531.6638 | 9.86 | 25.03 | 16.66 | 2.84 | 5.29 | 7.77 | 4.00 | 4.41 | 3.36 | ... | 6.72 | 10.22 | 19.16 | 31.81 | 18.85 | 3.80 | 7.89 | 7.90 | 4.98 | 4.96 |
2019-01-11 | 2533.3586 | 10.05 | 25.01 | 16.49 | 2.91 | 5.30 | 7.63 | 3.98 | 4.40 | 3.34 | ... | 6.68 | 10.19 | 19.23 | 31.55 | 18.79 | 3.80 | 7.91 | 7.70 | 5.00 | 4.95 |
2019-01-14 | 2533.0101 | 10.07 | 24.92 | 16.49 | 2.97 | 5.28 | 6.97 | 4.00 | 4.44 | 3.52 | ... | 6.35 | 9.94 | 18.76 | 31.50 | 19.06 | 3.80 | 7.87 | 7.64 | 5.00 | 4.93 |
2019-01-15 | 2532.4333 | 10.09 | 24.32 | 16.40 | 3.04 | 5.23 | 7.05 | 3.98 | 4.44 | 3.47 | ... | 6.35 | 10.01 | 18.90 | 31.52 | 18.88 | 3.80 | 7.91 | 7.77 | 5.00 | 4.94 |
2019-01-16 | 2563.0061 | 10.23 | 24.83 | 16.55 | 2.96 | 5.31 | 7.07 | 4.00 | 4.43 | 3.51 | ... | 6.40 | 10.24 | 19.38 | 31.56 | 19.14 | 3.81 | 8.08 | 7.77 | 5.03 | 4.97 |
2019-01-17 | 2557.7114 | 10.17 | 24.94 | 16.40 | 2.95 | 5.25 | 6.77 | 3.95 | 4.37 | 3.42 | ... | 6.28 | 9.88 | 18.80 | 31.50 | 18.69 | 3.78 | 7.99 | 7.62 | 4.96 | 4.95 |
2019-01-18 | 2565.9043 | 10.28 | 24.99 | 16.44 | 2.95 | 5.24 | 6.56 | 3.80 | 4.33 | 3.27 | ... | 6.34 | 9.75 | 18.86 | 31.50 | 18.58 | 3.81 | 7.95 | 7.61 | 4.98 | 4.86 |
2019-01-21 | 2599.0575 | 10.32 | 25.40 | 16.42 | 2.96 | 5.33 | 6.72 | 3.89 | 4.40 | 3.31 | ... | 6.42 | 9.81 | 18.91 | 31.05 | 18.28 | 3.91 | 7.99 | 7.66 | 5.02 | 5.07 |
2019-01-22 | 2573.0617 | 10.26 | 25.23 | 16.28 | 2.92 | 5.25 | 6.70 | 3.89 | 4.25 | 3.34 | ... | 6.42 | 9.68 | 18.82 | 31.36 | 18.89 | 3.85 | 7.87 | 7.65 | 4.97 | 5.03 |
2019-01-23 | 2572.4054 | 10.29 | 25.20 | 16.20 | 2.97 | 5.23 | 6.62 | 3.86 | 4.26 | 3.31 | ... | 6.37 | 9.66 | 18.71 | 31.53 | 18.75 | 3.83 | 7.86 | 7.61 | 4.93 | 4.97 |
2019-01-24 | 2569.7004 | 10.37 | 24.93 | 16.22 | 2.90 | 5.20 | 6.45 | 3.84 | 4.28 | 3.28 | ... | 6.39 | 9.68 | 17.95 | 31.85 | 18.59 | 3.83 | 8.07 | 7.62 | 4.94 | 4.97 |
2019-01-25 | 2595.6294 | 10.55 | 25.49 | 16.27 | 2.91 | 5.25 | 6.20 | 3.85 | 4.28 | 3.25 | ... | 6.36 | 9.59 | 17.73 | 32.03 | 18.43 | 3.83 | 8.02 | 7.63 | 4.93 | 4.93 |
2019-01-28 | 2591.1000 | 10.88 | 25.86 | 16.01 | 2.90 | 5.20 | 5.61 | 3.85 | 4.22 | 3.24 | ... | 6.12 | 9.32 | 17.75 | 32.22 | 18.23 | 3.83 | 7.93 | 7.54 | 4.86 | 4.93 |
2019-01-29 | 2559.9820 | 10.77 | 25.87 | 15.00 | 2.78 | 5.10 | 5.05 | 3.80 | 4.08 | 3.02 | ... | 5.92 | 9.07 | 17.63 | 32.27 | 17.53 | 3.62 | 7.23 | 7.41 | 4.71 | 5.10 |
2019-01-30 | 2575.4091 | 10.86 | 26.63 | 15.03 | 2.80 | 5.12 | 4.61 | 3.82 | 4.12 | 2.82 | ... | 6.05 | 9.22 | 17.51 | 32.39 | 17.27 | 3.73 | 7.28 | 7.33 | 4.65 | 4.92 |
2019-01-31 | 2571.5789 | 10.94 | 27.00 | 14.05 | 2.82 | 5.11 | 4.75 | 3.50 | 4.02 | 2.85 | ... | 5.85 | 8.41 | 17.50 | 32.60 | 16.57 | 3.78 | 7.25 | 7.01 | 4.61 | 4.72 |
2019-02-01 | 2590.5543 | 10.96 | 26.98 | 14.70 | 2.85 | 5.17 | 4.88 | 3.65 | 4.08 | 2.91 | ... | 5.96 | 8.75 | 17.56 | 33.13 | 16.80 | 3.83 | 7.46 | 7.12 | 4.66 | 4.73 |
2019-02-11 | 2613.1742 | 10.97 | 26.89 | 14.85 | 2.97 | 5.25 | 5.12 | 3.61 | 4.26 | 3.04 | ... | 6.19 | 9.04 | 18.12 | 34.91 | 17.45 | 3.89 | 7.92 | 7.45 | 4.77 | 4.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]:
stock | startdate | enddate | T | |
---|---|---|---|---|
0 | 000001.SH | 20181109 | 20190211 | 1.00000 |
177 | 000598.SZ | 20181109 | 20190211 | 0.94000 |
3382 | 603588.SH | 20181109 | 20190211 | 0.93050 |
51 | 000066.SZ | 20181109 | 20190211 | 0.92375 |
144 | 000553.SZ | 20181109 | 20190211 | 0.92275 |
2499 | 600449.SH | 20181109 | 20190211 | 0.91825 |
1285 | 002833.SZ | 20181109 | 20190211 | 0.91250 |
2806 | 600801.SH | 20181109 | 20190211 | 0.91150 |
2993 | 601169.SH | 20181109 | 20190211 | 0.90825 |
2441 | 600367.SH | 20181109 | 20190211 | 0.90800 |
704 | 002240.SZ | 20181109 | 20190211 | 0.90800 |
1213 | 002756.SZ | 20181109 | 20190211 | 0.90750 |
592 | 002128.SZ | 20181109 | 20190211 | 0.90675 |
2903 | 600926.SH | 20181109 | 20190211 | 0.90550 |
700 | 002236.SZ | 20181109 | 20190211 | 0.90250 |
882 | 002419.SZ | 20181109 | 20190211 | 0.90175 |
192 | 000616.SZ | 20181109 | 20190211 | 0.90175 |
2641 | 600618.SH | 20181109 | 20190211 | 0.89975 |
3126 | 601996.SH | 20181109 | 20190211 | 0.89875 |
99 | 000488.SZ | 20181109 | 20190211 | 0.89700 |
542 | 002078.SZ | 20181109 | 20190211 | 0.89700 |
3018 | 601318.SH | 20181109 | 20190211 | 0.89650 |
1762 | 300376.SZ | 20181109 | 20190211 | 0.89625 |
2857 | 600859.SH | 20181109 | 20190211 | 0.89625 |
2951 | 601009.SH | 20181109 | 20190211 | 0.89550 |
211 | 000639.SZ | 20181109 | 20190211 | 0.89550 |
869 | 002406.SZ | 20181109 | 20190211 | 0.89450 |
2234 | 600123.SH | 20181109 | 20190211 | 0.89300 |
738 | 002275.SZ | 20181109 | 20190211 | 0.89275 |
838 | 002375.SZ | 20181109 | 20190211 | 0.89200 |
... | ... | ... | ... | ... |
2811 | 600807.SH | 20181109 | 20190211 | -0.56725 |
707 | 002243.SZ | 20181109 | 20190211 | -0.56775 |
1333 | 002885.SZ | 20181109 | 20190211 | -0.56900 |
3293 | 603322.SH | 20181109 | 20190211 | -0.58125 |
1223 | 002767.SZ | 20181109 | 20190211 | -0.58325 |
181 | 000603.SZ | 20181109 | 20190211 | -0.58875 |
2576 | 600547.SH | 20181109 | 20190211 | -0.59000 |
3194 | 603098.SH | 20181109 | 20190211 | -0.59300 |
1944 | 300560.SZ | 20181109 | 20190211 | -0.59350 |
1883 | 300497.SZ | 20181109 | 20190211 | -0.59400 |
29 | 000035.SZ | 20181109 | 20190211 | -0.60075 |
2127 | 300753.SZ | 20181109 | 20190211 | -0.60125 |
132 | 000539.SZ | 20181109 | 20190211 | -0.60200 |
909 | 002446.SZ | 20181109 | 20190211 | -0.60250 |
2577 | 600548.SH | 20181109 | 20190211 | -0.60575 |
2338 | 600242.SH | 20181109 | 20190211 | -0.60775 |
899 | 002436.SZ | 20181109 | 20190211 | -0.61050 |
1529 | 300140.SZ | 20181109 | 20190211 | -0.61400 |
1264 | 002811.SZ | 20181109 | 20190211 | -0.61625 |
2015 | 300635.SZ | 20181109 | 20190211 | -0.62075 |
2635 | 600612.SH | 20181109 | 20190211 | -0.62150 |
516 | 002052.SZ | 20181109 | 20190211 | -0.62925 |
1948 | 300565.SZ | 20181109 | 20190211 | -0.63600 |
3368 | 603558.SH | 20181109 | 20190211 | -0.64475 |
1815 | 300429.SZ | 20181109 | 20190211 | -0.66475 |
2527 | 600489.SH | 20181109 | 20190211 | -0.68400 |
2783 | 600775.SH | 20181109 | 20190211 | -0.70025 |
1054 | 002592.SZ | 20181109 | 20190211 | -0.70950 |
1693 | 300305.SZ | 20181109 | 20190211 | -0.71700 |
1371 | 002927.SZ | 20181109 | 20190211 | -0.73100 |
3586 rows × 4 columns
In [21]:
dt =dt.iloc[1:]
dt.describe()
Out[21]:
T | |
---|---|
count | 3585.000000 |
mean | 0.421866 |
std | 0.349293 |
min | -0.731000 |
25% | 0.240000 |
50% | 0.524750 |
75% | 0.682250 |
max | 0.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]:
min | max | 数量 | |
---|---|---|---|
0.8 | 0.8 | 1.0 | 282.0 |
0.6 | 0.6 | 0.8 | 1089.0 |
0.4 | 0.4 | 0.6 | 920.0 |
0.2 | 0.2 | 0.4 | 454.0 |
0.0 | 0.0 | 0.2 | 311.0 |
-0.2 | -0.2 | 0.0 | 232.0 |
-0.4 | -0.4 | -0.2 | 169.0 |
-0.6 | -0.6 | -0.4 | 96.0 |
-0.8 | -0.8 | -0.6 | 20.0 |
-1.0 | -1.0 | -0.8 | 0.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线在预测股价中的运用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!