Something like the following should filter to just the NYSE and NASDAQ (note that in the Morningstar data there is a switchover in naming from NYSE to NYS so check for both). You can also easily make filters out factors with typical > and < operators.
def my_pipeline(context):
'''
Define the pipline data columns
'''
# Create filter for just the stocks we want to trade
universe = Filters.default_us_equity_universe_mask()
# Create any factors or classifiers we need (use a mask to potentially speed up the query)
market_cap = Factors.morningstar.MarketCap(mask = universe)
exchange = morningstar.share_class_reference.exchange_id.latest
# Create any filters based upon above factors
# This assumes 'small cap' is defined as between 300M and 2B
small_cap = (market_cap > 300e+6) & (market_cap < 2000e6)
my_exchanges = exchange.element_of(['NYSE','NYS','NAS'])
return Pipeline(
columns={
'market_cap': market_cap
},
screen = universe & my_exchanges & small_cap
)
Not sure what you mean by "Spend no more than $900 on any one position". If it's that you don't wan't the stock price to be more than $900 then create another filter like this
less_than_900 = USEquityPricing.close.latest < 900
However, if you only ever want to open a position worth no more than $900, then that's a bit trickier. How do you want to distribute your available cash? If you have $900 in cash and there are 10 potential stocks do you want to open $900 of the one? Which one? Or, do you want to open a $90 position of each. What if the stock price is more than $90 in that case? Do you want to account for rounding and use up as much of the $900 as possible (but then you may have a different percentage of each).
I'd recommend maybe not going down that path.