I tried to filter the universe based on the prices' Gap on open (if it opens more than the High of the previous day or less than the Low of the previous day).
Got this strange behaviour in the 'def OnSecuritiesChanged(self, changes):' function, where the only changes passed are removals!
By debugging the 'def SelectSymbols(self, dateTime):' function You can see that it correctly creates the new symbols (when needed), but when returned, they don't appear inside changes.AddedSecurities...
Can't figure out why it only removes securities and can't add them.
Did someone encounter the same problem?
Hope that someone can help.
Derek Melchin
Hi Alessio,
The issue is that the algorithm above calls `AddEquity` for the entire universe during the `Initialize` method and sets up a coarse universe selection method. Since it's not currently possible to chain universe selection methods, we need to select just one universe selection technique to resolve the issue. In the attached backtest, we define the universe using the `AddEquity` method. We then create a Scheduled Event to narrow down our universe to the symbols with the largest gaps. Note that when using this technique, the algorithm is still subscribed to all of the securities in the original universe after narrowing down the universe.
In the attached backtest, we've also made the following changes:
Â
Best,
Derek Melchin
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.
Alessio Magri
Thank You Derek!
I've seen that it's not possible to chain universe selection, but does it mean that the framework adds the initial list in the Initialize method and then, when the scheduled event is called, it doesn't remove or add symbols?
That could be the problem that is showing up that I can see with debugging that there are removed equities, but no added equities.
I've tried to follow your guidelines (moved the insights inside the update function of the alpha model, and changed the time of the scheduled event to 10.01, not 10.00, because I need the indicators to be updated before the filter is called).
I Registered the indicators because without registering them, they're not warming up before the algorithm starts.
I've attached the new algorithm based on your suggestions, but the problem remains: you can see it by inspecting self.removedSym and self.addedSym.
I can try to solve it by saving the Previous list of symbols in a variable and by checking the differences with the current list (so the alpha model can emit insights only on differences).
Best regards
Alessio
Derek Melchin
Hi Alessio,
>does it mean that the framework adds the initial list in the Initialize method and then, when the scheduled event is called, it doesn't remove or add symbols?
When the `SelectSymbols` method removes symbols from the universe, the `OnSecuritiesChanged` method is called, but all of the symbols in the `symDict` remained subscribed to for the entire backtest. See the attached backtest for reference.
>I Registered the indicators because without registering them, they're not warming up before the algorithm starts.
When we register the indicators in this algorithm, they are updated twice. They are updated automatically as new daily bars are passed to the algorithm and they are also updated when the `DailyConsolidator` is called. To have the indicators ready when the backtest starts, we just need to change
to
>I can try to solve it by saving the Previous list of symbols in a variable and by checking the differences with the current list (so the alpha model can emit insights only on differences).
Instead, we recommend tracking which of the symbols the `OnSecuritiesChanged` method includes in the `RemovedSecurities` collection. Â Then we can emit flat insights for the symbols that `SelectSymbols` has removed and emit Up/Down insights for the remaining symbols. Keep in mind that this technique will only work with a static universe. It won't work with a dynamic universe selection model.
See the attached backtest for reference.
Best,
Derek Melchin
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.
Alessio Magri
Thank You Derek for the Explanation.
I Was reading your code and I found that You debugged also Splits and Dividends information.
Is it possible to pass these information to SymbolData through its update method? Like:
Cause I'm trying but I really don't know which is the best way to get that result.
Best regards
Varad Kabade
Hi Alessio Magri,
In the above code snippet, the Splits and dividends are passed to on data method during midnight, and the trade bar is passed from 10 am to 4 pm; therefore, the update method does not receive information about split factor and dividend distribution. We recommend implementing a separate method to receive updates about splits and dividends(in the backtest Update1). Refer to the attached backtest.
Best,
Varad Kabade
Alessio Magri
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!