# Import things to run pipeline
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
# Import our data sources
from quantopian.pipeline.data import Fundamentals
# Import some basic universe filters
from quantopian.pipeline.filters import Q500US, Q1500US, Q3000US, QTradableStocksUS
pipe = Pipeline(
columns = {'exchange_id': Fundamentals.exchange_id.latest,
'QTradableStocksUS': QTradableStocksUS()
},
screen = None,
)
result = run_pipeline(pipe, '2019-04-18', '2019-04-18')
result.head()
# Let's name the date and stock index for easier reading
result.index.rename(['date','stock'], inplace = True)
# Let's also add a column which is the exchange from the symbol object
result['exchange_from_symbol'] = [stock.exchange for stock in result.index.get_level_values('stock').tolist()]
result
# Display our result in a qgrid to easily sort and filter
import qgrid
qgrid.show_grid(result)
# First check if there are any securities which don't have an exchange_id
result[result.isnull().any(axis=1)]
# There seem to be some securities which don't have an exchange_id
# However, scannng the list there seems to be a lot of ETFs and warrents and some other security types
# These won't have fundamental data so it's no surprise they don't show up in Morningstar fundamentals
# That's part of what the QTradableStocksUS universe is meant for - filter only stocks
# Lets see how many of the stocks from the QTradableStocksUS don't have an exchange_id
result[result.isnull().any(axis=1)].query('QTradableStocksUS == True')
# Looks like all the QTradableStocksUS securities have a value
# Let's verify the NYSE
result.query("exchange_from_symbol in ['NYSE'] and not exchange_id in ['NYS', 'ASE', 'ARCX'] and QTradableStocksUS")
# That looks good
# Let's verify the BATS
result.query("exchange_from_symbol in ['BATS'] and not exchange_id in ['BATS'] and QTradableStocksUS")
# That looks good too
# Let's verify the NASDAQ
result.query("exchange_from_symbol in ['NASDAQ'] and not exchange_id in ['NAS'] and QTradableStocksUS")