del df['action3'] del df['action4'] del df['action5'] #del df['action6'] df_copy = df.copy(deep=True) dfo = df.copy(deep=True) df_pos = df[['Price','logreturn','return']].copy(deep=True) alphas = 0 strategies = 0 for idx in range(0,((len(df.index)+1)/50)-3): start_time = idx * 50 del alphas del strategies df_copy = dfo.copy(deep=True) alphas, strategies = boosting.update_weights(df_copy[(df_copy.index > start_time) & (df_copy.index < start_time + 100)], "buy", 1.5) for i in range(len(alphas)): if alphas[i]<0 : df_copy[strategies[i] + 'wgt'] = 0 else: df_copy[strategies[i] + 'wgt'] = np.where(df_copy[strategies[i]] == 0, -1, 1)*alphas[i] columns = map(lambda x: x+"wgt", strategies) df_copy['final'] = df_copy[columns].sum(axis = 1) df_copy['final_ind'] = np.where(df_copy['final'] >= 0, 1, 0) #df_copy[(df.index >= 5000) & (df.index < 5100)] alphas_buy = alphas strategies_buy = strategies
df['action1buy'] = np.where(df['action1'] == -1, 0, df['action1']) df['action1sell'] = np.where(df['action1'] == 1, 0, df['action1']) df['action2buy'] = np.where(df['action2'] == -1, 0, df['action2']) df['action2sell'] = np.where(df['action2'] == 1, 0, df['action2']) df['action3buy'] = np.where(df['action3'] == -1, 0, df['action3']) df['action3sell'] = np.where(df['action3'] == 1, 0, df['action3']) df['action4buy'] = np.where(df['action4'] == -1, 0, df['action4']) df['action4sell'] = np.where(df['action4'] == 1, 0, df['action4']) df['action5buy'] = np.where(df['action5'] == -1, 0, df['action5']) df['action5sell'] = np.where(df['action5'] == 1, 0, df['action5']) df['action6buy'] = np.where(df['action6'] == -1, 0, df['action6']) df['action6sell'] = np.where(df['action6'] == 1, 0, df['action6']) del df['action1'] del df['action2'] del df['action3'] del df['action4'] del df['action5'] del df['action6'] alphas, strategies = boosting.update_weights(df[(df.index > 4800) & (df.index < 5000)], "buy") df_copy = df for i in range(len(alphas)): df_copy[strategies[i] + 'wgt'] = np.where(df[strategies[i]] == 0, -1, 1)*alphas[i] columns = map(lambda x: x+"wgt", strategies) df_copy['final'] = df_copy[columns].sum(axis = 1) df_copy[(df.index >= 5000) & (df.index < 5100)]
df['action1sell'] = np.where(df['action1'] == 1, 0, df['action1']) df['action2buy'] = np.where(df['action2'] == -1, 0, df['action2']) df['action2sell'] = np.where(df['action2'] == 1, 0, df['action2']) df['action3buy'] = np.where(df['action3'] == -1, 0, df['action3']) df['action3sell'] = np.where(df['action3'] == 1, 0, df['action3']) df['action4buy'] = np.where(df['action4'] == -1, 0, df['action4']) df['action4sell'] = np.where(df['action4'] == 1, 0, df['action4']) df['action5buy'] = np.where(df['action5'] == -1, 0, df['action5']) df['action5sell'] = np.where(df['action5'] == 1, 0, df['action5']) df['action6buy'] = np.where(df['action6'] == -1, 0, df['action6']) df['action6sell'] = np.where(df['action6'] == 1, 0, df['action6']) del df['action1'] del df['action2'] del df['action3'] del df['action4'] del df['action5'] del df['action6'] alphas, strategies = boosting.update_weights( df[(df.index > 4800) & (df.index < 5000)], "buy") df_copy = df for i in range(len(alphas)): df_copy[strategies[i] + 'wgt'] = np.where(df[strategies[i]] == 0, -1, 1) * alphas[i] columns = map(lambda x: x + "wgt", strategies) df_copy['final'] = df_copy[columns].sum(axis=1) df_copy[(df.index >= 5000) & (df.index < 5100)]