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
Jared Broad
I would not recommend adding and removing securities this way. Perhaps you can achieve better what you need to do with something simpler? Do you mind summarizing the goal?
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Peter Dimov
I turned to this method while trying to find a workaround for customizing the update schedule of a fundamental universe selector.
Since there is no functionality for this currently, I figured a good solution would be to:
1) Identify one large universe in the fundamental selector at the beginning of the day;
2) Return nothing from the universe selector but store the large universe in the algorithm
3) Schedule an event every X minutes that chooses a subset of the large universe and subscribes to it (while unsubscribing to the old subset)
The large goal for this is to run as many tickers as possible through the Alpha Model for a given period of time. Since I want to avoid increasing my subscription limits, I have to change the speed at which I recycle them.
Shile Wen
Hi Peter,
Why do you want to avoid increasing your subscription limit?
Furthermore, the best way to do this would be to get all of the Symbols in a coarse/fine fundamental Universe and then add specific symbols using a Scheduled Universe. I've shown an example in the attached backtest.
Best,
Shile Wen
Peter Dimov
That looks fantastic! I had no clue I could add multiple universe selectors - this perfectly solves my issue.
As for subscription limits, I'd like to limit costs on the broker side.
p.s. apologies for the bump, I did it right before you posted the code of conduct haha
Peter Dimov
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!