# 该Python代码用于模块定义,供其他Python代码或VBA调用。
from PythonApi import *
begin_date = '20210729' #计算的时间周期
end_date = '20210826'
index_num = 'sh000001'
name_num = get_blocks('自选股',1)
#求指数涨跌幅
index_close = history_bars_date(index_num,begin_date,end_date,'1d','close') # 把股票代码传到这个函数中得到区间每天的收盘价
num1 = (round(index_close[-1],2) - round(index_close[0],2))/ round(index_close[0],2) * 100 # 大盘的涨跌幅
index_num1 = round(num1,2)
for i in name_num: #遍历自选股中的每个股的股票代码
close_star = history_bars_date(i,begin_date,begin_date,'1d','close') #把股票代码传到这个函数中得到区间每天的收盘价
close_end = history_bars_date(i,end_date,end_date,'1d','close')
num = ((round(close_end[0],2) - round(close_star[0],2))/ round(close_star[0],2)) * 100#
if num > index_num:
print(i)
else:
pass
> 开始编译 <jzt_MyPython5> ......
>
> 编译错误 : IndexError
> line : 11
> 错误信息 : index -1 is out of bounds for axis 0 with size 0
我改了错误的地方,还是报错~~~~~~