Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Discrepancy between transaction unit price in back test and and output of data.current(stock, price)?

There is a discrepancy between the output I get in my log when printing data.current(stock, price) and the transaction unit cost shown in the back test. I was considering it may be transactions costs but sometimes the transaction unit cost is greater than the data.current(stock,price) and other times it is less than data.current(stock,price).

What is the reason for this discrepancy?

1 response

A couple of things.

First, the algo logs and records the 'current' price as of when the orders are placed. However, this price is actually the previous minute bar close (the most current data the algorithm has access to). However, the orders are then filled at the end of the current bar with prices based upon the current bar close. This price may be different from the previous price which was logged.

Second, unless a different slippage model is specified, the default slippage will fill orders at 5 basis points worse than the close price (ie 1 + .0005 x close price for a buy). If you want to fill at exactly the close price then set a fixed slippage model equal to 0 (see https://www.quantopian.com/help#ide-slippage).

Those would be my ideas for the discrepancy. This could be tested by not logging the price at the time the orders are placed, but rather the time the orders are filled (check when the order status is 'filled'). If you do that, and set slippage to 0 (and ensure orders complete in one bar), then the fill price will equal the last logged close price.

Good luck