class qf_lib.backtesting.execution_handler.slippage.base.Slippage(data_provider: qf_lib.data_providers.data_provider.DataProvider, max_volume_share_limit: Optional[float] = None)[source]

Bases: object

Base class for slippage models. It can limit the Order’s volume. This model needs to know the daily volume of the traded asset, thus it uses the data provider in order to be able to access the volume value for the day.

  • data_provider (DataProvider) – DataProvider component

  • max_volume_share_limit (float, None) – number from range [0,1] which denotes how big (volume-wise) the Order can be i.e. if it’s 0.5 and a daily volume for a given asset is 1,000,000 USD, then max volume of the Order can be 500,000 USD. If not provided, no volume checks are performed.


process_orders(date, orders, …)

Calculates fill prices and quantities for Orders.

process_orders(date: datetime.datetime, orders: Sequence[qf_lib.backtesting.order.order.Order], no_slippage_fill_prices: Sequence[float]) → Tuple[Sequence[float], Sequence[float]][source]

Calculates fill prices and quantities for Orders. For Orders that can’t be executed (missing security price, etc.) float(“nan”) will be returned.

  • date (datetime) – time when the slippage is applied

  • orders (Sequence[Order]) – sequence of Orders for which the fill price should be calculated

  • no_slippage_fill_prices (Sequence[float]) – fill prices without a slippage applied. Each fill price corresponds to the Order from orders list


sequence of fill prices (order corresponds to the order of orders provided as an argument of the method), sequence of fill order quantities

Return type

Tuple[Sequence[float], Sequence[float]]