Hi,
I am trying to create an algorithm that buys one share of apple when the market opens. I have the code :
from zipline.api import order, record, symbol, schedule_function, date_rules, time_rules, get_open_orders
def initialize(context):
context.capital = 100000
schedule_function(func=test, date_rule = date_rules.every_day(), time_rule = time_rules.market_open())
def test(context, data):
price = float(data.current(symbol('AAPL'), 'price'))
if not get_open_orders():
if context.capital > price:
order(symbol('AAPL'), 1)
record(AAPL=data.current(symbol('AAPL'), 'price'))
stop = float(data.current(symbol('AAPL'), 'price'))
context.capital -= stop
When i run the algorithm, all my trading occurs at "21:00:00", for example in the output =
2008-01-03 21:00:00+00:00 [{'commission': None, 'dt': 2008-01-03 21:00:0...
2008-01-04 21:00:00+00:00 [{'commission': None, 'dt': 2008-01-04 21:00:0...
2008-01-07 21:00:00+00:00 [{'commission': None, 'dt': 2008-01-07 21:00:0...
2008-01-08 21:00:00+00:00 [{'commission': None, 'dt': 2008-01-08 21:00:0...
When I run this in the quantopian environment, all the trades occur between 9:32-9:35.
Any help is appreciated,
Steve