Hi,
I'm having difficulty merging a table of industry averages that I calculated into the Pipeline dataframe and retaining the structure of the original dataframe so that it can be picked up by the order function later in the algorithm. The below code is where I am running into issues. Note that I reset the index of the pipeline dataframe so that I can merge my industry average table into it. I think that the issue I am having is recreating the multi-index that the order function can action. This gets slightly more confusing because when I log.info(top_outlook) it appears like the output is in the correct format.
Any help here is really appreciated. Please let me know if you need any additional info.
Thanks!
Stefan
context.output = pipeline_output('my_pipeline')
#log.info(context.output)
mean_val = calc_means(context, data)
#log.info(context.output)
#context.output.head()
curr_df = context.output.reset_index()
df = curr_df.merge(mean_val, on = 'Sector Code')
#log.info(df)
df.head()
df = df[np.isfinite(df['Gross Margin'])]
#df = df.set_index(['level_0','level_1']) #for some reason this kicks out an error but when I run it in research works fine
df['outlook'] = ((df['Gross Margin'] > df['Ind MEAN GM']).astype(int)*1)
top_outlook = df.sort_values(['outlook'], ascending=False).head(20)
log.info(top_outlook)
# These are the securities that we are interested in trading each day.
context.security_list = top_outlook.index