Hello,
I'm trying to compute the 1 period simple return, but I'm getting the following error:
15 Error Runtime exception: IndexError: index 27796 is out of bounds for axis 0 with size 10
Any ideas on what I'm doing wrong? Thank you in advance.
Here is the code:
import numpy as np
def initialize(context):
# http://money.usnews.com/funds/etfs/rankings/small-cap-funds
context.stocks = [sid(27796),sid(33412),sid(38902),sid(21508),sid(39458),sid(25899),sid(40143),sid(21519),sid(39143),sid(26449)]
context.m = len(context.stocks)
def handle_data(context, data):
loss = np.zeros(context.m)
price_history = history(bar_count=2, frequency='1d', field='price')
for s in context.stocks:
prev_bar = price_history[s][-2]
curr_bar = price_history[s][-1]
loss[s] = curr_bar/prev_bar - 1