How do you emulate slippage in a backtest?

Discussion in 'Automated Trading' started by jcl, Aug 21, 2012.

  1. jcl

    jcl

    Slippage is normally irrelevant, but can remarkably affect the result when you trade on short time frames, such as minutes or ticks. So far I used the following formula for calculating slippage when entering a trade at the open:

    P = S/T * (C-O)

    where P = price change due to slippage, S = slippage in seconds, T = bar width in seconds, C = close and O = open.

    This is the theoretical average slippage under the assumption of a honest broker, but I found that this generates usually too small slippage. Therefore I'm now using the following formula:

    P = S/T * (L-O) when C < O
    P = S/T * (H-O) otherwise

    This seems to give more realistic results. Which slippage formula do you use?
     
  2. you make the erroneous assumption that slippage is a function of future price moves during the time taken to get your order to market.

    However, how you get filled, in practice, is much more a function of market intrinsics unless of course it takes an unreasonable amount of time for your order to get filled during which the market may have moved against you.

    What I would do is to build a Transaction Cost Model, which you feed with historical slippage. This, imho will by far get you the most accurate figures. If you dont have the luxury to build such model then make very liberal assumptions about how you get filled especially if you trade with shady brokers or trade over a very slow connection.


     
  3. The best and most reliable way to apply what is essentially an educated guess is to run a live strategy and then run the live strategy through your simulator and compare the real trading results against your simulated results. Come up with an overall correction factor so that your backtest results are very realistic.

    Guessing about slippage is almost impossible because you have to make too many assumptions. You need good data so that you can see what executed and at what price. Even then you can't assume that an execution would have been yours - it's always best to go a penny up/down from your target price. If you are trying to sell 1000 shares offered at $10.61 assume you get a fill when you see more than 1000 shares print at $10.62. That extra penny may be too pessimistic for some strategies but the reality is that if you have decent backtest results even with adding an extra penny on the entry and exit then you probably won't get a surprise when you put real money behind it.

    If you are estimating slippage because you are using market orders - don't ever use market orders. Always submit marketable limit orders (meaning pay through the bid/offer). A marketable limit order always avoids slippage and guarantees fast execution as well as price improvement up to the NBBO.
     
  4. jcl

    jcl

    Thanks, that makes sense. It is probably futile to apply a slippage formula. I run systems anyway in parallel on a life and on a demo account, so I record the slippage under that assumption that a demo account has no slippage.

    So far slippage seems to depend on the quote rate and some random factor. The best solution is probably just some empiric value dependent on the asset and the trading time.
     
  5. To get accurate slippage you need to simulate the order book. That is almost impossible because of so many unknowns, as well as how/when/why the MMs will give you a price vs when they won't participate. In many of my strategies I have to use stop orders (for entries) which convert to Market (obviously) and in my experience it's best to have some tick data (not much, but some) from which you can estimate the slippage others were getting. It's a good enough approximation if you look at the Last ticks and then compare to Bid/Ask ticks, you can soon narrow down the standard deviation of slippage, and the best part comes when you link the StdDev to volatility. That way you get a model that's "accurate enough", ie transaction costs model of sorts like amazingIndustry mentioned. It won't be perfect but it's something. You should, in any case, leave room on your backtester to make slippage pessimistic. If you can't afford to do this, assume some distribution of slippage vs volatility (it is close to normal in my experience) and use random numbers to generate slippage.

    This of course only for Market (and Stop) orders, for limit, you just get filled when the price penetrates your level by a tick, but if you are using odd lots for orders (stocks) then you might not get filled on low liquidity stocks if the other side is looking for all-or-none (or avoids odd lots). So... liquidity is an issue with simulating limit orders so you may want some assumptions there as well, if you want to be very close to perfect.
     
  6. I daytrade stocks and enter at market. For simulations I use data from (a lot of) previous live trades. Slippage is a big deal for me, so I need to simulate it properly or I'll be wasting my time.

    The two factors that influence it the most are time of day - slippage is higher closer to the open - and liquidity of the stock in question. The best way I have found of measuring liquidity for this purpose is to multiply the average share volume of the past 20 days by last close. Higher liquidity gives lower slippage, no surprises there.

    So in practice I end up with an overall average slippage, and for each individual simulated position opened that average is adjusted according to time of trade and liquidity of stock traded. If the position is stopped out I need to add in slippage again, with the time of closure being the only change. For profitable trades I use limits and simulate a close if price penetrates my level. As braincell noted that may be a little optimistic, but I'll allow myself that indulgence.

    If anyone is interested I can post up some examples.
     
  7. dom993

    dom993

    In general terms, average slippage is equal to the bid-ask spread ... on any particular trade, the slippage will impacted by the bid-ask spread at the time of the order execution and your order size vs the offered/requested size. The real unknown is where the bid-ask will be at the time of your order execution, since it is a factor of the time it takes for your order to hit the exchange and whatever other orders hit the exchange in-between. On on average over many trades, these bid-ask spread moves away from your reference point should add-up to zero, so if you are trading small enough vs the average offerered/requested size you average slippage should be the average bid-ask spread (which you could track as a function of time-of-day, to get realistic figures overnight & during lunch hours).

    In the case of futures, this is pretty-much it ... in the case of stocks, how your orders are routed will also impact slippage, and for spot forex your broker will most likely screw you by a few pips on every-fill, above & beyond the bid-ask spread, but this can also be monitored & taken into account.
     
  8. jb514

    jb514

    Take the size of your order. Small orders will be simpler. Look at the depth of book and compare to what kind of order you are sending. If you are buying 1000 at market of ARCA with a proactive order, first you will buy the displayed size at the nbbo, then your order will go through the arca book. Depending on the size of your order, or the liquidity of the instrument, your order may just skim the top of book, or go deeper into the book. The last factor which is fairly important is the latency. So for testing, if you get an entry signal, remember that you cannot look at the book to determine your fill price until x, hopefully milliseconds have occured.
     
  9. profit = proft * 0.7


    :D


    How could u ever simulate a slippage when the price and time taken for you to send a signal to the time and price it is traded is unknown ??
     
  10. a5519

    a5519

     
    #10     Sep 1, 2012