Slippage

Key Concepts

Introduction

Slippage is the difference between the fill price you expect to get for an order and the actual fill price. Since the price can move in the direction of your trade or against the direction of your trade while you wait for the order to fill, slippage can be positive or negative. Slippage models model slippage to make backtest results more realistic.

Factors Impacting Slippage

There are many factors that can impact slippage, including the trading engine, brokerage connection, and market dynamics.

Trading Engine

How long does it take from when you place an order to when it's sent to the brokerage? Longer delays lead to more slippage.

Brokerage Connection

How long does it take for your brokerage to receive an order that you send? Slow internet connections, long travel distances, and poor infrastructure lead to more slippage

Market Dynamics

How volatile is the current market environment? More volatility leads to more slippage.

Does the market consist of sophisticated microsecond arbitrageurs? If your order creates an arbitrage opportunity, it can cause more slippage.

Set Models

The brokerage model of your algorithm automatically sets the slippage model for each security, but you can override it. To manually set the slippage model of a security, call the SetSlippageModel method on the Security object.

// In Initialize
var security = AddEquity("SPY");
security.SetSlippageModel(new VolumeShareSlippageModel());
# In Initialize
security = self.AddEquity("SPY")
security.SetSlippageModel(VolumeShareSlippageModel())

You can also set the slippage model in a security initializer. If your algorithm has a dynamic universe, use the security initializer technique. In order to initialize single security subscriptions with the security initializer, call SetSecurityInitializer before you create the subscriptions.

// In Initialize
SetSecurityInitializer(CustomSecurityInitializer);
AddEquity("SPY");

private void CustomSecurityInitializer(Security security)
{
    security.SetSlippageModel(new VolumeShareSlippageModel());
}
# In Initialize
self.SetSecurityInitializer(self.CustomSecurityInitializer)
self.AddEquity("SPY")

def CustomSecurityInitializer(self, security: Security) -> None:
    security.SetSlippageModel(VolumeShareSlippageModel())

To view all the pre-built slippage models, see Supported Models.

Default Behavior

The brokerage model of your algorithm automatically sets the slippage model of each security. The default brokerage model is the DefaultBrokerageModel, which uses the ConstantSlippageModel to model zero slippage for all securities.

Model Structure

Slippage models should implement the ISlippageModel interface. Extensions of the ISlippageModel interface must implement the GetSlippageApproximation method, which calculates the slippage quantity.

public class MySlippageModel : ISlippageModel 
{
    public decimal GetSlippageApproximation(Security asset, Order order) 
    {
        return asset.Price*0.0001m*(decimal) Math.Log10(2*(double) order.AbsoluteQuantity);
    }
}
class MySlippageModel:

    def GetSlippageApproximation(self, asset: Security, order: Order) -> float:
        return asset.Price * 0.0001 * np.log10(2*float(order.AbsoluteQuantity))

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: