import tushare as ts import pandas as pd #设定参数 start='2017-10-26 10:00:00' end='2017-10-26 10:30:00' zhenfudaxiao=0.01 def get_stock(start,end,zhenfudaxiao): #计算 result=[] #获取股票代码 daima2=pd.read_excel('C:/Users/Administrator/Desktop/daima2.xlsx') daima2.columns=['code_name'] symbols=['000001'] for i in range(len(daima2)): code=daima2.loc[i,'code_name'] if len(code)>0: symbols.append(code[7:13]) #获取数据 for stock in symbols[:100]: print('当前计算的股票为{}'.format(stock)) df=ts.get_hist_data(stock,ktype='5') #获取5分钟k线数据 #print(df) #计算振幅 try: data=df[end:start] highprice=data['high'].max() lowprice=data['low'].min() zhenfu=abs(highprice-lowprice)/lowprice if zhenfu<zhenfudaxiao: result.append(stock) except: pass print(result) return result zhenfu=get_stock(start,end,zhenfudaxiao)