# Backtesting - can you buy/sell at open and closing prices?

In backtesting (nasdaq stocks), I make the assumption that I have the ability buy/sell each day at the opening and closing prices. Is this realistic?

-
Yes, as realistic as bidding at an auction for a Picasso at 5 dollars. Good luck. –  Matt Wolf Jul 30 '13 at 5:49
As I mentioned here, you'll need to add a slippage. –  chrisaycock Jul 30 '13 at 10:15
its a race, first come first serve good luck! –  pyCthon Sep 22 '13 at 3:02

I do know of a largish prop shop that (as of 2009) had a deal with their prime broker to trade Nasdaq ETFs at the closing price, in size, so long as they gave a few hours' notice of order size and direction and never cancelled. After commissions and fees, the price was naturally worse.

Generally speaking, you have to assume slippage, as mentioned by chrisaycock, and most shops miss the trade with some regularity.

-
Does this mean that order types such as Market On Open(MOO) and Market On Close (MOC) orders also fail to get you a fill at opening price or closing price as claimed? –  Aziz Jul 30 '13 at 18:06
@Aziz A MOO or MOC just guarantees that you get the auction price; it doesn't guarantee what that price will be until after the auction is over. A big order, by necessity, will move the market even during the closing auction. The whole point of slippage is to account for market impact and transaction costs. –  chrisaycock Jul 30 '13 at 19:01
@chrisaycock On a side note, in researching slippage and how to incorporate it into backtesting, I come across descriptions such as "big orders" just like you have used it. In general, what qualifies an order as a "big order?" A certain dollar amount? –  Lee Schmidt Jul 30 '13 at 21:41
@LeeSchmidt Big enough to take-out the top-of-book quote. Once the exchange has to fill an order at the next price level, the price has become worse. That's what causes market impact. –  chrisaycock Jul 30 '13 at 22:31
@MattWolf I ran the other direction :-) they had done well for awhile on the "better lucky than skillful" plan. I had certain...concerns...about its stability. –  Brian B Aug 1 '13 at 15:49

@Chrisaycock , It should be noted that taking out the top order doesn't necessarily move the market by a non-negligible amount. For example, on a $150 stock, if there's an open sell order at \$150 X 1000 shares, and another at \$150.10 @ 5000 shares, you're not going to move the market much, and .10 / \$150.10 is less than 0.1% - negligible unless you're doing HFT.

@LeeSchmidt, I think a better indicator of a "big order" is the ratio of your order size relative to all the open orders that are relatively close in price to the NBBO. There's also a dark pool that you should consider, especially on large-cap stocks. The easiest way might be to look at volume vs. time (it's best if you can look at intraday volume vs. time but you could eyeball with daily volume). If the 30-minute volume is 10k, and you want to do even a 2k trade, you'll probably move the market. A \$500,000 trade on a company like AAPL won't make a dent in the price when it's average volume is 15 million shares / \$7 billion... but a \\$500k buy could easily cause a short spike in some penny stocks.

-

First of all you need to be clarify what you mean by 'opening/closing price' are you talking about the last tick? The opening/closing auction price?

Let's say you're talking about closing auction price within the context of a backtest. The big question here is are you computing your trading signal based on that same price? If you are then there's a major issue with this in you've essentially introduced lookahead bias. Remember in order to get the closing auction price for most US equities you have to send out a MOC 15 minutes before the close. Therefore you can't possibly have the closing print to compute on and achieve execution at that price.

Final tick maybe, but you'll have to include a pretty substantial slippage assumption.

-