Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
2 goals: limit failed order fill and controlling leverage

I have two goals in mind:

  1. Keeping leverage < 1

I am using the ExposureMngr class which I found on these forums and only purchasing stocks when context.exposure.get_available_cash(context) >= 300 * data.current(s, "close"). If that is true, the purchase going through is order(s, 300). Given slippage and a few other things, I can see the leverage going up a small bit but it jumps to 8x. Presumably I am utilizing this helper class ExponsureMngr wrong?.

  1. Determining why fill values can be in the thousands exist

Given what I mentioned earlier, I only ever buy stocks in quantities of 300 only if they don't exist as a position s not in context.portfolio.positions and it doesn't exist in an open order, s not in get_open_orders(). However my logs are still littered with Your order for 6596 shares of LNC failed to fill by the end of day and was canceled. Any idea why there would be so many shares of LNC trying to fill? Controlling how many buy orders there are seems pretty straight forward, but something here is not being considered.

Thanks !

2 responses

A general rule of thumb, always close orders before opening.
There are orders for open and close at the same time.
Others may have more to add.

First column is minute of the day. Last column leverage, I added leverage to this.

2018-06-05 12:55 _trac:239 INFO  385   Buy 124534 LNC (-124534) at 67.44                     9226387  aa44  9.3  
2018-06-05 12:56 _trac:239 INFO  386      Sold -1198/-41942 LNC (-125732) at 67.45           9307157  e24b  9.4  
2018-06-05 12:56 _trac:239 INFO  386   Buy 125732 LNC (-125732) at 67.45                     9307157  f552  9.4  
2018-06-05 12:57 _trac:239 INFO  387      Sold -1267/-41942 LNC (-126999) at 67.47           9392591  e24b  9.6  
2018-06-05 12:57 _trac:239 INFO  387   Buy 126999 LNC (-126999) at 67.47                     9392591  97e6  9.6  
2018-06-05 12:58 _trac:239 INFO  388      Sold -1871/-41166 LNC (-128873) at 67.46           9518946  3230  9.7  
2018-06-05 12:58 _trac:239 INFO  388      Sold -41942 LNC (-128873) at 67.46                 9518946  e24b  9.7  
2018-06-05 12:58 _trac:239 INFO  388   Buy 128873 LNC (-128873) at 67.46                     9518946  d838  9.7  
2018-06-05 12:59 _trac:239 INFO  389      Sold -1688/-41166 LNC (-130561) at 67.45           9632734  3230  9.8  
2018-06-05 12:59 _trac:239 INFO  389   Buy 130561 LNC (-130561) at 67.45                     9632734  ce5c  9.8  
2018-06-05 13:00 _trac:239 INFO  390      Sold -4081/-41166 LNC (-134642) at 67.47           9907938  3230  10.1  
2018-06-05 13:00 _trac:239 INFO  390   Buy 134642 LNC (-134642) at 67.47                     9907938  ad22  10.1  
2018-06-05 13:00 WARN Your order for -41166 shares of LNC has been partially filled. 7640 shares were successfully sold. 33526 shares were not filled by the end of day and were canceled.  

You can isolate any stock(s) like
'symbols' : ['LNC'], # List of symbols to filter for, like ['TSLA', 'SPY']

Where I come from, people are very simple, there's a company like Quantopian and when I presented them with track_orders they sent me $500, a thank you note and built it into their system but I come from a different planet.
And producers edited my actual message in the show, you humans are really something

Made a few changes, captain

Thanks Blue, that track_orders seems particularly helpful for transparency.