Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Testing Market Stop - Stop Filling on Low Ficticious Price - AAPL

I'm new to the Q environment and have been testing the order object methods. First, is there a current complete API reference? For example, one of the order object methods described is direction to show whether the order direction was long or short. When I tried to access that method, the IDE said that it wasn't an available order object method.

On the subject of the market stop, I placed a single AAPL test paper trade on 1/2/15 that showed that it filled 2600 shares, no fill price indicated, at 1434 UTC. A market stop placed at the same time indicated that it immediately filled at half the price. The low price on 1/2/15 was approximately $107.35, while the stop reported a fill price at 1434 on 1/2/15 of $55.65, when the low price at 1434 as $111.14. I've copied the code snippet and printout of order object info for both the order and the stop.

What is going on?

Thanks

    if c.buy_once == False :  
        shares = int((300000 / Close[0])/100) * 100  
        c.order_id = order(symbol('AAPL'), shares)  
        c.stop_id = order(symbol('AAPL'), shares, style=StopOrder(0.50*Close[0]))  
        c.order_info = get_order(c.order_id)  
        c.stop_info = get_order(c.stop_id)  
        c.buy_once = True  

    c.order_info = get_order(c.order_id)  
    c.stop_info = get_order(c.stop_id)  
    print("order_info ",c.order_info )  
    print("stop_info ",c.stop_info )

2015-01-05PRINT('order_info ', Event({'status': 1, 'limit_reached': False, 'created': Timestamp('2015-01-02 14:33:00+0000', tz='UTC'), 'stop': None, 'reason': None, 'stop_reached': False, 'commission': 6.5, 'amount': 2600, 'limit': None, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2015, 2, 2, 0, 0, tzinfo=), first_traded=None), 'id': '20e39da584e14f01ad4a1aa037afec06', 'dt': Timestamp('2015-01-02 14:34:00+0000', tz='UTC'), 'filled': 2600}))
2015-01-05PRINT('stop_info ', Event({'status': 1, 'limit_reached': False, 'created': Timestamp('2015-01-02 14:33:00+0000', tz='UTC'), 'stop': 55.65, 'reason': None, 'stop_reached': True, 'commission': 6.5, 'amount': 2600, 'limit': None, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2015, 2, 2, 0, 0, tzinfo=), first_traded=None), 'id': '20e2176116e644c9b8f8d0cc4304b21c', 'dt': Timestamp('2015-01-02 14:34:00+0000', tz='UTC'), 'filled': 2600}))

2 responses

I think you'd have to check the zipline source to find out why a stop fills at the stop price rather than the market price, but it looks like you were trying to do stop-buy, which if the stop price is below the current price, arguably ought to execute immediately (though I would have thought as a market order). If you want a stop-loss, I believe shares ought to be negative, implying a stop-sell.

Aah, the general purpose container strikes again! Sorry, my mistake, good find! I'll be more careful to ensure proper application of the negative sign!