I am working on volatility of stocks and cryptos. My goal is calculating their historical high/low and close deltas.
In mathematically the formula of close delta is: (1 - close price/previous close price) and high/low delta formula is: (Difference between High and Low / Previous Close Price)
I want to merge result in one dataframe. I tried below:
for i in range(len(df)):
df['Closedelta'] = (1 - df['Close'].iloc[i] / df['Close'].iloc[i-1])
With this code I am getting same result for every row, output.
Any help appreciated, thank you.
CodePudding user response:
With the df['Closedelta'] in the for loop you are setting 1 value for the entire column, you should specify the row aswell to which you want to connect the value to.
Change df['Closedelta']
to df.iloc[i,5]