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
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