Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
when are interday orders executed?

since the price shown in interday testing is the market closing price, does that mean orders are filled at the start of the next trading day?

if so, it seems like no one should use interday for simulation testing, as it will add a great deal of price randomization due to the gap in time.

3 responses

Hello Jason,

When running a backtest on daily bars, there is a one trading day delay between order submission and order fulfillment (assuming the slippage model is turned off, and the stock trades frequently). Anony Mole developed a work-around (see https://www.quantopian.com/posts/trade-at-the-open-slippage-model and some of his subsequent posts).

Frankly, if you have decent programming experience and a feel for trading, I'd just jump into writing algorithms for minute bars, with the caveat that backtests will take longer to run. I saw your post on your sketchy internet connection, and so this might be problematic. I suggest sending a note directly to Quantopian support, since it is my impression that the algorithm runs remotely and is just reporting the results to the browser.

Grant

thanks Grant, yeah i'm trying a stochastic algo right now and it looks like it's trading 1 day late. thanks for confirming.

from looking at that slipage model you posted, here is my hack to allow trading at the preceeding close:

class OrderAtTodaysClose:  
    '''  
    wrapper for ordering, lets the TradeAtTodaysCloseSlippageModel know what today's price was.  
    '''  
    def __init__(this):  
        this.closePrices = {}  
    def order_target_percent(this,data,sid,percent, limitPrice=None, stopPrice=None):  
        this.closePrices[sid]=data[sid].close_price  
        return order_target_percent(sid,percent,limitPrice,stopPrice)  
global orderAtTodaysClose  
orderAtTodaysClose = OrderAtTodaysClose()

class TradeAtTodaysCloseSlippageModel(slippage.SlippageModel):  
    ''' simulate selling immediatly at the close (hack to let interday pretend to be intraday)  
    YOU MUST USE OrderAtTodaysClose.order_target_percent() for this to take effect.  
    '''  
    def __init__(self):  
        pass

    def process_order(self, trade_bar, order):          

        #doesn't work with daily  
        #price_history = history(bar_count=2, frequency='1d', field='price')  
        #price = price_history[trade_bar.sid][-2]

        return slippage.create_transaction(  
            trade_bar,  
            order,  
            orderAtTodaysClose.closePrices[trade_bar.sid],  
            order.amount  
        )  

here's an update with some minor bugfixes:

Please note that you need to use the OrderAtTodaysClose.order_target_percent() method otherwise the price will be the opening of the following day.

class OrderAtTodaysClose:  
    '''  
    wrapper for ordering, lets the TradeAtTodaysCloseSlippageModel know what today's price was.  
    '''  
    def __init__(this):  
        this.closePrices = {}  
    def order_target_percent(this,data,sid,percent, limitPrice=None, stopPrice=None):  
        this.closePrices[sid]=data[sid].close_price  
        return order_target_percent(sid,percent,limitPrice,stopPrice)  
global orderAtTodaysClose  
orderAtTodaysClose = OrderAtTodaysClose()

class TradeAtTodaysCloseSlippageModel(slippage.SlippageModel):  
    ''' simulate selling immediatly at the close (hack to let interday pretend to be intraday)  
    YOU MUST USE OrderAtTodaysClose.order_target_percent() for this to take effect.  if not, we use the opening price for the following timeslice  
    '''  
    def __init__(self):  
        pass

    def process_order(self, trade_bar, order):          

        #doesn't work with daily  
        #price_history = history(bar_count=2, frequency='1d', field='price')  
        #price = price_history[trade_bar.sid][-2]  
        if orderAtTodaysClose.closePrices.has_key(trade_bar.sid):  
            price = orderAtTodaysClose.closePrices[trade_bar.sid]  
        else:  
            price = trade_bar.open_price

        return slippage.create_transaction(  
            trade_bar,  
            order,  
            price,  
            order.amount  
        )