import pandas as pd
from quantopian.pipeline import Pipeline
from quantopian.research import run_pipeline
from quantopian.pipeline.data import Fundamentals
from quantopian.pipeline.filters import QTradableStocksUS, Q1500US
def make_pipeline(universe):
base_universe=universe()
return Pipeline(columns={'name': Fundamentals.short_name.latest,
'symbol': Fundamentals.symbol.latest,
'security_type': Fundamentals.security_type.latest,
'share_class_description': Fundamentals.share_class_description.latest,
'ev_to_ebitda': Fundamentals.ev_to_ebitda.latest},
screen=base_universe
)
def show_closed_end_funds(result):
# Find Securities that are closed end funds
mask = result['share_class_description'].str.startswith('CE')
mask=mask.map(lambda x: False if x==None else x)
return result[mask]
A few closed end funds got pulled into this screen in the more recent time period.
result = run_pipeline(make_pipeline(QTradableStocksUS), '2018-04-30', '2018-04-30')
result['share_class_description'].unique().categories
show_closed_end_funds(result)
result2 = run_pipeline(make_pipeline(QTradableStocksUS), '2017-04-30', '2017-04-30')
show_closed_end_funds(result2)
result3 = run_pipeline(make_pipeline(QTradableStocksUS), '2015-04-30', '2015-04-30')
show_closed_end_funds(result3)
No closed end funds were found in the Q1500US.
result4 = run_pipeline(make_pipeline(Q1500US), '2018-04-30', '2018-04-30')
show_closed_end_funds(result4)