(df, n)
return out(SETTINGS, df, result)
On-balance Volume
On-balance Volume
On - balance Volume
def OBV(df, n):
    """
    On-balance Volume
    """
    i = 0
    OBV = [0]
    while i < len(df) - 1:  # df.index[-1]:
        if df.iat[i + 1, df.columns.get_loc('Close')] - df.iat[i, df.columns.get_loc('Close')] > 0:
            OBV.append(df.iat[i + 1, df.columns.get_loc('Volume')])
        if df.iat[i + 1, df.columns.get_loc('Close')] - df.iat[i, df.columns.get_loc('Close')] == 0:
            OBV.append(0)
        if df.iat[i + 1, df.columns.get_loc('Close')] - df.iat[i, df.columns.get_loc('Close')] < 0:
            OBV.append(-df.iat[i + 1, df.columns.get_loc('Volume')])
        i = i + 1
    OBV = pd.Series(OBV)
    result = pd.Series(OBV.rolling(n).mean(), name='OBV_' + str(n))
    return out(SETTINGS, df, result)
def OBV ( df , n ) : i = 0 OBV = [ 0 ] while i < len ( df ) - 1 : # df.index[-1]: if df . iat [ i + 1 , df . columns . get_loc ( 'Close' ) ] - df . iat [ i , df . columns . get_loc ( 'Close' ) ] > 0 : OBV . append ( df . iat [ i + 1 , df . columns . get_loc ( 'Volume' ) ] ) if df . iat [ i + 1 , df . columns . get_loc ( 'Close' ) ] - df . iat [ i , df . columns . get_loc ( 'Close' ) ] == 0 : OBV . append ( 0 ) if df . iat [ i + 1 , df . columns . get_loc ( 'Close' ) ] - df . iat [ i , df . columns . get_loc ( 'Close' ) ] < 0 : OBV . append ( - df . iat [ i + 1 , df . columns . get_loc ( 'Volume' ) ] ) i = i + 1 OBV = pd . Series ( OBV ) result = pd . Series ( OBV . rolling ( n ) . mean ( ) , name = 'OBV_' + str ( n ) ) return out ( SETTINGS , df , result )