I'm seeing some odd outcomes when using manual AddSecurity / RemoveSecurity.

In the backtest attached, a timer is set to switch across equities every 10 minutes removing the existing security and adding a new one.

The first thing to notice is that the first time that OnData is called is at 11:00AM. I would expect this to be at market open as the first AddSecurity call happens then and if you modify breakpoints to audit this you will notice that the security is appropriately added at 9:30AM BUT ActiveSecurities remains empty until the 11:00AM mark as well.

Once OnData is called, the other unexpected outcome is an ActiveSecurities list that contains 4 tickers, as opposed to 1 (which should be the case given the fact that the rotator removes all securities before adding the current one).

This ends up smoothing itself out over time (by 11:20AM, the expected flow ramps up properly).

 

Im not sure if the backtest attached will show the debug setup but here it is:

Breakpoints: Lines 10, 27 (both self.Debug Statements)

Watchers:

- [x.Value for x in self.ActiveSecurities.Keys]

-self.Time