I would expect coarse universe selection to be able to automatically add and remove securities. However, I am running into the following two issues right now:
1. I still need to call self.AddEquity() specifically to be able to get stock price through self.Securities[stock].Price.
2. self.Securities.Count keeps on growing. I suppose it will hit memory issue if the securities maintained by self.Securities keep on growing.
Does anyone know anything about this? How do I fix those issues? Any suggestions are welcome!
The following is how I am using coarse universe selection:
...
self.UniverseSettings.Resolution = Resolution.Minute
self.AddUniverse(self.CoarseSelectionFunction)
...
def CoarseSelectionFunction(self, coarse):
CoarseWithFundamental = [x for x in coarse if x.HasFundamentalData]
sortedByDollarVolume = sorted(CoarseWithFundamental, \
key=lambda x: x.DollarVolume, reverse=True)
return [ x.Symbol for x in sortedByDollarVolume[:250] ]
Thanks,
Jessica
Michael Manus
hi,
i will post here some examples from other project so you can clone it and work with this if you want:
(also check out the examples provided by QC on github, links are on the right side in the community forum)
Jessica Gu
Thanks a lot Michael! I don't feel I do anything differently than the example. However, I will try to clone one of those or other examples and see what's the difference.
Tim De Lise
Hi Jessica, just from my own experience, yes you do need to use AddEquity even with the coarse universe selection. This helps control the amount of data. Also, because of the same issue, if you want to remove the symbol from your data, then I think you need to use remove the equity from the data with a similar function, like RemoveEquity, although i can't seem to find the documentation on that.
Jared Broad
- Securities count will grow forever, but even with 16,000 securities added the ram usage is minimal. Log/debug strings use far more RAM.
- AddEquity will override the universe; and force it to always be in your algorithm.
- Likely your coarse selection is actually not selecting the assets like you think. E.g. maybe it doesn't have fundamental data.
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.
Jessica Gu
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!