Back

Speeding Up Universe Selection

I was wondering if anyone had any tips on how to speed up universe selection.

Also, in CourseFilter, I return an empty list if it is not a new month. I did this in hopes that fine data would not be collected in the FineFilter function. Is my thought process here correct?

Here is my code.

    def CoarseFilter(self, coarse):
        if self.Time.month == self.lastMonth:
            return []
        
        CoarseWithFundamental = [x for x in coarse if x.HasFundamentalData and x.DollarVolume > 10000000]
        sortedByDollarVolume = sorted(CoarseWithFundamental, key=lambda x: x.DollarVolume, reverse=False) 

        return [i.Symbol for i in sortedByDollarVolume[:500]]
        
    
    def FineFilter(self, fine):
        if self.Time.month == self.lastMonth:
            return self.symbols
        self.lastMonth = self.Time.month
        
        fine = [x for x in fine if x.ValuationRatios.PERatio > 0]
        sortedPERatio = sorted(fine, key=lambda x: x.ValuationRatios.PERatio)
        self.symbols = [x.Symbol for x in sortedPERatio[:50]]
        return self.symbols

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.


When the universe doesn't change it is better to return "Universe.Unchanged" as it signals don't bother loading the files. In the snippet above it is returning [] which actually unloads the universe -- I'm not sure if that was your intent.

1

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.


Thanks for the response! I made the switch to Universe.Unchanged

I noticed that course filter is being called every day. Does this mean the program is spending time loading course data every day? If I only want to access fundamental data once a month, is this slowing down my backtest? If so, how can I prevent the fundamental data from being retrieved every day and only retrieve it once a month?

0

Correct it is selecting every day. If you want to just perform 1 selection per month you can revert it back to what you had earlier (return []). This will still maintain the data subscriptions for the assets you hold an open position. 

1

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.


Would it be faster to return [] or Universe.Unchanged? I would like to prevent my algorithm from wasting time loading fundamental data on days I don't need it. (I only need it once a month).

0

Hi Michael,

It is faster to return Universe.Unchanged since it signals to the algorithm that no changes need to be made to the universe and so universe selection is skipped.

Best
Rahul 

1

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.


Okay, I will stick with Universe.Unchanged.

Thank you for all of your help!

0

Hey Michael,

After running some tests it turns out that when doing universe selection once per month, it is faster to return [], which actually unloads the universe. This will still maintain the data subscriptions for the assets you hold an open position in.

You can test out the differences in speed yourself by comparing the run times between returning [] and returning Universe.Unchanged in coarse selection.

Best
Rahul 

1

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.


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