Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to circumvent partial number of shares being filled?

In practice, sure, if I were to request for some large number of X, then all of it may not be filled.

But aside from the technicalities, I would just like to check the pure performance of my strategy (i.e. little to no slippage ...etc)

is there a way to circumvent "partial number of shares being filled?" cause it seems that the number of shares that were not filled by the end of day end up being canceled which can distort the the weights for target percentage and not represent the performance of the strategy in essence.

1 response

Yes, one can control how the backtest engine fills orders by specifying the slippage model. Take a look at the documentation https://www.quantopian.com/help#ide-slippage.

Specifically, if one wants to ensure orders are always 100% then put the following code in the 'initialize' routine.

set_slippage(FixedSlippage(spread = 0.0))

That will fill all orders in the first non-zero volume bar. Note this doesn't completely ensure an order will fill. If one trades low liquidity securities and places trades towards the end of the day, there may be a chance that there is no volume traded (it does happen a lot). In this case, an order will not fill.

A word of caution, Q has spent a lot of time analyzing real world order fill patterns. The default slippage model tracks reality pretty well (for large orders) and does try to represent the true expected strategy performance. When using custom slippage just make sure you understand the consequences. That said, it is often instructive to run a strategy with zero slippage and zero commision and compare it to the results when run with the defaults.

Good luck