I'm getting incorrect values for EMA for banknifty options (way off the mark). Below is the code snippet. I'm using TALIB for calculating EMA. I even printed the "close" price for each interval...they are not same as the one we see on the zerodha chart.
records = kite.historical_data(9496834, from_date=from_date, to_date=to_date, interval=interval ) df = pd.DataFrame(records) df.drop(df.tail(1).index,inplace=True) open = df['open'].values close = df['close'].values volume = df['volume'].values ema10 = talib.EMA(close,10) ema20 = talib.EMA(close,20) print(ema10)
sma = df['close'].rolling(window=window, min_periods=window).mean()[:window]
rest = df['close'][window:]
df.loc[:, 'ema'] = pd.concat([sma, rest]).ewm(span=window, adjust=False).mean()