(df, n, price='Close')
return out(SETTINGS, df, result)
Bollinger Bands
Bollinger Bands
Bollinger Bands
def BBANDS(df, n, price='Close'):
    """
    Bollinger Bands
    """
    MA = pd.Series(df[price].rolling(n).mean())
    MSD = pd.Series(df[price].rolling(n).std())
    b1 = 4 * MSD / MA
    B1 = pd.Series(b1, name='BollingerB_' + str(n))
    b2 = (df[price] - MA + 2 * MSD) / (4 * MSD)
    B2 = pd.Series(b2, name='Bollinger%b_' + str(n))
    result = pd.DataFrame([B1, B2]).transpose()
    return out(SETTINGS, df, result)
def BBANDS ( df , n , price = 'Close' ) : MA = pd . Series ( df [ price ] . rolling ( n ) . mean ( ) ) MSD = pd . Series ( df [ price ] . rolling ( n ) . std ( ) ) b1 = 4 * MSD / MA B1 = pd . Series ( b1 , name = 'BollingerB_' + str ( n ) ) b2 = ( df [ price ] - MA + 2 * MSD ) / ( 4 * MSD ) B2 = pd . Series ( b2 , name = 'Bollinger%b_' + str ( n ) ) result = pd . DataFrame ( [ B1 , B2 ] ) . transpose ( ) return out ( SETTINGS , df , result )