Back

Stocks aren't being removed from Securities dict when not in universe selection

This is probably a misunderstanding on how data and universes work together in QuantConnect. The documentation states "When no universes are asking for data, the asset is removed from your algorithm" 

https://www.quantconnect.com/docs#Universes

However, in a simple test, I create a course universe filter which returns exactly 20 securities. I then simply log the number of securities currently in the 'Securities' object. The number of securities in that object continues to grow beyond 20.

I would have expected the 'Securities' object to always contain exactly the securities returned by the universe filter?

Am I missing something? See the attached backtest and inspect the logs to view this behavior.

Update Backtest








Instead of inspecting the length of the 'Securities' object I decided to look at the length of the 'slice' of data in the 'OnData' method. This seems to better reflect the results from the universe filter and doesn't continue to grow. Securities do seem to be getting removed, however, the securities in the 'slice' are sometimes off by one or two from those returned in the universe.

Again, am I missing something. Do the securities in the 'slice' object reflect the results from the universe filter. What is the timing for getting removed?

The attached backtest shows this. See the logs.

0


The subscription is removed but not the object itself as we save it to record trades/fees etc.

If you have holdings the subscription also isnt removed.

We could probably make this clearer by adding "HasData" property to the security object.

0

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.


Jared,

Thanks for the explanation. I stumbled upon that fact in another post here in the forums shortly after posting. 

Would it be reasonable to say, typically, one never needs to access the 'Securities' object when using universes? The "Members" property of the universe holds the set of current securities? In a similar fashion, the slice object would be referenced to get technical data but not for determining which securities are in the universe at a given time. Again, it seems best to look at the universe "Members". Am I on the right track?

0

Very helpful share for people from Quantopian like me! Thanks for this Dan.

0

I still don't quite understand this issue.  Why does the Slice object not inlcude data on all of the securities in the ActiveSecurities list (which I understand to hold the most recent universe selection of securities)?   

0

Update Backtest





0

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.


Loading...

This discussion is closed