Python Forum
error on stock indicator code on balance volume
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error on stock indicator code on balance volume
#1
# 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 aapl
the 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
Reply


Messages In This Thread
error on stock indicator code on balance volume - by yatish - Jul-04-2018, 10:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to accumulate volume of time series amdi40 3 2,300 Feb-15-2022, 02:23 PM
Last Post: amdi40
  Integrating for the volume of a torus in SciPy Nitram 2 3,673 Jan-08-2020, 04:45 PM
Last Post: Nitram

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020