20181022券商板块集体涨停,想看看历史上类似事件发生后对市场的影响
安装 pip install tushare
注册tushare获取接口TOKEN
import tushare as ts
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
import datetime
pro = ts.pro_api('your token')
#由于tushare单次调取最多取2800行记录, 因此从最近往前推2800天获取时间窗
end_date = '20181019'#20181022券商板块涨停
end_date_list = []
start_date_list = []
for i in range(1, 3):
end_date_list.append(end_date)
end_date = datetime.datetime.strptime(end_date, '%Y%m%d')
start_date = end_date - datetime.timedelta(2800*i)
end_date = start_date - datetime.timedelta(1)
end_date = end_date.strftime('%Y%m%d')
start_date = start_date.strftime('%Y%m%d')
start_date_list.append(start_date)
index_daily_qs = pd.DataFrame(columns = ['ts_code', 'trade_date', 'pct_change']) #券商指数
index_daily_sz = pd.DataFrame(columns = ['ts_code', 'trade_date', 'pct_change']) #上证指数
#取出每个时间窗内的历史指数
for i in range(len(end_date_list)):
index_daily_qs = index_daily_qs.append(pro.index_daily(ts_code='399975.SZ', start_date = start_date_list[i], end_date = end_date_list[i])[['ts_code', 'trade_date', 'pct_change']], ignore_index=True)
index_daily_sz = index_daily_sz.append(pro.index_daily(ts_code='000001.SH', start_date = start_date_list[i], end_date = end_date_list[i])[['ts_code', 'trade_date', 'pct_change']], ignore_index=True)
#获取券商板块历史涨停的日期
trade_date_zt = list(index_daily_qs[index_daily_qs['pct_change'] >= 9.9]['trade_date'])
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
#可视化券商每次涨停后上证指数一年内的表现
path = 'D:/BaiduNetdiskDownload/python/tushare'
for date in trade_date_zt:
# date = '20141205'
print(date)
index = index_daily_sz[index_daily_sz['trade_date'] > date]
index = index.sort_values(by = 'trade_date', ascending = True)
index['pct_change_cumsum'] = index['pct_change'].cumsum()
index_y = index.head(360)
index_y.plot(x = 'trade_date', y = 'pct_change_cumsum')
plt.title('上证指数' + date + '券商涨停后累计涨幅(一年)')
plt.savefig(path + '/' + date + '_year.jpg')
历史上券商涨停的日子不多
[‘20160321’,
‘20151104’,
‘20141205’,
‘20080922’,
‘20080919’,
‘20080820’,
‘20080425’,
‘20080424’]
券商涨停后对后市的影响不一致,要根据大盘当时具体情况来分析,这里看的是累计涨幅,后续有时间写上证指数的点位。