Hello,
I have this really simple code, it's really slow and I don't know why. It seems like every coarse you let through gets processed. Is there a way to make it faster?
QUANTCONNECT COMMUNITY
Hello,
I have this really simple code, it's really slow and I don't know why. It seems like every coarse you let through gets processed. Is there a way to make it faster?
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.
Rahul Chowdhury
Hey Alexander,
You algorithm is slow because in your coarse selection you're returning a vast number of symbols. Filtering based on fundamental data is already a pretty computationally expensive act, but doing it on thousands of symbols slows down your algorithm further. To speed up your algorithm, you should narrow down the symbols you return in coarse selection. One way to do this is to only consider the most liquid stocks.
def CoarseSelectionFunction(self, coarse): # Filter coarse for those which have fundamental data hasFundamental = [x for x in coarse if (x.HasFundamentalData)] # Sort filtered coarse by dollar volume sortedCoarse = sorted(hasFundamental, key=lambda c:c.DollarVolume, reverse=True) # select and return top 500 most liquid symbols selected = [x.Symbol for x in sortedCoarse][:500] return selected
Â
Learn more in the documentation.Â
Alexander Kool
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!