OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

python index out of bounds error

  • Thread starter Thread starter Biggie Gv0
  • Start date Start date
B

Biggie Gv0

Guest
Tryind this code:

Code:
f2 = []
for i in symb_list: 
    f2.append(earnings_vola(i))

Gives the index out of bounds error. Sample of symb_list:

Code:
symb_list
Out[143]:
['MTMC',
 'ANCI',
 'TPLM',
 'BERK',
 'DGI',
 'QLTY',
 'GST',
 'AGEN',
 'NURO',

earnings_vola(i) returns float

UPD. Sorry, im new user here.

Code:
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

UPD2

Code:
> IndexError                                Traceback (most recent call
> last) <ipython-input-144-f3de6042c223> in <module>()
>       1 f2 = []
>       2 for i in symb_list:
> ----> 3     f2.append(earnings_vola(i))
> 
> <ipython-input-123-96f164ec1ad9> 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

**UPD3 Example of result earnings_vola(symbol) function:

Code:
earnings_vola(symbol='MSFT')
0.080011249349832989**

I need to iterate list of symbols (example above) and get all results in list
<p>Tryind this code:</p>

<pre><code>f2 = []
for i in symb_list:
f2.append(earnings_vola(i))
</code></pre>

<p>Gives the index out of bounds error. Sample of symb_list:</p>

<pre><code>symb_list
Out[143]:
['MTMC',
'ANCI',
'TPLM',
'BERK',
'DGI',
'QLTY',
'GST',
'AGEN',
'NURO',
</code></pre>

<p>earnings_vola(i) returns float</p>

<p>UPD. Sorry, im new user here. </p>

<pre><code>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
</code></pre>

<p>UPD2</p>

<pre><code>> IndexError Traceback (most recent call
> last) <ipython-input-144-f3de6042c223> in <module>()
> 1 f2 = []
> 2 for i in symb_list:
> ----> 3 f2.append(earnings_vola(i))
>
> <ipython-input-123-96f164ec1ad9> 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
</code></pre>

<p>**UPD3
Example of result earnings_vola(symbol) function:</p>

<pre><code>earnings_vola(symbol='MSFT')
0.080011249349832989**
</code></pre>

<p>I need to iterate list of symbols (example above) and get all results in list</p>
 

Latest posts

J
Replies
0
Views
1
jbowerbir
J
Top