Back to Community
Positive Volume Index (PVI) and Negative Volume Index (NVI)

Hi,
Im new in Quantopian, but i think is the best tool for trading algorithm.

I want to do one algorith based in Positive Volume Index (PVI) and Negative Volume Index (NVI), but i dont find anything about this indicator ( or if exist in Quantopian). Exist this indicator in python o in any library? do you know about it?

So, as I could not find anything about this indicators, i want to do that with one Custom Factor, but i have one problem. This indicators is based in the yesterday values and i dont know how to do that. This is basically the alg (PVI for example, ¬°DOESNT WORK!):

PVI https://www.fmlabs.com/reference/default.htm?url=PVI.htm
NVI https://www.fmlabs.com/reference/default.htm?url=NVI.htm

class MFI(CustomFactor):

    inputs = [USEquityPricing.close, USEquityPricing.volume]  
    window_length = 2

    def compute(self, today, assets, out, close, vol):  
        vol_yesterday = np.roll(vol, 1, axis=0)  
        close_yesterday = np.roll(close, 1, axis=0)  
        price_op = (close-close_yesterday) / close_yesterday  
        if (vol > vol_yesterday):     # (This statent give error)  
               pvi = pvi[-1] + price_op  # ( I dont know how to access to yesterday pvi value)  
        else:  
              pvi = pvi[-1]   # ( I dont know how to access to yesterday pvi value)  


        out[:] =    pvi

I appreciate very much any help with this question.
Thank you very much