Schedule Function Issue

72 views
Skip to first unread message

Steve Satterthwaite

unread,
Aug 6, 2017, 9:54:27 PM8/6/17
to Zipline Python Opensource Backtester
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

Ed Bartosh

unread,
Aug 7, 2017, 3:48:53 AM8/7/17
to Steve Satterthwaite, Zipline Python Opensource Backtester
Hi Steve,

You seem to use daily frequency. As for the time - could it be that it's reported in your local time zone?

Regards,
Ed

--
You received this message because you are subscribed to the Google Groups "Zipline Python Opensource Backtester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
BR,
Ed

Steve Satterthwaite

unread,
Aug 7, 2017, 11:11:15 AM8/7/17
to Zipline Python Opensource Backtester, ssattert...@gmail.com
Hi Ed, 

Thanks for the response. I tried changing to minute, only to get the error that the quandl bundle does not contain minute data. I saw your csvdir.py, is that the easiest way to get minute data bundles into Zipline?

Thanks, 

Steve
To unsubscribe from this group and stop receiving emails from it, send an email to zipline+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
BR,
Ed

Ed Bartosh

unread,
Aug 7, 2017, 12:59:39 PM8/7/17
to Steve Satterthwaite, Zipline Python Opensource Backtester
Hi Steve,

I saw your csvdir.py, is that the easiest way to get minute data bundles into Zipline?

It's hard to say if it's easiest or not. You can load minute data from csv files with it for sure.

BTW, I'm trying to upstream csvdir code. You can consider trying it from my pull request: https://github.com/quantopian/zipline/pull/1860/commits/6ef0ca0352e902211b64c681890e9373b3da137b

It should work with the latest zipline code from master branch.

Regards,
Ed



To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
BR,
Ed

Steve Satterthwaite

unread,
Aug 7, 2017, 4:56:40 PM8/7/17
to Zipline Python Opensource Backtester, ssattert...@gmail.com
Hi Ed, 

I installed csvdir and edited zipline/data/bundles/__init__.py, should I follow these instructions https://groups.google.com/forum/#!topic/zipline/GbnwZO-Gbn4 in order to get my CSV into a bundle?

Thanks so much for all your help, 

Steve

Ed Bartosh

unread,
Aug 7, 2017, 6:11:12 PM8/7/17
to Steve Satterthwaite, Zipline Python Opensource Backtester
Hi Steve,

Yes, you should follow those instructions.

Regards,
Ed

To unsubscribe from this group and stop receiving emails from it, send an email to zipline+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
BR,
Ed
Reply all
Reply to author
Forward
0 new messages