Fundamental filtering

I want to combine multiple filters in a universe selection. If I wanted to take top 10% and bottom 10%. Can the perentile function be used in fundamental universe selection aswell? And if so, how would that be done? Thank you. 

Update Backtest

You can select the elements in the symbol list with the length.

def CoarseSelectionFunction(self, coarse):
sorted = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
# top ten percent = [i.Symbol for i in sorted[:int(0.1*len(sorted))]]
# bottom ten percent
self.bottom = [i.Symbol for i in sorted[-int(0.1*len(sorted)):]]

return + self.bottom

@Jing Wu I an odd syntax error on the return arguement, 


class Fundamentals(QCAlgorithmFramework):

def Initialize(self):

# Set requested data resolution
self.UniverseSettings.Resolution = Resolution.Daily


def SelectFine(self, data, fine):

# The company's headquarter must in the U.S.
# The stock must be traded on either the NYSE or NASDAQ
# The stock's market cap must be greater than 500 million
selected = [x for x in fine if x.CompanyReference.CountryId == "USA"
and x.ValuationRatios.FCFYield > 0
and x.EarningReports.BasicAverageShares.ThreeMonths * \
x.EarningReports.BasicEPS.TwelveMonths * x.ValuationRatios.PERatio > 5e8]

filteredFine = sorted(selected, key=lambda x: x.DollarVolume, reverse=True) = [i.Symbol for i in filteredFine][:int(0.1*len(filteredFine))]
self.bottom = [i.Symbol for i in filteredFine[-int(0.1*len(filteredFine)):]

return self.bottom +


There's a typo in = [i.Symbol for i in selected[:int(0.1*len(selected))]]
self.bottom = [i.Symbol for i in selected[-int(0.1*len(selected)):]]

DollarVolume is the property in coarse selection function. To filter stocks with the fine selection function, you need to add a coarse selection function. For details, please see the documentation and the attached algorithm

Update Backtest


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.


This discussion is closed