Heiken Ashi Using pandas python

前端 未结 7 2237
南方客
南方客 2021-01-31 23:23

I was defining a function Heiken Ashi which is one of the popular chart type in Technical Analysis. I was writing a function on it using Pandas but finding little difficulty. T

7条回答
  •  渐次进展
    2021-02-01 00:00

    Unfortunately, set_value(), and get_value() are deprecated. Building off arkochhar's answer, I was able to get a 75% speed increase by using the following list comprehension method with my own OHLC data (7000 rows of data). It is faster than using at and iat as well.

    def HA( dataframe ):
    
        df = dataframe.copy()
    
        df['HA_Close']=(df.Open + df.High + df.Low + df.Close)/4
    
        df.reset_index(inplace=True)
    
        ha_open = [ (df.Open[0] + df.Close[0]) / 2 ]
        [ ha_open.append((ha_open[i] + df.HA_Close.values[i]) / 2) \
        for i in range(0, len(df)-1) ]
        df['HA_Open'] = ha_open
    
        df.set_index('index', inplace=True)
    
        df['HA_High']=df[['HA_Open','HA_Close','High']].max(axis=1)
        df['HA_Low']=df[['HA_Open','HA_Close','Low']].min(axis=1)
    
        return df
    

提交回复
热议问题