Python Package bt: Bool index error

class SelectWhere(bt.Algo):
def __init__(self, signal):
    self.signal = signal

def __call__(self, target):
    # get signal on target.now
    if target.now in self.signal.index:
        sig = self.signal.loc[target.now]

        # get indices where true as list
        selected = list(sig.index[sig])

        # save in temp - this will be used by the weighing algo
        target.temp['selected'] = selected

    # return True because we want to keep on moving down the stack
    return True

Which gives the error:

AttributeError: ‘numpy.bool_’ object has no attribute ‘index’

Which looks like it is relating to the following line:

            selected = list(sig.index[sig])

Now I’m just wondering how this is meant to work, as the whole purpose of creating this list is to have a True/False indicator iterated across a data set depending on the rule of the strategy – but such a data type cannot have an index?

Leave a Comment