# On-balance Volume def on_balance_volume(aapl, n): i = 0 OBV = [0] #I have a dataframe with open high low close volume of stock prices and wanted to calaculate obv of parameter 10 and 20 while (i < (len(aapl.index)-1)): if aapl.iloc[i + 1]['Close'] - aapl.iloc[i]['Close'] > 0: OBV.append(aapl.iloc[i]['Volume']) elif aapl.iloc[i + 1]['Close'] - aapl.iloc[i]['Close'] < 0: OBV.append(-aapl.iloc[i + 1]['Volume']) else : OBV.append(0) i = i + 1 OBV = pd.Series(OBV) #print(obv) #obv is calculated till here but not passed to the rolling function OBV_ma = pd.Series(OBV.rolling(n, min_periods=n).mean(), name='OBV_' + str(n)) aapl = aapl.join(OBV_ma) return aaplthe output for obv is displaying nan values tried several other ways...please can someone check my whole code and guide me
I have dataframe of open high low close volume of stock prices