i've been banging my head against this for a while. i think that i am too python ignorant. my code is included at the end.
i have two issues -- first, how do i get the last trading bar of the day? it is not clear to me how to use the array to access it. i've tried data['price'][390] but that fails. i know that the price that i use in the main routine (firstPrice using [0] is not getting the eod of price).
on a narrower note, it fails in runtime in the batch_transform stating that no item named security 3766 exists.i know it is related to this line because it worked before i added it.
import datetime
import pytz
def initialize(context):
context.stocks = [sid(3766),sid(28368)]
context.IBM=sid(3766)
context.SLV = sid(28368)
utc = pytz.timezone('UTC')
context.d = datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=utc)
def handle_data(context, data):
prices = endpoints(data, context.stocks)
if prices is not None:
firstPrice = prices[context.IBM][0]
#curDate = data[context.IBM].datetime.replace(hour=21,minute=0,second=0,microsecond=0)
log.info('time : {t}, cur price {pc}, close price {p}'.format(t=data[context.IBM].datetime,pc=data[context.IBM].price,p=firstPrice))
#if data[context.GLD].datetime==curDate:
# log.info('hi')
#log.info('p3: {d} {p}'.format(d=data[sid(3766)].datetime,p=data[sid(3766)].price))
#log.info('end-of-day')
#cp = data[sid(3766)].close_price
#log.info('p3: {p}'.format(p=cp))
#ma = data[sid(3766)].mavg(1)
#log.info('p4: {p}'.format(p=ma))
@batch_transform(refresh_period=1, window_length=1)
def endpoints(data, stocks):
prices = data['price']
log.info('p1: {p} time {t}'.format(p=prices,t=data[sid(3766)].datetime))
return prices