def strategy_bollinger(d_data, ldt_timestamps): ls_symbols = list(d_data['close'].keys()) df_index_bollinger = BollingerBands.bollinger_bands(d_data['close'], ldt_timestamps, ls_symbols=ls_symbols) mkt_benchmark = Analyze.get_mktBenchmark(ldt_timestamps) mkt_bollinger = BollingerBands.bollinger_bands(mkt_benchmark, ldt_timestamps) df_events = copy.deepcopy(df_index_bollinger) * np.NAN for i in range(1,len(ldt_timestamps)): boll_today = df_index_bollinger.ix[ldt_timestamps[i]] boll_yest = df_index_bollinger.ix[ldt_timestamps[i-1]] for c_sym in ls_symbols: if boll_today[c_sym] <= -2.0 and boll_yest[c_sym] > -2.0 and \ mkt_bollinger['$SPX'].ix[ldt_timestamps[i]] >= 1.0: df_events[c_sym].ix[ldt_timestamps[i]] =1 return df_events