Hi All,

I'm trying to build a custom Universe Selection Model simply combining several conditions using price and volume.

I'm using self.SetUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseSelectionFunction)) in my framework and then basically customizing the def CoarseSelectionFunction within the same script.

So what I'm trying to do is filtering stocks (before opening the market every day) with close price > X, close price > close price of last day, last volume > X, average volume of the past n days > X, close price > max price of the last n days, etc.

As you can see in the attached backtest, I followed examples I found in the community and managed to get some of the above conditions working, However, I could not get the close price in an elegant way so had to use SimpleMovingAverage(1) to do that (terrible, I know). Also, how do I do the max function, or the lag closing prices, etc??

I think this could be a good, simple example of a template in which you add all the functions needed in the class SymbolData(object) such as moving averages and so on, and then perform all the filtering within the def CoarseSelectionFunction(self, coarse) adding many conditions to filter(lambda x: (x.is_ready and x.price.Current.Value > 20), self.averages.values())

Thank you so much in advance for the help!

Emilio

Author