stock_list=get_all_securities(['stock']) #获取所有股票代码
stock_list = list(get_all_securities(['stock']).index)
#stock_list[1]
t2='09:30'
def get_count(t2):
t1=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
tt=t1[:11]+t2
d1 = datetime.datetime.strptime(t1[:16], '%Y-%m-%d %H:%M')
d2 = datetime.datetime.strptime(tt, '%Y-%m-%d %H:%M')
delta = (d1 - d2).seconds/60
count = round(delta)
if count>120 and count<210:
count=120
elif count>210 and count<330:
count=count-90
elif count>330:
count=329
return count
count=get_count(t2)
#获取当日最高价
df_today_h=history(count=count, unit='1m', field='high', security_list=stock_list, df=True, skip_paused=True, fq='pre').max()
#获取当日最低价
df_today_l=history(count=count, unit='1m', field='high', security_list=stock_list, df=True, skip_paused=True, fq='pre').min()
#当日开盘股票总数
to_num=len(df_today_h.index)
#当日开盘股票列表
stock_list_today=df_today_h.index.values
#获取前N日的最高价(不包括当前交易日)
df20_h=history(count=day_num, unit='1d', field='high', security_list=stock_list_today, df=True, skip_paused=False, fq='pre').max()
#获取前N日的最高价(不包括当前交易日)
df20_l=history(count=day_num, unit='1d', field='high', security_list=stock_list_today, df=True, skip_paused=False, fq='pre').min()
#
#创新高的股票
br_h_list=df_today_h[find(df_today_h>df20_h)]
br_h_num=len(br_h_list)
#创新低的股票
br_l_list=df_today_l[find(df_today_l<df20_l)]
br_l_num=len(br_l_list)
#br_h_num
#百分比
ratio_h=br_h_num/to_num*100
ratio_l=br_l_num/to_num*100
#ratio
labels_h=['总开盘股票数','创新高股票数']
labels_l=['总开盘股票数','创新低股票数']
X_h=[100-ratio_h,ratio_h]
X_l=[100-ratio_l,ratio_l]
fig = plt.figure()
plt.pie(X_h,labels=labels_h,autopct='%1.2f%%') #画饼图(数据,数据对应的标签,百分数保留两位小数点)
plt.title("创"+str(day_num)+"日新高百分比图")
plt.show()
fig = plt.figure()
plt.pie(X_l,labels=labels_l,autopct='%1.2f%%') #画饼图(数据,数据对应的标签,百分数保留两位小数点)
plt.title("创"+str(day_num)+"日新低百分比图")
plt.show()