Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Odd Order Execution In Backtest

I've just completed my first trading algo that is entirely of my own design and is not simply a modification of someone else's algo. The strategy is to purchase shares of a single security in a value that does not exceed 75% of my available cash balance. In addition, the program only holds one security at a time. Therefore, leverage does not dip into margin and the volatility of the program is entirely dependent upon a single security's performance. So, this would be a normal set of transactions over the course of a few days:

 08.21.16 8:31am -- BUY AAPL (300 Shares)  
 08.22.16 8:31am -- SELL AAPL (300 Shares)  
 08.22.16 8:32am -- BUY F (1500 Shares)  
 08.23.16 8:31am -- SELL F (1500 Shares)  
 08.23.16 8:32am -- BUY LUV (950 Shares)  
 08.24.16 8:31am -- SELL LUV (950 Shares)

Now, my issue is that I usually end up seeing something like this in the backtest, under transaction details:

 08.21.16 8:36am -- BUY AAPL (50 Shares)  
 08.21.16 8:38am -- BUY AAPL (2 Shares)  
 08.21.16 8:39am -- BUY AAPL (2 Shares)  
 08.21.16 8:44am -- BUY AAPL (130 Shares)  
 08.21.16 8:52am -- BUY AAPL (116 Shares)  
 08.22.16 8:32am -- SELL AAPL (88 Shares)  
 08.22.16 8:33am -- BUY F (632 Shares)  
 08.22.16 8:35am -- SELL AAPL (23 Shares)  
 08.22.16 8:39am -- SELL AAPL (77 Shares)  
 08.22.16 8:42am -- BUY F (484 Shares)  
 08.22.16 8:48am -- BUY F (384 Shares)  
 08.22.16 8:31am -- SELL AAPL (112 Shares)

Is this the Backtester's way of trying to simulate reality and intentionally breaking my order up because of the low volume of the securities I'm trading? My plan is to live trade this algo soon with Robinhood and I don't want the algo to be executing multiple different sets of orders at different times of the day if the brokerage has the ability to buy me those shares at a single time and a single price. Basically, I'm wondering if the backtester is faking slippage.

Thank You!

2 responses

Sorry, I just typed a nice response and lost it. So I'll be brief now. Yes, those are simulated order fills. This must be using leverage because F was bought before the AAPL sell order was filled. Nest your buy orders inside logic that checks for open orders. Here's some code to work with

            open_order = get_open_orders()  
            if len(open_order) > 0:  
                          nested code  
            else:  
                  pass  

Thank you very much for the response Addison. Actually, there's some fault in my first post's example and I should have used an actual screenshot of the backtest. It would be more accurate to say that my single sell order for AAPL is broken up into multiple separate sells (same with F), although the Buy for the following security never dips into margin and doesn't use unsettled funds. I have a function in my algo that checks available cash every Buy/Sell order to prevent buying on margin. I'm sorry I didn't explain the original post very well, but I hope you still have an answer for me. Actually, on second thought, your statement about how the orders are simulated probably was meant to answer my slippage question.

Thank You!