I'd like to get the say 20 largest market cap securities, but the problem i have with the query is that it returns them multiple times in diff share classes.
Eg, the code below returns:
0: AAPL
3: BRK_A
4: GOOG_L
5: GOOG
6: BRK_B
16: RDS_B
18: RDS_A
36: CMCS_A
37: CMCS_K
Does anyone know how to get around this problem? id like the the regular retail investor classes. maybe there's a special flag in the query?
def before_trading_start(context):
"""
Called before the start of each trading day (handle_data) and updates our universe with the securities and values found from fetch_fundamentals
"""
#: Reference fundamentals in a shorter variable
f = fundamentals
#: SQLAlchemy
fundamental_df = get_fundamentals(
query(
f.valuation.market_cap,
f.valuation_ratios.pe_ratio,
f.asset_classification.morningstar_sector_code,
f.operation_ratios.roa,
f.cash_flow_statement.operating_cash_flow
)
# .filter(fundamentals.valuation.market_cap != None)
.order_by(fundamentals.valuation.market_cap.desc())
.limit(40)
)
# the problem here is we get duplicate multple calsses of the shares
secs = np.array([s.symbol for s in fundamental_df.columns.values])
for i, s in enumerate(secs):
if s[-2] is '_':
if s[:-2] in secs:
raise('drop duplicate class shares')
#: Set our fundamentals into a context variable
context.fundamental_df = fundamental_df
#: Update our universe with the values
update_universe(fundamental_df.columns.values)