Formula to smoothen the stochastics study that is shown in the Kite HTML interface

RajeshSivadasan
What is the formula to smooth the stochastics study that is shown in the Kite HTML interface? My calculation of %K is not matching with the values that are shown in the Kite interface. Any help highly appreciated.
  • ganeshv02
    You can use below to pass a pandas dataframe and get back updated result.

    def calculate_stochastics(df, period=14, smooth_k_period=3, d_period=3):
    highest_high = df["high"].rolling(center=False, window=period).max()
    lowest_low = df["low"].rolling(center=False, window=period).min()
    df['%_k'] = pd.Series(round(((df["close"] - lowest_low) / (highest_high - lowest_low) * 100), 2))
    df['k_line'] = round((df["%_k"].rolling(center=False, window=smooth_k_period).mean()), 2)
    df['d_line'] = round((df["k_line"].rolling(center=False, window=d_period).mean()), 2)
    return df
Sign In or Register to comment.