I am trying to buy the highest dividend in each sector. I do not know why this code will not work. I have tried it after I have ran the pipeline, and it will work. I cannot keep the ticker index name though when I do it that way.
I would like to know a better way to display my class factor.
# highest dividend in the sector
class sector_div(CustomFactor):
window_length=1
inputs= [morningstar.valuation_ratios.dividend_yield,morningstar.asset_classification.morningstar_sector_code]
def compute(self, today, assets, out, div, sector):
df = pd.DataFrame(index=assets, data={"div": div,
"sector":sector})
best_sector = df.groupby(['sector'], as_index=False)["div"].max()
best_sector = best_sector.drop('sector', axis=1)
out[:]= best_sector