(df, n)
return out(SETTINGS, df, result)
Money Flow Index and Ratio
Money Flow Index and Ratio
Money Flow Index and Ratio
def MFI(df, n):
    """
    Money Flow Index and Ratio
    """
    PP = (df['High'] + df['Low'] + df['Close']) / 3
    i = 0
    PosMF = [0]
    while i < len(df) - 1:  # df.index[-1]:
        if PP[i + 1] > PP[i]:
            PosMF.append(PP[i + 1] * df.iat[i + 1, df.columns.get_loc('Volume')])
        else:
            PosMF.append(0)
        i=i + 1
    PosMF = pd.Series(PosMF)
    TotMF = PP * df['Volume']
    MFR = pd.Series(PosMF / TotMF)
    result = pd.Series(MFR.rolling(n).mean(), name='MFI_' + str(n))
    return out(SETTINGS, df, result)
def MFI ( df , n ) : PP = ( df [ 'High' ] + df [ 'Low' ] + df [ 'Close' ] ) / 3 i = 0 PosMF = [ 0 ] while i < len ( df ) - 1 : # df.index[-1]: if PP [ i + 1 ] > PP [ i ] : PosMF . append ( PP [ i + 1 ] * df . iat [ i + 1 , df . columns . get_loc ( 'Volume' ) ] ) else : PosMF . append ( 0 ) i = i + 1 PosMF = pd . Series ( PosMF ) TotMF = PP * df [ 'Volume' ] MFR = pd . Series ( PosMF / TotMF ) result = pd . Series ( MFR . rolling ( n ) . mean ( ) , name = 'MFI_' + str ( n ) ) return out ( SETTINGS , df , result )