Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Feature request: get_slippage

There should be a way for an algorithm to know the type and amount of slippage - something like get_slippage(sid), because in general the slippage will be different for different securities. This is necessary to estimate (since we can't know the price we'll end up paying) the number of shares we can afford with a given amount of cash. I have requested adding a function, get_commission, retrieving commission information, here. I haven't had time to think what behavior of such a function I would like.

Slippage models in the Quantopian API, and the set_slippage function, are discussed in the Quantopian help.

4 responses

Unfortunately, as documented the actual slippage depends on the volume of the next bar in the future so there would be look-ahead bias I think. But you could code your own rough predictor and use it to break up your order in to small lots. A starting point for an order volume that should have minimim slippage would be to get the volume traded over the last 30 minutes, calculate the average and then order say 5 to 10% of that volume. Repeat every bar until your order is filled. If you get filled at 10% of the volume on the next bar, your slippage in the classic Q model would be 0.1*(0.1)^2 = 0.001 = 0.1%; at 5% it would be 0.1*(0.05)^2=0.025% . (Not sure what Q's new slippage model would do though as the final version isnt on the api help page yet or I have missed it).

@Richard - Thank you. Your post actually goes further - suggests what to do to keep slippage under control.

I decided that, with the FixedSlippage model, I want get_slippage(sid) to return the half-spread (not the spread) for the security sid. Then I can simply add it to the most recent price data[sid].price to obtain an estimate of the net price I'm going to pay. Then the code to calculate and order as many shares of sid as cash allows becomes

cpt, cps=get_commission() # commission per trade, per share  
hs=get_slippage(sid) # half-spread, assuming the FixedSlippage model  
p=data[sid].price  
n=int((cash-cpt)/(p+hs+cps))  
if n>0:  
    order(sid, n)  

It would be nice if get_slippage(sid) returned something that could be added to the current price (or subtracted if I'm selling) to obtain an estimate of the actual transaction price, regardless of the slippage model used, even if user-defined. Can this be done? How?

André, I think Richard is giving excellent advice.

Slippage is, by definition, unpredictable. The slippage model that Quantopian uses by default is a decent estimation, but it is far from perfect. The real world will behave differently every time, and it cannot be predicted. You can't know in advance what other buyers and sellers will be in the market, what news is breaking, etc. Richard is suggesting a way to manage the risk of slippage. Managing the uncertainty of slippage is a viable strategy, but removing the uncertainty is not.

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.

@Dan - We know that the exact price we'll be charged for (each chunk of) our order cannot be known or calculated. But it can be treated as a random variable that follows some distribution, and estimated, ie. its expected value (or maximum, or the 95th percentile) found, can't it?

You seem to argue that the future is entirely unknowable. Do you watch weather forecasts? Do you factor them into your decisions? But the weather is more chaotic, and less predictable, than financial markets, isn't it?