Looking at class
VolumeShareSlippage(SlippageModel)
on https://github.com/quantopian/zipline/blob/master/zipline/finance/slippage.py, the comments and code suggest that this case should be handled:
if order.limit:
# this is tricky! if an order with a limit price has reached
# the limit price, we will try to fill the order. do not fill
# these shares if the impacted price is worse than the limit
# price. return early to avoid creating the transaction.
# buy order is worse if the impacted price is greater than
# the limit price. sell order is worse if the impacted price
# is less than the limit price
if (order.direction > 0 and impacted_price > order.limit) or \
(order.direction < 0 and impacted_price < order.limit):
return
This would seem to do the trick, no? It just skips processing the transaction if the limit order conditions are not met, using a hypothetical price if the order were to go through.
Interestingly, the code under FixedSlippage(SlippageModel)
does not appear to handle limit orders in the same fashion--it has no awareness of the order type, and would transact all orders with slippage applied to the price.
Either way, unless we're talking about a contest entry here (for which the default slippage must be used), wouldn't it be possible simply to write a custom slippage model so that the desired execution of limit orders is effected?