Hi! Fairly new to viikate. I looked here but I couldn't find a similar error, so hopefully this is not a repeated thread. On my initialize function, I wrote this to calculate a percentage change. Just like in the API docs:
price_history=history(bar_count=30,frequency='1d', field='close_price') context.pct_change = price_history.iloc[[0, -1]].pct_change()
Then, on my before_trading_start function I'm trying to use it to calculate the percentage change on the stocks of a list of securities I've defined in initialize(). Like this:
for stock in context.stock_list: percent=context.pct_change[stock]
And when I run the algo, I get the following exception:
49 Error Runtime exception: KeyError: Security(21651, symbol='IYM', security_name='ISHARES U.S. BASIC MATERIALS E', exchange='NYSE ARCA EXCHANGE', start_date=Timestamp('2000-06-16 00:00:00+0000', tz='UTC'), end_date=Timestamp('2015-06-17 00:00:00+0000', tz='UTC'), first_traded=None)
Which really doesn't help me a lot in trying to figure out what I did wrong.
Any ideas? :)