python index out of bounds_python索引越界

尝试此代码:f2 = []

for i in symb_list:

f2.append(earnings_vola(i))

给出索引越界错误。符号列表示例:symb_list

Out[143]:

['MTMC',

'ANCI',

'TPLM',

'BERK',

'DGI',

'QLTY',

'GST',

'AGEN',

'NURO',

收益率浮动

升级版。抱歉,我是新用户。def earnings_vola (symbol):

price_b = marketdata.ext.load_metotron('%s'%symbol)

price = price_b.sort()

d = pickle.load(open('/home/mad/Appr/data_%s.pickle'%(symbol), 'rb'))

df = h.to_df(d)

if df['timetype'][2]=='After Close':

price['VOLA'] = (price.shift(-1)['C']-price['C'])/price['C']*100

else:

price['VOLA'] = (price['C']-price.shift(+1)['C'])/price['C']*100

x1 = pa.Series(sorted(df['Date_p']))

px = price.reindex(x1, method='ffill')

avg_vola = np.mean(px['VOLA'])

return avg_vola

上浮2> IndexError Traceback (most recent call

> last) in ()

> 1 f2 = []

> 2 for i in symb_list:

> ----> 3 f2.append(earnings_vola(i))

>

> in earnings_vola(symbol)

> 4 d = pickle.load(open('/home/mad/Appr/data_%s.pickle'%(symbol), 'rb'))

> 5 df = h.to_df(d)

> ----> 6 if df['timetype'][2]=='After Close':

> 7 price['VOLA'] = (price.shift(-1)['C']-price['C'])/price['C']*100

> 8 else:

>

> /usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in

> __getitem__(self, key)

> 616 def __getitem__(self, key):

> 617 try:

> --> 618 return self.index.get_value(self, key)

> 619 except InvalidIndexError:

> 620 pass

>

> /usr/local/lib/python2.7/dist-packages/pandas/core/index.pyc in

> get_value(self, series, key)

> 728

> 729 try:

> --> 730 return tslib.get_value_box(series, key)

> 731 except IndexError:

> 732 raise

>

> /usr/local/lib/python2.7/dist-packages/pandas/tslib.so in

> pandas.tslib.get_value_box (pandas/tslib.c:8534)()

>

> /usr/local/lib/python2.7/dist-packages/pandas/tslib.so in

> pandas.tslib.get_value_box (pandas/tslib.c:8378)()

>

> IndexError: index out of bounds

**向上3

结果收益(符号)函数示例:earnings_vola(symbol='MSFT')

0.080011249349832989**

我需要迭代符号列表(上面的例子)并得到列表中的所有结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值