KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Technical Analysis using embedPy Re: Technical Analysis using embedPy

  • hoffmanroni

    Member
    June 29, 2021 at 12:00 am

    FYI if anyone is interested I was able to get this working now

    py script

    import pandas as pd from ta.utils 
    import dropna from ta.volatility 
    import BollingerBands 
    def returnBB(df, window=20, window_dev=2): 
        indicator_bb = BollingerBands(close=df["close"], window=20, window_dev=2) 
        # Add Bollinger Bands features 
        df['bb_bbm'] = indicator_bb.bollinger_mavg() 
        df['bb_bbh'] = indicator_bb.bollinger_hband() 
        df['bb_bbl'] = indicator_bb.bollinger_lband() 
        # Add Bollinger Band high indicator 
        df['bb_bbhi'] = indicator_bb.bollinger_hband_indicator() 
        # Add Bollinger Band low indicator 
        df['bb_bbli'] = indicator_bb.bollinger_lband_indicator() 
    return df

    and then q script

    //load above .p script l bb.p

    //make returnBB py func callable in q

    func:.p.get`returnBB

    //conv t to dataframe, pass to the py func and then conv back to qtable .ml.df2tab[func[.ml.tab2df[t]]]