Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
New Order Types! (And Backtester Changes)

This afternoon we pushed a number of changes to the website. The changes are as previously discussed with one exception: the benchmark fix ended up having a bigger impact than we expected. Everyone's algorithms suddenly look better than they used to because the benchmark looks worse. We of course apologize for the error, and we're sorry about any hassle the changes have caused.

Now the good news. Order types! We now have limit orders, stop orders, and stop limit orders. The explanation on how the orders are used is in two sections of our help doc. General description is here, and more technical details are here. We're not quite done with the super-cool autocomplete and tool tips in the IDE, so you have to type them out the old fashioned way for the next day until we ship the tool tips.

For now, you can probably learn most of what you need to know from the example below. The sample code rotates through the order types, over and over. Clone it, and run a full backtest on it (don't just build it, also run the full test to get the full picture). Look at the Transactions graph - you'll see a huge spike in October 2008. That's because all of the limits and stops triggered when the price crashed - a flood of orders became active.

Now click the Transactions Detail tab. You see that in early going only the market orders get processed at 5 shares each. Page through the transactions to October, and you see the limits and stops getting processed at 10 and 15. It's not until they are all processed that you see the first stop-limit of 20 shares - that's because all of the previous stop-limits had been cancelled by the rotator! I know that sounds a bit confusing, but if you step through the code, I think it will all make sense.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

8 responses

We'd also like to extend a special thanks to Tony Worm (https://github.com/verdverm) for his contributions to Zipline that helped define and implement the underpinnings of the orders interface. (https://github.com/quantopian/zipline/commit/086679c3d69271c9012772dc62f25acf4ea2662a)

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi, regarding limit orders are they executed when prices touch our limit or when prices go through our limit ?

Thanks

Hello Quentin,

They execute when the limit is touched:

2008-01-24 PRINT Price of AAPL is 135.53  
2008-01-24 PRINT Event({'status': 0, 'created': datetime.datetime(2008, 1, 24, 0, 0, tzinfo=<UTC>),  
    'limit_reached': False, 'stop': None, 'stop_reached': False, 'amount': 10, 'limit': 129.98, 'sid': 24,  
    'dt': datetime.datetime(2008, 1, 24, 0, 0, tzinfo=<UTC>), 'id': '8c4776ad5197413082e3fd5b2cc8eb71', 'filled': 0})

2008-01-25 PRINT Price of AAPL is 129.98  
2008-01-25 PRINT Event({'status': 1, 'created': datetime.datetime(2008, 1, 24, 0, 0, tzinfo=<UTC>),  
    'limit_reached': True, 'stop': None, 'stop_reached': False, 'amount': 10, 'limit': 129.98, 'sid': 24,  
    'dt': datetime.datetime(2008, 1, 25, 0, 0, tzinfo=<UTC>), 'id': '8c4776ad5197413082e3fd5b2cc8eb71', 'filled': 10})  

Regards,

Peter

Hi Peter,
Did you Check the high and low of the bar from which you print PRICE ?
I would expect to be executed if either of ohc ( resp olc) is STRICTLY above ( resp lower than) my limit sell ( resp buy ) order .

I agree with Quentin. The ideal behaviour for Daily mode is to check all OHLC prices against stops and limits to trigger the order.

However for the slippage model perhaps use the close price to fulfill the order.

Hello All,

I think my example with daily data was a bit meaningless. With minute data we get:

2008-01-23PRINT 2008-01-23 16:47:00+00:00  
2008-01-23PRINT O is 130.47  
2008-01-23PRINT H is 130.48  
2008-01-23PRINT L is 130.05  
2008-01-23PRINT C is 130.09  
2008-01-23PRINTEvent({'status': 0, 'created': datetime.datetime(2008, 1, 22, 14, 31, tzinfo=<UTC>),  
    'limit_reached': False, 'stop': None, 'stop_reached': False, 'amount': 10, 'limit': 129.98, 'sid': 24,  
    'dt': datetime.datetime(2008, 1, 22, 14, 31, tzinfo=<UTC>), 'id': 'aa9cd460d08949f3a08aacad1c56fe7b', 'filled': 0})

2008-01-23PRINT 2008-01-23 16:48:00+00:00  
2008-01-23PRINT O is 130.068  
2008-01-23PRINT H is 130.09  
2008-01-23PRINT L is 129.42  
2008-01-23PRINT C is 129.58  
2008-01-23PRINTEvent({'status': 1, 'created': datetime.datetime(2008, 1, 22, 14, 31, tzinfo=<UTC>),  
    'limit_reached': True, 'stop': None, 'stop_reached': False, 'amount': 10, 'limit': 129.98, 'sid': 24,  
    'dt': datetime.datetime(2008, 1, 23, 16, 48, tzinfo=<UTC>), 'id': 'aa9cd460d08949f3a08aacad1c56fe7b', 'filled': 10})  

and

Transactions List  
1 - 1 of 1  
2008-01-23 16:48:00     AAPL    BUY     10  $129.61     $1,296.10  

Regards,

Peter

Hi Peter,
Thanks for more detail. Still it raises more questions than answers.
How did ou get executed t 129.61 when your limit was 129.98.
Still doesn't clear up if a limit order is executed on touch or on cross.
The question is basically on the last bar you published would a buy @ 129.42 be executed or not.
What about 129.43

Regards,
Q.

Hello All,

Setting the limit to 129.42 or 129.43 both give the same result - a fill at 17:00 the same day.

2008-01-23PRINT 2008-01-23 16:59:00+00:00  
2008-01-23PRINT O is 130.27  
2008-01-23PRINT H is 130.3  
2008-01-23PRINT L is 129.66  
2008-01-23PRINT C is 129.66  
2008-01-23PRINTEvent({'status': 0, 'created': datetime.datetime(2008, 1, 22, 14, 31, tzinfo=<UTC>),  
    'limit_reached': False, 'stop': None, 'stop_reached': False, 'amount': 10, 'limit': 129.42, 'sid': 24,  
    'dt': datetime.datetime(2008, 1, 22, 14, 31, tzinfo=<UTC>), 'id': '0c9bb37d23b9417aad0beda48cc37cd0', 'filled': 0})

2008-01-23PRINT 2008-01-23 17:00:00+00:00  
2008-01-23PRINT O is 129.65  
2008-01-23PRINT H is 129.77  
2008-01-23PRINT L is 129.15  
2008-01-23PRINT C is 129.3  
2008-01-23PRINTEvent({'status': 1, 'created': datetime.datetime(2008, 1, 22, 14, 31, tzinfo=<UTC>),  
    'limit_reached': True, 'stop': None, 'stop_reached': False, 'amount': 10, 'limit': 129.42, 'sid': 24,  
    'dt': datetime.datetime(2008, 1, 23, 17, 0, tzinfo=<UTC>), 'id': '0c9bb37d23b9417aad0beda48cc37cd0', 'filled': 10})

and

Transactions List  
1 - 1 of 1  
2008-01-23 17:00:00     AAPL    BUY     10  $129.33     $1,293.30  

I'll get me coat. *

Regards,

Peter

* http://www.youtube.com/watch?v=lfJAHASV8k8