Disclaimer: I'm another Quantopian migrant, and mediocre (at best) programmer.

I'm looking to use several parameters in both the coarse and fine universe functions, and was curious if there was a more 'pythonic' way of doing it. For example, this appears to work:

def CoarseSelectionFunction(self, coarse): price_filter = [x for x in coarse if float(x.Price) < 5] sortedByDollarVolume = sorted(price_filter, key=lambda x: x.DollarVolume, reverse=True) return [x.Symbol for x in sortedByDollarVolume[:50 ]] def FineSelectionFunction(self, fine): primaryshare = [x for x in fine if x.SecurityReference.SecurityType == 'ST00000001'] nototc = [x for x in primaryshare if x.SecurityReference.ExchangeId != 'OTC'] sortedByPERatio = sorted(nototc, key = lambda x: x.ValuationRatios.PERatio, reverse=True) return [x.Symbol for x in sortedByPERatio[:10]]

However, I don't like cascading each variable into the next (which requires refactoring the whole function each time I add/remove filters).

On Quantopian, I would expect to be able to do something like:

def make_pipeline(context): primary_share = IsPrimaryShare() common_stock = morningstar.share_class_reference.security_type.latest.eq('ST00000001') not_otc = ~morningstar.share_class_reference.exchange_id.latest.startswith('OTC') AtMostPrice = (price <= context.MyMostPrice) tradeable_stocks = (common_stock & not_otc & AtMostPrice) base_universe = AverageDollarVolume( window_length=20, mask=tradeable_stocks).percentile_between(10,40) ShortAvg = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=3, mask=base_universe ) LongAvg = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=45, mask=base_universe ) percent_difference = (ShortAvg - LongAvg) / LongAvg stocks_worst = percent_difference.bottom(context.MaxCandidates) securities_to_trade = (stocks_worst) return Pipeline(columns={'stocks_worst': stocks_worst},screen=(securities_to_trade))

So I have two questions:

  1. Is there a way to use booleans, and aggreations of booleans, in the universe filters? I haven't seen this in any of the documentation or example algos.
  2. How could I print the stocks in the universe to confirm the universe filters are working correctly? (eg. excluding OTC)
Many thanks in advance!