Hi, I've tried to run a simple test algo in the Research notebook with Zipline but I have an error if I run it with 1 minute data.
Conversely, it works fine with daily data.
Here is the original test algo in IDE that works fine with minute data:
from datetime import datetime
TIME_FMT = '%H:%M:%S'
def initialize(context):
context.spy = symbol('SPY')
context.order_id = None
context.shares = 414 # number of shares to buy
init_order(context)
schedule_function(place_buy, date_rules.every_day(), time_rules.market_open())
set_slippage(slippage.VolumeShareSlippage(volume_limit=1e-5, price_impact=0))
def handle_data(context, data):
update_order(context, context.order_id)
def place_buy(context, data):
# CALLED TO PLACE AN ORDER
init_order(context)
context.order_id = order(context.spy,context.shares)
def init_order(context):
'''
Must be called only once in initialize
'''
context.bar_count = 0
context.has_filled = False
context.prev_status = -1
def update_order(context, order_id):
'''
Keeps track of order's status change, and number of bars needed to completely fill the order
'''
context.bar_count += 1
if order_id <> None:
ordr = get_order(context.order_id)
context.filled_shares = ordr.filled
if context.prev_status <> ordr.status:
# KEEP TRACK OF ORDER STATUS CHANGE
print("----------------------------------------------------")
print("Order status change: %i at %s" % (ordr.status, datetime.strftime(ordr.dt, TIME_FMT))) # 0 = open order, 1 = Filled
if ordr.status == 2:
# the order has been canceled
position = context.portfolio.positions[ordr.sid]
print("Only %i shares filled! VWAP: %f at %s" %
(position['amount'], position['cost_basis'], datetime.strftime(position['last_sale_date'], TIME_FMT)))
if ordr.filled==context.shares:
# FILLED IS THE CUMULATIVE # OF SHARES FILLED
if not context.has_filled:
position = context.portfolio.positions[ordr.sid]
print ("Shares filled: %i, at %s" % (ordr.filled, datetime.strftime(ordr.dt, TIME_FMT))) # cumulative number of shares filled
print("Bars needed to fill: %i, VWAP is: %f" % (context.bar_count, position['cost_basis']))
context.has_filled = True
context.prev_status = ordr.status
Running the code as shown above in a Research notebook, rise the following error:
KeyError: 'the label [2007-01-04 00:00:00+00:00] is not in the [index]'
it seems something wrong with Zipline.